get pixel index from region props
3 views (last 30 days)
Show older comments
majed majed
on 12 Jun 2015
Commented: Image Analyst
on 9 Apr 2019
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 Comments
Benjamin Drewry
on 9 Apr 2019
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
on 9 Apr 2019
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.
Accepted Answer
Image Analyst
on 12 Jun 2015
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 Comments
Image Analyst
on 17 Jun 2015
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.
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!