我有一张红色和蓝色的彩色图片。我把蓝色和红色的信号砂从它们中分离出来:第一图像和第二图像。
现在,我想看看第二幅图像中的白点是否重叠在第一幅图像上的线条上。
我的做法如下:
代码由@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,我被卡住了:,在第二张图像中,我很难检测到白点的中心点。尤其是因为我想避免白点的聚集。我只想在第一张图像中,在相同的线附近探测到这些斑点。
我愿意尝试任何有良好图像分析库的语言。我该怎么做?
发布于 2017-05-27 11:17:31
这似乎很管用:
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结束
https://stackoverflow.com/questions/44195033
复制相似问题