以下のコードを実行した後、以下のイメージがあります。線を引き、サーキュラー領域を切り取ります
file='grayscale.png';
I=imread(file);
bw = im2bw(I);
bw = bwareaopen(bw,870);
imwrite(bw,'noiseReduced.png')
subplot(2,3,1),imshow(bw);
[~, threshold] = edge(bw, 'sobel');
fudgeFactor = .5;
im = edge(bw,'sobel', threshold * fudgeFactor);
subplot(2,3,2), imshow(im), title('binary gradient mask');
se = strel('disk',5);
closedim = imclose(im,se);
subplot(2,3,3), imshow(closedim), title('Connected Cirlces');
cc = bwconncomp(closedim);
S = regionprops(cc,'Centroid'); //returns the centers S(2) for innercircle
numPixels = cellfun(@numel,cc.PixelIdxList);
[biggest,idx] = min(numPixels);
im(cc.PixelIdxList{idx}) = 0;
subplot(2,3,4), imshow(im), title('Inner Cirlces Only');
c = S(2);
マイターゲットは円形の物体の周りに赤cirleを描画(画像参照)、原画像から円形領域(面積)を切断することになりました「私は」とトリミングされた領域を節約するようイメージを作成したり、他のタスクを実行できます。どうしたらいいですか?
fminconで 'img'とは何ですか? –
@Nektar a typo。アップデート – Shai
あなたの解決策は正しいですか?しかし、バイナリマスクの代わりに、円領域を切り抜きたい。私はイメージ "私"から "bw"を得たと言うことができます。では、検出された円を「私」からどのように切り取ることができますか?または、 "I"にバイナリマスクを適用して、唯一の円領域が変更されずに残りの領域が黒くなるようにします。 –