Effacer les filtres
Effacer les filtres

Image processing/Matrix manipulation question

2 vues (au cours des 30 derniers jours)
John Moseley
John Moseley le 26 Août 2013
Hello,
I have a 256x256 matrix (matrix 1) where the numerical value in each cell corresponds to an intensity value in an (x, y)-coordinate system (x=rows, y=columns). The intensity may take on a value of 0 or 255. First, I would like to extract the locations of the pixels in the (x, y)-coordinate system with intensity values of 255. Exactly how this is done likely depends on what I am trying to do next, but I assume the extracted coordinate locations will be stored in another matrix (matrix 2).
I also have a matrix (matrix 3) with four columns and thousands of rows. The middle two columns correspond to (x, y)-coordinates, e.g., {a, 1,1, b}, {c, 1,2, d}, etc. What I would like to do is form a fourth matrix (matrix 4) containing only the rows with the specific coordinate locations in matrix 2.
I would appreciate all help, thanks!
John

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 26 Août 2013
M1=randi([0 255],256,256) % Your matrix 1
[x,y]=ind2sub([256 256],1:256*256);
M2=[x' y' M1(:)] %
%--------------------------------
M3=[1 2 3 4;5 6 7 8 ;11 22 33 44;55 11 44 77];
M4=M3(:,2:3)
  3 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 27 Août 2013
matrix1=[0 0 0 255 0;255 0 0 0 255;0 0 0 255 0;0 0 0 0 255;255 0 0 0 0]
[ii,jj]=find(matrix1==255)
matrix2=sortrows([ii jj],[1 2])
matrix3= [10 1 4 20;11 1 5 12;14 2 1 25;44 6 1 1;4 4 5 8;1 7 8 1]
matrix4=matrix3(ismember(matrix3(:,2:3),matrix2,'rows'),:)
John Moseley
John Moseley le 27 Août 2013
Thanks, this is spot on.
John

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 26 Août 2013
The first question is easy:
matrix2 = matrix1 == 255;
For the second question, I'm not sure what you want. matrix2 does not have to have pixels in a rectangle but matrix4 must be rectangular, so I don't know how to build it unless you want matrix4 to just be a long list of pixel values pulled from matrix2 (or matrix1 - I can't tell). Please give a small example with like a 5 by 5 image.
  3 commentaires
Image Analyst
Image Analyst le 27 Août 2013
Modifié(e) : Image Analyst le 27 Août 2013
Why are these cell arrays instead of just regular old integer or double matrices? That complicates things. And I still don't understand the relationship between matrix4 and matrix2 that you mentioned in your original post. Can we assume that the middle columns of matrix3 are always identical to matrix2? Please give the final result for matrix4 because I'm still not sure what matrix4 looks like. Try Azzi's code - does that work?
John Moseley
John Moseley le 27 Août 2013
It seems that Azzi's code works. Probably my explanation could have been better. Thanks again.
John

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by