2017-05-26 12 views
0

gray scale imageの白い点を検出するために次のコードを使用しています。画像に特定の距離にマーカーを配置する

Gimg=imread('hi.tif','tif'); 
BW=Gimg>150; 
rp=regionprops(BW,Gimg,'WeightedCentroid'); 

disp('Centroiding is done.'); 

figure(1); image(Gimg); axis image; hold on; 
n=numel(rp); 
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)<1^2,pos(ct,:)=[];end %remove if any point is too close 
end 

for i=1:pos 
    plot(rp(i).WeightedCentroid(1), rp(i).WeightedCentroid(2), 'wX', 'markers',15) 
end 

しかし、私は私は赤で概説した画像の一部に白い斑点を保持する:従って

、全てprev_*変数。

これを行うにはどうすればよいですか?

+0

したがって、場所のコレクションがあり、前の2つのポイントから少なくとも50離れているすべてのポイントを検索する必要があります。現在のメソッドで何が問題になっていますか?その領域にスポットを入れたい場合は、 'inpolygon'を使うことができます。 – Gelliant

+0

現在の方法(上記の画像を生成した)では、非常に近いところに多くのマーカーがあります。 – nini

答えて

0

kmeansクラスタリングを使用できます。バウンスのkmeansクラスタリングを読んでください。

clc ; clear all ; 
I=imread('r7oR4.jpg'); 
I = rgb2gray(I) ; 
%% Remove borders 
n = 30 ; 
I1 = I(n:end-n,n:end-n) ; 
[y,x,val] = find(I1) ; 
%% 
N = 5 ; 
[idx,C] = kmeans([x,y],N) ; 
%% figure 
figure 
imshow(I1) 
hold on 
Cm = {'.r' '.b' '.g' '.y' '.m'} ; 
for i = 1:N 
    plot(x(idx==i),y(idx==i),Cm{i}) 

end 
0

この解決方法はどうですか?別の距離が近すぎる場合は、すべての(二乗された)距離をチェックし、ポイントを削除します。

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 
+0

自分のコードをスニペットに統合しました。しかし、私は今、写真にマーカーをつけていません。 – nini

関連する問題