Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using gui slider to display 3d image stack

302 views
Skip to first unread message

Alex

unread,
Dec 20, 2010, 3:16:05 PM12/20/10
to
I am new to GUI programming. I am trying to do the following:
1. Display an 3-D MRI image (represented as a stack of 2D images).
2. Use a slider to scroll through each image in the stack.
3. Get the axis coordinates on the image when the user clicks on the image.

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

ImageAnalyst

unread,
Dec 20, 2010, 3:23:25 PM12/20/10
to
If you're using a slider going from 0-1, then set the small step size
to be 1/numberOfSlices, and the large step size to be about 10 times
that. Check the calculated slice number to make sure it's not less
than 1.

Otherwise, I think you can just set the max value of the slider to be
numberOfSlices, and the small step size to be 1.

Alex

unread,
Dec 21, 2010, 10:20:38 AM12/21/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <46d17bdd-9920-4f27...@v23g2000vbi.googlegroups.com>...

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.

ImageAnalyst

unread,
Dec 21, 2010, 10:39:38 AM12/21/10
to
The rest of the GUI should not lose its functionality. Chances are
you didn't have a try/catch and it encountered an error. Look in the
command window right after you move the slider and look for a bunch of
red error messages.

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.

Mark Pether

unread,
Aug 11, 2015, 9:25:08 AM8/11/15
to
Hi Alex,

I was just wondering if you ever got a solution to this? I am having problems with exactly the same problem.

Thanks
0 new messages