get pixel index from region props

3 次查看(过去 30 天)
If someone help or try help to me ,I'll be so thankful : as shown in the image , I used 'regionprops' function to divide it into five regions. I want to copy any region (say the second region)from this image and put in a new image which has the same size as original image ,how can I get the pixel indices of that region . thank you.
  2 个评论
Benjamin Drewry
Benjamin Drewry 2019-4-9
this is how I do it, but there are probably better ways. I.e. to separate out the 'jacket' region of the matlab provided pout image
img=imread('pout.tif');
mask=img>130;
bwlabel(mask);
figure(); imagesc(ans);
stats=regionprops(mask, 'all');
bkdg=zeros(img);
y=stats(25).PixelList(:,2);
x=stats(25).PixelList(:,1);
for i=1:length(I)
bkdg(y(i),x(i))=1;
end
figure(); imagesc(bkdg);
final=double(img).*bkdg;
figure(); imagesc(final);
Image Analyst
Image Analyst 2019-4-9
Benjamin, please fix the code (so it at least runs), and put it down in the official "Answers" section, not up here in the comments section where we ask posters for additional clarification.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2015-6-12
You can do that, but it's not the most efficient way, so I won't go into it (besides, it's more complicated). The way you want to do it is with ismember(). You use your labeled image and create the 5 new images with ismember
[labeledImage, numRegions] = bwlabel(binaryImage);
binaryRegion1 = ismember(labeledImage, 1) > 0;
binaryRegion2 = ismember(labeledImage, 2) > 0;
binaryRegion3 = ismember(labeledImage, 3) > 0;
binaryRegion4 = ismember(labeledImage, 4) > 0;
binaryRegion5 = ismember(labeledImage, 5) > 0;
  3 个评论
Image Analyst
Image Analyst 2015-6-17
majed's "Answer" moved here:
thanks a lot , your technique works good . but how can i remove any region from the original image and put in zeros image(with the same size as original one) in the same position(indices) as the original one.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by