Prev: problems writing to excel file... please help
Next: get a mean of indexed data without using for loop
From: Varun on 20 May 2010 09:13 Hi all, I am making a GUI for dicom images, I have already read the images from a series and stored them into a 3D matrix. Now the next step is I have to display each image one at a time. I am new to GUI programming but I have read the theor behind it. I cant understand how to program the slider callback function in order to display images one at a time ! Can anyone please help me with this ? Thank You. Regards, Varun
From: RG on 20 May 2010 11:36 "Varun " <var3161(a)yahoo.co.in> wrote in message <ht3ch0$ni0$1(a)fred.mathworks.com>... > Hi all, > > I am making a GUI for dicom images, I have already read the images from a series and stored them into a 3D matrix. Now the next step is I have to display each image one at a time. I am new to GUI programming but I have read the theor behind it. I cant understand how to program the slider callback function in order to display images one at a time ! > Can anyone please help me with this ? > > Thank You. > > Regards, > Varun Hi Varun, I have done something similar using DICOM images, and I'm also a newbie with GUI programming. In my experience, if you want to show the images using 2D cross sections (one at a time) with the z-axis selected via a slider, you'll need to get comfortable using handles to pass values back and forth between objects in the GUI (using set and get functions). Generally speaking, any time you want to retrieve a property from an object you use the *get* function (get(handles.thatObject, 'property') substituting the 'property' string with whatever property it is you're trying to receive). When you want to apply a property to an object, you use the *set* function (set(handles.thatObject, 'property', value)). So, let's say you are trying to display your image (dicomImg) on an axes called showImgAxes and your slider (z-slice selection) is called sliderZ: 1) After loading your image, set the Min, Max, and SliderStep values based on your 3D image size (z-dimension). This can be done using set(handles.sliderZ, 'Min', 1), etc. 2) The slider callback function (sliderZ_callback) executes every time you change the value of the slider. Thus, here is where you would add your imshow command: 2a) First, get the value of the slider: currentSlice = get(hObject,'value'); 2b) Next, set your image display axes as the current axes: axes(handles.showImgAxes); 2c) Finally, display the image: imshow(dicomImg(:,:,currentSlice)); Note that you can do the same for coronal and saggital sections using a similar idea (basically you'd create an x slider to show a y-z slice and a y slider to show an x-z slice). Hope that helps. RG
From: Varun on 21 May 2010 06:03 Hi RG, Thanks a lot for posting such a detailed message, it really helped. but i like programmed as you said but then i am getting an error -> ????? The class "handles" is undefined. Perhaps Java is not running. Error in ==> GUI_without_GUIDE at 35 set(handles.slider1, 'Min', 1); I have designed the GUI without GUIDE since this is just a small part of a larger GUI that i am supposed to build and my code looks like this -> function GUI_without_GUIDE %% Beginning of outer function red_blue % Create figure f = figure('Visible','on','Name','My GUI',... 'Position',[360,500,600,600]); % Create an axes object to show which color is selected Img = axes('Parent',f,'units','pixels',... 'Position',[50 50 512 512]); % Create a slider to display the images slider1 = uicontrol('Style', 'slider', 'Parent', f, 'String', 'Image No.', 'Callback', @slider_callback, ... 'Units', 'pixels', 'Position', [231 5 100 20]); %DICOM image reading from the folder and setting slider parameters % saving the file names in dirOutput dirOutput = dir('*.dcm'); row = size(dirOutput,1); % reading the DICOM images into the 3D array 'dicom_images' for i = 1:row info = dicominfo(dirOutput(i).name); dicom_images(:,:,i) = dicomread(info); end dicom_images = mat2gray(dicom_images); %converting the matrix into grayscale movegui(Img,'onscreen')% To display application onscreen movegui(Img,'center') % To display application in the center of screen imshow(dicom_images(:,:,1)); set(findobj(gcf,'type','axes'),'hittest','off'); set(handles.slider1, 'Min', 1); set(handles.slider1, 'Max', row); set(handles.slider1, 'SliderStep', 1); %% Beginning of slider callback function function slider_callback(h, eventdata) axes(handles.Img); imshow(dicom_images(:,:,currentSlice)); end end Thanks a lot again, Varun
From: Varun on 21 May 2010 07:39
Hey RG, I have completed the image viewer part. Thanks a lot for ur help, it was really very helpful. Regards, Varun |