I am having the following problems.
1. As soon as I scroll using the slider, I am no longer able to get the pixel info.
2. My slider will not scroll through every image. It gives non-integer values, so I use round(), but not every slice is represented.
I think my problems are that the figure is not refreshed after a callback and I don't know how to set the step size on the slider, but I don't know how to fix either of these. My code is below.
%%%%%%%%%%%%%%%%%%%%%%%
function displayIm3d(im)
sizeImg = size(im);
minSlice = 1;
maxSlice = sizeImg(3);
startSlice = round((maxSlice-minSlice)/2);
% Create a figure without toolbar and menubar.
hfig = figure('Toolbar','none',...
'Menubar', 'none',...
'Name','MRI Viewer',...
'NumberTitle','off',...
'IntegerHandle','off');
slider1 = uicontrol(hfig,'Style','slider','Callback',@slider1_Callback);
set(slider1,'value',startSlice); %
set(slider1,'max',maxSlice); %
set(slider1,'min',minSlice);
slice = get(slider1,'Value'); % returns position of slider
% Display the image in a figure with imshow.
himage = imshow(im(:,:,slice),'DisplayRange',[ ]);
hpixinfo = impixelinfo(himage);
set(himage,'ButtonDownFcn',@pixelInfo)
function slider1_Callback(slider1,eventdata,handles)
% update the displayed image when the slider is adjusted
slice = round(get(slider1,'Value'));
imshow(im(:,:,slice),'DisplayRange',[]);
end
function pixelInfo(cursor,eventdata,handles)
% get coordinates of clicked pixel
[ x, y ] = ginput(1)
end
end
Otherwise, I think you can just set the max value of the slider to be
numberOfSlices, and the small step size to be 1.
Great. Thank you. How should I go about fixing the other problem, that is, having the gui refresh/update after the slider is moved? The current callback function will change the image displayed, but the rest of the gui loses its functionality.
Long shot: Look for 'enable' in your code - you might be disabling
the controls, but I doubt it.
You might also try drawnow - that is used to force a screen update and
is most useful when you've changed something but then immediately
enter into an intensive loop - so intensive that the figure never gets
a chance to update itself.