MATLAB: Image processing/Matrix manipulation question

image processingmatrix manipulation

Hello,
I have a 256×256 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

Best Answer

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)