regions of interest on 3D dataset

All,
I've got some 3D medical data (128x128x128) in a GUI. I'd like to be able to manually draw ROIs on about 25 of the images and use these for segmentation purposes. Firstly, is there a way I could draw the ROIs for each image sequentially, and secondly after all 25 ROIs have been manually drawn, go back and adjust any ROI vertex if necessary?
My current attempt involved using a togglebutton to store the positions of the ROIs while stepping through the dataset while the togglebutton is switched "on" (I used a while loop as I may want ROIs on 23 images, or 28 images, may not always exactly 25) but is failing miserably. This is my callback:
function segmentation_togglebutton_Callback(hObject, eventdata, handles)
flag = get(hObject,'Value'); %this =1 when toggle button is "on"
i = handles.current_im;
last = handles.total_im;
images=handles.images;
while flag==1
imshow(images(:,:,i),[], 'InitialMagnification', 'fit')
h=impoly;
position = wait(h);
contours{i}=position;
i = i+1
if flag==0 %i.e. toggle button is switched "off"
break
end
end
Thanks Jim

 Accepted Answer

Sean de Wolski
Sean de Wolski on 30 Oct 2012
Edited: Sean de Wolski on 30 Oct 2012
The problem is that the Toggle Button Callback does not stop the execution of the loop because the flag is never checked.
What you want to do is have the togglebutton callback throw away 'off' calls and 'enable' 'on' calls but have enabled check on each iteration if it's still on. The English on this isn't very clear I know! so here is the pseudocode
function tglbutton_callback(blha,blah)
if 'off'
return
end
while get(hObject,'value')
%check on each loop iteration if it's on
do_stuff
end
More
Consider this example function:
function example_togglin
hF = figure;
hTb = uitoolbar(hF);
hTg = uitoggletool('oncallback',@cb,'parent',hTb,'cdata',repmat(magic(16)./16^2,[1 1 3]));
function cb(src,evt)
cnt = 0;
while strcmp(get(src,'State'),'on') && cnt<20
cnt = cnt+1;
disp(['I''m on!!! Iteration: ' num2str(cnt)])
pause(0.25);
end
Save this as example_togglin.m and run it.

5 Comments

Hi Sean, Thanks for your reply. I may be missing something in your message, but in my loop I had a check for the "off" position of the button (albeit probably in the wrong position) through the use of
if flag==0 %i.e. toggle button is switched "off"
break
end
in the while loop. So in total, with your extra check at the start, I have
flag = get(hObject,'Value')
if flag ==0
test=1
return
end
while flag==1
if flag==0 %i.e. toggle button is switched "off"
test=2
return
end
imshow(images(:,:,i),[])
h=impoly;
position = getPosition(h);
contours{i}=position
i = i+1;
end
Which gives me the contours I need, but still doesn't end the while loop when the toggle is in the "off" state (i.e. flag ==0). The code is printing the dummy variable test=1 indicating that the button is in the off state, but impoly is still running and expecting input, meaning that I am still somehow stuck in the while loop.
Jim
The flag in your original will always be one! Because the condition is never checked once entering the while loop.
In mine, you don't need the flag==0 check because if the while loop is entered, then it is pushed down.
Thanks, much appreciated. I managed to edit your code in my program and understand how its working. For the benefit of others (who like me may not have used this option before), I have placed
hTg = uitoggletool('oncallback',@cb,'cdata',repmat(magic(16)./16^2,[1 1 3]));
in my opening function and
function cb(src,evt)
handles = guidata(src);
cnt = 1;
images=handles.images;
start = handles.current_im;
last = handles.total_im;
while strcmp(get(src,'State'),'on') && cnt<(last-start)
imshow(images(:,:,start),[])
h=impoly;
position = getPosition(h);
contours{cnt}=position;
cnt=cnt+1;
start=start+1;
end
elsewhere in the script.
Just a final question Sean, after I press the toggle button to switch off the impoly feature, the loop requires me to draw one final impoly. Is it possible to add another check after the image is displayed (using imshow) but before impoly is called to see if the button is still on? i.e. if button is not still on then don't call impoly
Thanks,
Jim
I supposed you could have the 'offcallback', explicitly grab the handle to the IMPOLY object, which you would need to store, and delete it or do whatever with it.

Sign in to comment.

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!