Hi,
I wrote a program for viewing 4D images (x,y,z,t), one at a time. The user uses the left and right arrows to scroll through the z dimension, and the up and down arrows to scroll through the t dimension.
The problem is, I cannot figure out how to make it so that given a certain keystroke (for example, pressing enter), the figure will close and the function will terminate. I tried to put a bit of code like "if keystroke == enter, close", but that makes matlab crash.
Any ideas?
% Austin Bishop. April 2010. apb14@case.edu
%
% function scroll(vol)
% parameters:
% 'vol' is a 3D image matrix (x,y,z) where z is the image number.
% This function allows you to use the left and right arrow keys
% to browse through a collection of z images.
% Press leftarrow to move back
% Press rightarrow to move forward
% CTRLC to QUIT
% Uses imshow, so doubles should be converted to uint8
%
function scroll(vol)
figure('KeyReleaseFcn',@cb)
i=1;
k=1;
flag=0;
imshow(imresize(vol(:,:,i,k),2),[]);
maxi=size(vol,3);
maxk=size(vol,4);
title(strcat('Slice: ',num2str(i),'(',num2str(maxi),') Timepoint: ',num2str(k),'(',num2str(maxk),')'));
%fourflag=maxk>1;
function cb(src,evnt)
key = evnt.Key;
if strcmp(key,'leftarrow')==1
i=i+1;
end
if strcmp(key,'rightarrow')==1
i=i+1;
end
if strcmp(key,'uparrow')==1
%if fourflag==1
k=k+1;
%end
end
if strcmp(key,'downarrow')==1
%if fourflag==1
k=k1;
%end
end
if i<=0
i=maxi;
end
if i>maxi
i=1;
end
if k<=0
k=maxk;
end
if k>maxk
k=1;
end
imshow(imresize(vol(:,:,i,k),2),[])
title(strcat('Slice: ',num2str(i),'(',num2str(maxi),') Timepoint: ',num2str(k),'(',num2str(maxk),')'));
end
end
