get pixel index from region props
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
majed majed
le 12 Juin 2015
Commenté : Image Analyst
le 9 Avr 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 commentaires
Benjamin Drewry
le 9 Avr 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
le 9 Avr 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.
Réponse acceptée
Image Analyst
le 12 Juin 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 commentaires
Image Analyst
le 17 Juin 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!