How to get find() results as a matrix?
Afficher commentaires plus anciens
Hi,
I have a binary image that was obtained from a color image (both were attached here). The background of the segmented image is black and the main object is white. I'm trying to use that binary image to get only the main object of the color image by using find() function.
I was able to do it using the following code:
I = imread(<binaryImage>);
I2 = imread(<color image>);
IMNONZERO = find(I); % this code returns only indexes of non-zero values
I3 = I2(IMNONZERO); % this gets all indexes of IMNONZERO in the I2 color image
imshow(I3);
This is my question: I saw that find() returns linear indexes. Also, I tried [row, col] = find(I) and it brings me the indexes of non-zero values as 2 separated arrays (one for row and another for column). However, I would like to know if it's possible to obtain those indexes as a regular matrix.
Is it possible?
Thank you in advance,
Queila
Réponse acceptée
Plus de réponses (1)
Philip Borghesani
le 30 Oct 2015
How about:
[ind(:,1),ind(:,2)]=find(I);
1 commentaire
Queila Martins
le 3 Nov 2015
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!