A. Rpt
A. Rpt

Reputation: 13

MATLAB Shift the origin (0,0) of the pixels in my image

As an input of my code, I need to have some positions on my picture: the positions are in pixels and the origin (0,0) is in the CORNER top left of my picture

picture where positions are tracked with origin top left

The problem is that when I run my code which maps the positions on my picture, the origin shifts to the bottom left :

picture where positions are mapped with origin bottom left

So my question is : how could I also shift my input (positions of my picture1) so that it is relevant with the code process?

Thank you for your help, Aude

Upvotes: 1

Views: 1302

Answers (3)

Mendi Barel
Mendi Barel

Reputation: 3677

With images you reverse the Y axis:

set(ax,'YDir','reverse');

Upvotes: 0

Ander Biguri
Ander Biguri

Reputation: 35525

Adding an answer with a bit detail:

In computers, image processing etc it is the norm to have the (0,0) pixel in the top left corner. However, it is understandable that when you have x,y data, you'd want to plot it together with the image. Here some solutions:

imshow(image);
axis xy; % This line sets up the axis in a standard coordinate system

you can revert it with axis ij


Often, this is not enough. As imshow assumes that each pixel is in integer index position, and you may not have that. Maybe your data is in milimeters, or in any other arbitrary units. A solution to that is using imagesc

imagesc(img); 

is equivalent to imashow(img);axis xy. Additionally, you can choose arbitrary matrices for pixel locations as imagesc(x,y,img);


Finally, you can flipud your data for plotting, but I suggest you do that inline with the plot, so you dont modify the data itself.

imshow(flipud(img))

Upvotes: 1

Piglet
Piglet

Reputation: 28940

That would depend on your code. Maybe you can do it on-the-fly so you'll get the desired output right away.

If not just flip the output. You could use flipud for that.

https://de.mathworks.com/help/matlab/ref/flipud.html

Upvotes: 0

Related Questions