2014-09-04 83 views
0

我正在使用gui并使用GUIDE。它加载和图像,并让用户围绕某个点绘制ROI(粒子ROI)。然后,我想要两个滑块创建第二个ROI(扫描ROI),用户可以使用滑块设置第二个ROI的宽度和高度,并在图像上查看它的更新。滑块似乎可以正常工作,但是我的gui不断在图像的顶部绘制一个新的roi,所以它看起来很杂乱。我想在重新绘制图像之前从图像中删除用户大小的roi(同时仍然保留图像上的原始粒子ROI,我目前按照以下方式进行:在图像上绘制可调整大小的框

在setroi大小按钮的回调(应该是用于的质点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); 

然后该呼叫回该设置扫描ROI尺寸滑块我有(这是内的两个不同的滑块一个内调整宽度和一个高度: 处理= 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); 

但是,它永远不会删除扫描区域的ROI,并且不会重新绘制它。我认为try ... catch会起作用,但似乎没有。我是否额外制作了ROI或其他内容?请帮忙.. 谢谢。

回答

0

如果您需要删除与imrect得出的投资回报率,您可以使用findobj寻找矩形对象(这是类型的“hggroup”),并将其删除:

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

而且应该这样做。由于您第一次绘制的是particleroiSize,它也是hggroup类型的,因此您可能不希望删除调用findobj中的所有输出。如果当前轴上有多个矩形,则hfindROI将包含多个条目。因此,您可能希望删除它们中的全部,但第一个与particleroiSize对应。

我希望我的问题得到了解决。如果不是,请询问澄清!

0

谢谢。这工作完全不同的是,我不得不使用

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

摆脱一切,但第一ROI的,所以我guessteh hggoup对象是刚开始添加? (我想我会用删除(hfindROI(2:??结束)),删除所有,但第一此外,为什么hfindROI返回号码列表做他们所代表hggroup对象或类似的东西 感谢..

+0

Mhh诚实地说我会猜到(2:end)是正确的。基本上,数字列表对应于轴(handle.Image_Sequence_Plot)中包含的给定类型(hggroup)的所有对象的句柄。我认为这些手柄将根据它们在轴上的创建顺序排列。 – 2014-09-04 17:00:47

+0

噢,如果我的回答有帮助,您能否将它标记为已接受?谢谢,祝你好运! – 2014-09-04 17:01:10

+0

这是行得通的,但似乎我也想从图像中删除ROIs,但我想把手柄保持为ROI信息..(例如,扫描区高度和宽度)是有办法做到这一点? – 2014-09-05 00:12:27