tags:

views:

7782

answers:

2

I want to switch back and forth between two images, like blinking: 1 second for the first image and one second for second image.

+1  A: 

How are your images stored in Matlab? As a matlab movie or a 3 or 4 dimensional matrix depending on if the images are color or grayscale. Also, if you have the image processing toolbox, implay and immovie. Another option assuming that your images are in a mxnx3xk (rgb color) or a mxnxk (gray scale) matrix. Then the following should work. Assuming the following

  • Img - matrix storing image data either with dimensions mxnx3xk or mxnxk

  • handles.imageAxes - handle for the axis you want to display the image (set the tag of the axis to imageAxes in GUIDE)

Now you can loop through Img

for i=1:k
    % display the i^th image use `Img(:,:,i)` for a gray scale stack
    image(Img(:,:,:,i),'parent',handles.imageAxes);
    pause(1) % pause one second
end

that's it.

Azim
+4  A: 

I'm not totally sure of what you want to do (specifically what type of images you are trying to display), but here's some sample code that may do what you want:

image1 = imread('cameraman.tif');  % Load a test image
image2 = imread('circles.png');    % Load another test image

hAxes = gca;  % Get a handle to the current axes

for iLoop = 1:5,  % Loop five times
  imshow(image1,'Parent',hAxes);
  pause(1);
  imshow(image2,'Parent',hAxes);
  pause(1);
end

I used the general function IMSHOW, but this sometimes changes other properties of the figure/axes and that may not be to your liking (since you mention adding this to an existing GUI). You may want to use the IMAGE function instead. Also, instead of the for loop you could use a while loop that stops switching images when a condition is met (such as a button press).

gnovice