Can I sort Find function base on rows?

Hello
I use find function to find location of a vector on my Image, It works, but I have location Order by column.I mean at firs I have location of pixels on column1 then column2,..... Can I change find function to have location of pixels on row1,row2,.....?
I'll appreciate your help.

댓글 수: 3

Roger Stafford
Roger Stafford 2014년 3월 4일
I don't understand your question, Bkshn. Matlab's 'find' function finds the locations of individual nonzero elements within arrays. It doesn't find "location of a vector on my Image". Could you please explain what you mean by "location of pixels on column1" and "location of pixels on row1,row2,.....?" Please give some very simple examples.
Image Analyst
Image Analyst 2014년 3월 4일
편집: Image Analyst 2014년 3월 4일
I agree - totally confusing. Posting the image would probably help, as well as reading this. And say what you want to do once you have this. Because I suspect you don't even need it. I think you might be able to do what you want to do just with a binary image - no need to get (x,y) coordinates of every single non-zero pixel. I mean, why? Why do you think you need that? There are some situations (e.g. edge linking) but I'd like to know your reason.
bkshn
bkshn 2014년 3월 5일
편집: Walter Roberson 2014년 3월 15일

Hello Image Analyst

I'm working on seam carving(one of content aware image resizing methods).Then I need to khnow location of seam to cut it from my Image.I try to attach my image or insert it, But I can't do it compeletly. as you see I have a vector on the left of my image.

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

답변 (2개)

Julian
Julian 2023년 8월 3일

1 개 추천

I couldn't find a nice solution in the documentation, so I assume the best way is instead of:
A = [1 0;
0 1;
1 0];
[row, col] = find(A);
% Results:
% row = [1; 3; 2]
% col = [1; 1; 2]
Transpose the matrix A and exchange the row and column:
[col, row] = find(A.');
% Results:
% row = [1; 2; 3]
% col = [1; 2; 1]
Walter Roberson
Walter Roberson 2014년 3월 4일

0 개 추천

[row, col] = find(.....);
cr = sortrows([col(:), row(:)];
r = cr(:,2);
c = cr(:,1);
now r(K), c(K) is a (row, column) pair and the pairs are ordered so that column varies more slowly. But it normally would anyhow. So perhaps what you want is
[row, col = find(.....);
rc = sortrows([row(:), col(:)]);
r = rc(:,1);
c = rc(:,2);
and that should be ordered with row varying more slowly, "going along rows", the opposite of what would normally happen.

댓글 수: 6

Image Analyst
Image Analyst 2014년 3월 4일
Which would be slower than the "normal" way of going down rows in a column before moving over to the next column. So why is this wanted? I'm still waiting to hear.
bkshn
bkshn 2014년 3월 5일
when I use
cr = sortrows([col(:), row(:)]; and rc = sortrows([row(:), col(:)]);
I see this error
Undefined function or variable "col".
so I replace col by c and row by r.
is it ok?
It works!
Thank alot Walter Roberson
bkshn
bkshn 2014년 3월 14일
Hello Walter Roberson
as I checked your answer sort my matrix base on row and col, could you help me How can I sort my matrix just base on row not col?
I'll appreciate your help
With regards to your March 5 response, it appears you missed the line
[row, col] = find(.....);
which give values to row and col.
With regards to your more recent question, you have not defined what you want to have happen when there are multiple entries with the same row but with different columns. When you define what you want to have happen in that case, the code can be adjusted.
bkshn
bkshn 2014년 3월 16일
I have a 5*2 matrix like A=[3,4;2,5;1,6;4,7;5,9;]
your answer sort this like A=[1,4;2,5;3,6;4,7;5,9;] , as you see it sort rows and column
but I want to sort just rows like
A=[1,6;2,5;3,4;4,7;5,9;]
Walter Roberson
Walter Roberson 2014년 3월 16일
sort(A,2)
but you are now not working with vectors returned from find(), which are indices with row(K) corresponding to col(K) after the find and row(K), col(K) giving the location of what was found; you are now sorting by array content based upon the full array, which is a different task.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2014년 3월 3일

답변:

2023년 8월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by