我正在使用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或其他內容?請幫忙.. 謝謝。
Mhh誠實地說我會猜到(2:end)是正確的。基本上,數字列表對應於軸(handle.Image_Sequence_Plot)中包含的給定類型(hggroup)的所有對象的句柄。我認爲這些手柄將根據它們在軸上的創建順序排列。 – 2014-09-04 17:00:47
噢,如果我的回答有幫助,您能否將它標記爲已接受?謝謝,祝你好運! – 2014-09-04 17:01:10
這是行得通的,但似乎我也想從圖像中刪除ROIs,但我想把手柄保持爲ROI信息..(例如,掃描區高度和寬度)是有辦法做到這一點? – 2014-09-05 00:12:27