필터 지우기
필터 지우기

Image processing/Matrix manipulation question

조회 수: 2 (최근 30일)
John Moseley
John Moseley 2013년 8월 26일
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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 26일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 27일
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 2013년 8월 27일
Thanks, this is spot on.
John

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 8월 26일
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
Image Analyst
Image Analyst 2013년 8월 27일
편집: Image Analyst 2013년 8월 27일
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 2013년 8월 27일
It seems that Azzi's code works. Probably my explanation could have been better. Thanks again.
John

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by