简体   繁体   English

检查两个不同图像的像素重叠

[英]Checking for overlap of pixels from two different images

I have a color picture with red and blue colors. 我有一张红色和蓝色的彩色照片。 I separated the blue and red color signal sand created black and white images from them as such: first image and second image 我将蓝色和红色信号沙子分开,从而创建了黑白图像:第一张图像和第二张图像

Now, I want to see how if the white spots in the second image overlap on top of the squiggly lines in the first image. 现在,我想看看第二张图像中的白点如何在第一张图像中的波浪线上重叠。

My approach is the following: 我的方法如下:

  1. First detect the center coordinate of the white spots in the 2nd image. 首先检测第二图像中白点的中心坐标。 Avoiding the big white clusters. 避免大的白色群集。 I only care about the white spots that are in the same vicinity of the squiggly lines in the first image. 我只关心第一张图像中波浪线相同附近的白点。
  2. Then use the following MATLAB code to see if the white spot is on top of the squiggly lines from the first image. 然后使用以下MATLAB代码查看白点是否位于第一张图像的波浪线之上。

The code is courtesy of @ rayryeng 代码由@ rayryeng提供

val = 0; % Value to match
count = 0 
N = 50; % Radius of neighbourhood

% Generate 2D grid of coordinates
[x, y] = meshgrid(1 : size(img, 2), 1 : size(img, 1));

% For each coordinate to check...
for kk = 1 : size(coord, 1)
    a = coord(kk, 1); b = coord(kk, 2); % Get the pixel locations
    mask = (x - a).^2 + (y - b).^2 <= N*N; % Get a mask of valid locations
                                           % within the neighbourhood        
    pix = img(mask); % Get the valid pixels
    count = count + any(pix(:) == val); % Add either 0 or 1 depending if 
                                        % we have found any matching pixels
end

Where I am stuck: I'm having trouble detecting the center point of the white spots in the 2nd image. 我被卡住的地方:我无法检测到第二张图像中白点的中心点。 Especially because I want to avoid the clusters of white spots. 特别是因为我想避免白点簇。 I just want to detect the spots that are in the same vicinity of the squiggly lines in the first image. 我只想检测第一张图像中波浪线相同附近的斑点。

I am willing to try any language that has good image analysis libraries. 我愿意尝试任何具有良好图像分析库的语言。 How do I go about this? 我该怎么做?

This seemed to work pretty well: 这似乎工作得很好:

pos = rp.WeightedCentroid; %all positions
for ct = size(pos,1):-1:1  %check them backwards
d = sum((pos-pos(ct,:)).^2); %distance to all other points (kd-trees could be used for speedup)
if min(d)<50^2,pos(ct,:)=[];end  %remove if any point is too close

end 结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM