0

I'm working on a gui and using GUIDE. It loads and image and has the user draw an ROI around a point (the particle ROI). I would then like to have two sliders for creating a second ROI (the Scan ROI) where the user can use sliders to set the width and height of the second roi and see it updated on the image. The sliders seem to work ok but my gui keeps drawing a new roi on top of the image so it gets messy looking really fast. I would like to remove the user sizeable roi from the image before redrawing it (while still keeping the original particle ROI on the image. I currently do it the following way :

Inside the callback for the setroi size button (this should be for the particel ROI)

    handles=guidata(hObject);
particleroiSize=imrect;% - draw a rectagle around the particle to get a meausr eof ROI size
roiPoints=getPosition(particleroiSize); %-get tha parameters fo the rectanlge
partX1 = round(roiPoints(1));
partY1 = round(roiPoints(2));
partX2 = round(partX1 + roiPoints(3));
partY2 = round(partY1 + roiPoints(4)); % these are the ROi positions in pixels

roiHeight = round(roiPoints(3)); % - these are just the ROI width and height
roiWidth  = round(roiPoints(4));

handles=guidata(hObject); %_ update all the handles...
handles.partX1=partX1;
handles.partX2=partX2;
handles.partY1=partY1;
handles.partY2=partY2;

handles.roicenterX = (partX1 + round(roiPoints(3))/2);
handles.roicenterY= (partY1 + round(roiPoints(4))/2);

handles.roiHeight = roiHeight;
handles.roiWidth = roiWidth;
current_slice = round(get(handles.Image_Slider,'Value'));
particleImage=handles.Image_Sequence_Data(partY1:partY2,partX1:partX2,current_slice);
handles.particleImage=particleImage;

set(handles.RoiSizeDisplay,'String',strcat('Particle ROI is ',' ',num2str(roiHeight),' ', ' by ',num2str(roiWidth)) );

guidata(hObject,handles); 

And then inside the call back for the sliders that set the Scan ROI size I have (this is inside two different sliders one adjusts the width and one the height : handles=guidata(hObject);

try
  delete(handles.ScanArea);
  % plus any cleanup code you want
catch
end



WidthValue = get(handles.ScanAreaSliderWidth,'value');
HeightValue = get(handles.ScanAreaSliderHeight,'value');

set(handles.ScanAreaWidthDisplay,'String',strcat('Scan Area Width is ','  ', num2str(WidthValue))); % sets the display..now to do the drawing...


%h = imrect(hparent, position);
%position = [Xmin Ymin Width Heigth];
position = [ round(handles.roicenterX-WidthValue/2) round(handles.roicenterY-HeightValue/2) WidthValue HeightValue];

handles.ScanArea = imrect(handles.Image_Sequence_Plot,position);
%h = imrect(hparent, position)
handles=guidata(hObject);
guidata(hObject, handles);

But it never deletes the scan area ROI and keeps redrawign over it..I thought the try...catch would work but it doens't seem to. Am I making extra copies of the ROI or something? Please help.. Thanks.

dsolimano
  • 8,870
  • 3
  • 48
  • 63

2 Answers2

0

If you need to delete the ROI drawn with imrect, you can use findobj to look for rectangle objects (which are of type "hggroup") and delete them:

hfindROI = findobj(gca,'Type','hggroup');    
delete(hfindROI)

and that should do it. Since you first draw particleroiSize, which is of the hggroup type as well, you might not want to delete all the outputs from the call to findobj. If there are multiple rectangles in your current axis, then hfindROI will contain multiple entries. As such you might want to delete all of them but the first one, which corresponds to particleroiSize.

I hope i got your question right. If not please ask for clarifications!

Benoit_11
  • 13,905
  • 2
  • 24
  • 35
0

Thanks. This worked perfectly except that I had to use

hfindROI = findobj(handles.Image_Sequence_Plot,'Type','hggroup');
delete(hfindROI(1:end-1))

to get rid of everything but the first ROI, so I guessteh hggoup objects are added at the start ? (I thought I would use deleted(hfindROI(2:end)) to delete all but the first. Also, why does hfindROI return a list of numbers? Do they represent the hggroup objects or something like that? thanks..

  • Mhh honestly I would have guessed that (2:end) would be correct. Basically the list of numbers corresponds to the handles of all the objects of a given type (hggroup in your case) contained within the axes (handles.Image_Sequence_Plot). I thought the handles would be ordered according to the order in which they were created in the axes. – Benoit_11 Sep 04 '14 at 17:00
  • This is working, but it appears to be removing the handles to all the ROIs as well. I do want to delete the ROIs from the image, but I want to keep the handles to the ROI info..(i.e. the scan area height and width) is there a way to do this? – Jeff Spector Sep 05 '14 at 00:12
  • Yep you should be able to do something like; set(yourHandles,'Visible','off'); which will make them not visible without deleting them. – Benoit_11 Sep 05 '14 at 01:09