Q:

Matlab move image

How would I move an image along the x or y axis by clicking a button?
I have imported the image with 'image = imread('image.jpg');' and then use 'Left = uicontrol('Parent', gcf, 'Style', 'pushbutton', 'String','Left',...', but I am stuck there. I would like to move the image in any direction.

A:

You can create a simple callback function for the pushbutton, that changes XLim and YLim properties of axes showing the image.
Save the original limits:
xl = xlim;
yl = ylim;

For example to move image to the left:
step = 5; %# move by 5 pixels
xlim(xlim+step)

To move up:
ylim(ylim+step)

To restore the original position:
xlim(xl)
ylim(yl)

UPDATE:
Here is a working sample code (without using GUIDE):
im = imread('pout.tif');
imshow(im);
step = 5;
xl = xlim;
yl = ylim;
pbLeft = uicontrol('Parent', gcf, 'Style', 'pushbutton', 'String','Left', ...
    'Units','norm', 'Position', [0.4 0.05 0.1 0.05], 'Callback', 'xlim(xlim+step)');
pbReset = uicontrol('Parent', gcf, 'Style', 'pushbutton', 'String','Reset', ...
    'Units','norm', 'Position', [0.5 0.05 0.1 0.05], 'Callback', 'xlim(xl);ylim(yl);');
pbRight = uicontrol('Parent', gcf, 'Style', 'pushbutton', 'String','Right', ...
    'Units','norm', 'Position', [0.6 0.05 0.1 0.05], 'Callback', 'xlim(xlim-step)');
pbUp = uicontrol('Parent', gcf, 'Style', 'pushbutton', 'String','Up', ...
    'Units','norm', 'Position', [0.5 0.1 0.1 0.05], 'Callback', 'ylim(ylim+step)');
pbDown = uicontrol('Parent', gcf, 'Style', 'pushbutton', 'String','Down', ...
    'Units','norm', 'Position', [0.5 0.0 0.1 0.05], 'Callback', 'ylim(ylim-step)');

