필터 지우기
필터 지우기

Determining new x,y location of an object

조회 수: 1 (최근 30일)
Sara
Sara 2012년 11월 28일
If I know the original x,y location of an object, then move it randomly to a different point on an image, how can I determine it's new x,y location?
  댓글 수: 2
John Petersen
John Petersen 2012년 11월 29일
If you moved it, just remember where you moved it to.
Jan
Jan 2012년 11월 30일
@Sara: Most likely the problem gets clear, when you post the relevant part of the code.
Of course the information where the parts of the scrambled image are located afterwards are available in your program already. But we cannot guess where or in which format.

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

답변 (3개)

Image Analyst
Image Analyst 2012년 11월 29일
  댓글 수: 1
Image Analyst
Image Analyst 2012년 11월 29일
If you move the object by deltaX and deltaY, then obviously the new location is
newX = startingX + deltaX;
newY = startingY + deltaY;
Needless to say, it's new position is (newX, newY). But this is way way too obvious (you wouldn't have even asked about something so trivial and simple) so we must have misunderstood your question. Can you try to describe it in more detail this time?

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


Sara
Sara 2012년 11월 29일
The object is moved via code. It is moved to a random location on the image.
  댓글 수: 5
Sara
Sara 2012년 11월 30일
Here is my code. I am not sending one tile to the same new location each time. What you say makes sense, I'm just not sure how that works with this:
A=mat2cell(image,[384,384],[256,256,256,256],[3]);
B=randperm(8);
C=reshape(B,2,4);
D=mat2cell(C,[1,1],[1,1,1,1]);
[row,col]=find(C==1)
D(row,col)=A(1,1)
[row,col]=find(C==2)
D(row,col)=A(1,2)
[row,col]=find(C==3)
D(row,col)=A(1,3)
[row,col]=find(C==4)
D(row,col)=A(1,4)
[row,col]=find(C==5)
D(row,col)=A(2,1)
[row,col]=find(C==6)
D(row,col)=A(2,2)
[row,col]=find(C==7)
D(row,col)=A(2,3)
[row,col]=find(C==8)
D(row,col)=A(2,4)
scram=cell2mat(D); fig3=figure('Visible','on'); imshow(scram)
Sara
Sara 2012년 11월 30일
편집: Sara 2012년 11월 30일
the intial location of the pedestrian is located in an excel file that i upload, and I am running this for about 500 images.

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


John Petersen
John Petersen 2012년 11월 30일
You know which cell in A that the pedestrian is located, right? Say it's the A(r,c) cell. Then,
ped = (c-1)*2 + r; % location of the pedestrian in A strung out,
% i.e. A(ped) = A(r,c)
B=randperm(8);
C=reshape(B,2,4);
D=mat2cell(C,[1,1],[1,1,1,1]);
for i=1:8
[row,col]=find(C==i) % move tile i to row,col
D(row,col)=A(i); % Build new image
if (C(i)==ped)
Row_newped = row; %FOUND PEDESTRIAN in New image
Col_newped = col;
end
end
There's probably a more efficient code that doesn't require a loop, but this should be clear to you so you understand the idea.
  댓글 수: 1
Sara
Sara 2012년 12월 3일
I apologize to everyone for being unclear. I am teaching myself Matlab and I appreciate everyone's help with this.
@John - Thank you for your post, I understand now what I need to do.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by