How to make a loop on objects after watershed segmentation

I want to find objects with mean grayscale value <30 after watershed segmentation. But I don't know how to write the loop.After watershed, I think it is the segmented image is in label matrix (but not exactly sure). Could anyone give me a hand on writing this loop? Any help is appreciated.

 採用された回答

Matt J
Matt J 2018 年 2 月 23 日
編集済み: Matt J 2018 年 2 月 23 日

1 投票

No need for a loop,
stats=regionprops(labelmatrix, grayvalues, 'MeanIntensity');
index=[stats.MeanIntensity]<30;

6 件のコメント

Tian Tian
Tian Tian 2018 年 2 月 23 日
Thank you! In this way, how can I view the objects with the index in the image?
Matt J
Matt J 2018 年 2 月 23 日
編集済み: Matt J 2018 年 2 月 23 日
You mean how would you know, for example, which object corresponds to label number=2? One way would be to display the labelmatrix next to the original gray value image. The output structure "stats" will be ordered so that stats(i) corresponds to label number i.
Tian Tian
Tian Tian 2018 年 2 月 23 日
Sorry I feel a little bit confused. After applying the index (in your first comment), how can the object that selected using index be shown in the image to be view?
Image Analyst
Image Analyst 2018 年 2 月 23 日
You can loop through (untested):
for k = 1 : length(stats)
if index(k)
% Intensity is < 30
mask = ismember(labelmatrix, k); % Get this one blob only.
outputImage = grayImage; % Initialize
outputImage(~mask) = 0; % Blacken outside mask
figure; % Bring up new figure
imshow(outputImage, []);
end
end
Tian Tian
Tian Tian 2018 年 2 月 23 日
編集済み: Matt J 2018 年 2 月 23 日
Thank you for this loop. I am trying this, but there is always unexpected errors about my code. If it is possible, may you please have a look?
T = stats;
excelfilename = 'Picture2.xlsx';
writetable(T,excelfilename,'Sheet',1,'Range','A1');
column=xlsread(excelfilename, 'A:A')
H=length(column)
dbstop if error
for n = 1 : H
MeanIntensity(n)= T(n,'MeanIntensity')
if (MeanIntensity(n)<30)
% Intensity is < 30
mask = ismember(cc, n);
outputImage = I;
outputImage(~mask) = 0;
figure; % Bring up new figure
imshow(outputImage , []);
end
end
The error is "You cannot subscript a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts). Use a row subscript and a variable subscript." Thank you for your time in advance.
Matt J
Matt J 2018 年 2 月 23 日
@Tian Tian,
Please close this question (by Accept-clicking) and start a new one. The issue in your posted question has been addressed. The discussion is now well into other unrelated issues.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2018 年 2 月 23 日

コメント済み:

2018 年 2 月 23 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by