2017-01-04 8 views
-1

と、画像内の点への標識面積の最も近い点を探す:私は閉じて、MATLABで画像内の領域を指す見つけようとしているMatlabの

myimg = rgb2gray(imread('tissue.png')); %load grayscale example image of cells 
BW=bwareaopen(myimg<150,10); %only look at dark pixels, remove small objects 
BW=bwlabel(imfill(BW,'holes')) %fill holes of structures, label structures 
figure; 
imagesc(BW); %display image 

は、この例のコードを考えます

私はポイントに最も近い構造の最も近い点を見つけたいと思います。 [0,0]。これまでの私のアプローチは、すべての接続された構造体の重心をすべて取得し、それらのすべてをループして、最も近いもの(不正確で非効率的なもの)を見つけることです。

答えて

1

最も近い点を1つだけ探したい場合は、bwdistに2番目の出力引数を使用できます。これは、各点で入力画像の最も近い非ゼロ点の線形インデックスを含む行列を与えます。その後、ちょうどあなたが興味を持っている点に対応するインデックスを選択する必要があります。入力画像をbwdistにバイナリである必要があり、あなたのケースでは、あなたが

% Make the image binary 
binaryimage = BW > 0; 

% Get the linear indices of the closest points 
[~, idx] = bwdist(binaryimage); 

% Find the linear index for point (3, 2) 
x = 3; 
y = 2; 
pointindex = sub2ind(size(binaryimage), y, x); 

% Find the index of the closet point from the segmentation 
closestpointindex = idx(pointindex); 

% Get coordinates of the closest point 
[yc, xc] = ind2sub(size(binaryimage), closestpointindex); 

ような何かを試みることができるので、これはあなたの座標を与える(xc, yc)(x,y)に最も近い2値画像内の非ゼロ値を有する画素のマトリクスインデックス(closestpointindex)(ここでxおよびyはMatlabインデックスであり、Matlabインデックスは1から始まり、ローが最初であることを覚えている)、すなわちBW(y,x)

関連する問題