how do I select only the segmented region from a original image in MATLAB

3 ビュー (過去 30 日間)
kashif Mobeen
kashif Mobeen 2021 年 6 月 20 日
コメント済み: Image Analyst 2021 年 6 月 20 日
I need a little help.
I have a MATLAB code in which I've segment out an original image into multiple segments. Now I want to select only a specific segmented area and give it as an input to my function. I have attached my segmented image in which desired part is shown along with the black pixels. How do I select only the desired region, I don't want black pixels region.
Thanks,
for k = 1:max(max(l))
color = img;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
image = double(segmented_images{k})/255.0;
end

採用された回答

Matt J
Matt J 2021 年 6 月 20 日
You could do,
S=regionprops(rgb_label,img,'Image')
  4 件のコメント
kashif Mobeen
kashif Mobeen 2021 年 6 月 20 日
How can I display every region?
imshow(S(1))??
imshow(S(2))??
......
Matt J
Matt J 2021 年 6 月 20 日
編集済み: Matt J 2021 年 6 月 20 日
For example,
for k=1:numel(S)
figure(i); imshow(S(k).Image)
end

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 6 月 20 日
You could do
mask = max(rgbImage, [], 3) > 0;
[r, c] = find(mask); % Find rows and columns of non-zero pixels
row1 = min(r);
row2 = max(r);
col1 = min(c);
col2 = max(c);
croppedImage = rgbImage(row1:row2, col1:col2, :);
  5 件のコメント
Matt J
Matt J 2021 年 6 月 20 日
No, there is no such thing as a non-rectangular image.
Image Analyst
Image Analyst 2021 年 6 月 20 日
Matt's right. Why do you want that anyway? Do you want transparent pixels, like I think PNG images can have so that you can see the background. I never do that since it has no real use in image analysis. If you think you need transparent pixels, explain why? Because I would counter that you don't, even though you think you might. It's not necessary to do any kind of image analysis on the image.

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by