MATLAB Answers


Determining new x,y location of an object

Asked by Sara
on 28 Nov 2012

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?


If you moved it, just remember where you moved it to.

@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.


No products are associated with this question.

3 Answers

Answer by Image Analyst
on 29 Nov 2012

  1 Comment

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?

Answer by Sara
on 29 Nov 2012

The object is moved via code. It is moved to a random location on the image.


Let's take it one step at a time. You said "I know the original x,y location of an object" so let's assume it's at (50,50). Now let's say that your image is 1024 pixels wide by 960 pixels high and you chop it up into 2 tiles high by 4 tiles wide so that each tile is 480 pixels high and 256 pixels wide. Now let's say your scrambled the image (in code) so you know that you sent the upper left tile where your object was to the second rows, third panel over. So now the (50,50) point will be sent to the (50+480) row and the (50+256*2) column, or in other words, it's now at (row, column) = (520, 562). Make sense?

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:





















scram=cell2mat(D); fig3=figure('Visible','on'); imshow(scram)

the intial location of the pedestrian is located in an excel file that i upload, and I am running this for about 500 images.

Answer by John Petersen
on 30 Nov 2012

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)
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;

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 Comment

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.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!