Center a plot on top of an image in Matlab

1

I'm plotting over an image, however with the code below the plot happens at the beginning of the image at 0,0. I wish it was done from the center of the image in question. Code snippet:

image=imread('imagem.jpg');
imshow(image);
hold on;
plot(X,Y,'k-','linewidth',2)
hold off;
    
asked by anonymous 16.05.2014 / 04:17

1 answer

0

You can move the location where the image will be drawn by setting XData and YData to imshow . To center, you define that the position of the image (by default is [0,0]) is [-large / 2, height / 2].

Example

% carrega a imagem
image=imread('imagem.jpg');

% calcula a metade da altura e largura
image_sz = size(image) * 0.5;

% desenha a imagem deslocada
imshow(image, 'XData', [-image_sz(1) image_sz(1)],'YData', [-image_sz(2) image_sz(2)]);
hold on;

Demonstration

For the following image:

Andthisfunction:

t=0:0.0001:2*pi;x=50*cos(t);y=50*sin(t);plot(x,y)

Centralizingtheimage,youhave:

To center the function on the image you can simply move the function elements to the center of the image. For example:

For this function:

t = 0:0.0001:2*pi;
x = 50 * cos(t);
y = 50 * sin(t);

Scroll using:

x = x + image_sz(1);
y = y + image_sz(2);

What results in:

    
16.05.2014 / 05:31