1

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.

The code is courtesy of @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?

nini
  • 79
  • 1
  • 8
  • @rayryeng I came across your solution for a very similar [question](https://stackoverflow.com/questions/43725793/check-for-pixel-values-in-a-neighborhood). Perhaps you can shed some light on this question as well? – nini May 26 '17 at 06:35
  • Independently on this question: I hope you are separating by colors in HSV space, RGB is bad for that – Ander Biguri May 26 '17 at 07:42
  • Hmm, I actually did it in RGB. Why is it a bad option? – nini May 26 '17 at 15:12
  • Depends on your data, but the problem is that RGB is VERY nonlinear. "brown" can have a very wide range of values in RGB. Unless your images are very specific, RGB will not segment things that are "yellow" properly. HSV instead, does a great job in color-segmentation – Ander Biguri May 26 '17 at 15:14

1 Answers1

0

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

nini
  • 79
  • 1
  • 8