How to select ROI?

3 vues (au cours des 30 derniers jours)
Hai Nguyen
Hai Nguyen le 10 Mai 2017
When I move the Z axis, the ROI is lost. Thank you for your help.
function LoadImageGUI2() handles.hfig = figure(4000); set(handles.hfig,'units','pixels','color',[0.925 0.913 0.687],'numbertitle','off','name','[GUI] Stack converter','menubar','none','tag','interface'); handles.load=uicontrol('Style','pushbutton','Units','normalized','Position',[0.85 0.8 0.1 0.1],'String','Load File','BusyAction','queue','callback',@load_stack); handles.plot = axes('Position',[.05 .25 .7 .7]); handles.Zplane = uicontrol(4000,'style','slider','units','normalized','position',[0.05 0.1 0.7 0.05],'callback',@changeZplane); handles.zplane_indicator=uicontrol(4000,'Style','text','Units','normalized','Background',[.8 .8 .4],'Position',[0.8 0.12 0.18 0.03],'string','z-plane = #','HorizontalAlignment','left'); handles.load=uicontrol('Style','pushbutton','Units','normalized','Position',[0.85 0.7 0.1 0.1],'String','ROI','BusyAction','queue','callback',@ROI); handles.load=uicontrol('Style','pushbutton','Units','normalized','Position',[0.85 0.6 0.1 0.1],'String','Choose ROI','BusyAction','queue','callback',@choose_ROI); handles.load=uicontrol('Style','pushbutton','Units','normalized','Position',[0.85 0.5 0.1 0.1],'String','Confirm ROI','BusyAction','queue','callback',@confirm_ROI); guidata(4000,handles) % Update handles structure
function load_stack(hObj, eventdata, handles) handles=guidata(4000); [filename, pathname] = uigetfile('*.tiff', 'Select a MATLAB code file'); if isequal(filename,0) disp('User selected Cancel') else handles.filename=[pathname, filename]; a=imread(handles.filename,1); set(handles.zplane_indicator,'string', ['z-plane =' num2str(1)]); info = imfinfo([pathname filename]); num_images = numel(info); axes(handles.plot); imshow(a); handles.a=a; set(handles.Zplane, 'Min', 1); set(handles.Zplane, 'Max', num_images); set(handles.Zplane, 'Value', 1); set(handles.Zplane, 'SliderStep', [1/(num_images-1) , 1/(num_images-1) ]); handles.lastSliderVal = get(handles.Zplane,'Value'); % save the current/last slider value guidata(4000, handles); % Update handles structure end guidata(4000, handles); % Update handles structure end
function changeZplane(hObject, eventdata)
handles=guidata(4000);
newVal = floor(get(handles.Zplane,'Value')); % set the slider value to this integer which will be in the set {1,2,3,...,12,13}
set(handles.Zplane,'Value',newVal); % now only do something in response to the slider movement if the new value is different from the last slider value
if newVal ~= handles.lastSliderVal % it is different, so we have moved up or down from the previous integer save the new value
handles.lastSliderVal = newVal; % display the current value of the slider
set(handles.zplane_indicator,'string', ['z-plane =' num2str(newVal)]);
end
a = imread(handles.filename,newVal);
axes(handles.plot);
imshow(a,[]);
guidata(4000, handles); % Update handles structure
end
function ROI (obj,eventdata)
handles=guidata(4000);
axes(handles.plot);
h = imrect(gca, [10 10 100 100]);
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(h,fcn);
guidata(4000, handles)
end
function choose_ROI(obj,eventdata)
handles=guidata(4000);
%data=guidata(gcbf);
%delete(data.h); %Delete imcrop rectangle
%stockage_rectangle=getappdata(0,'stockage_rectangle'); %Display the ROI that has been choosen on the axes
rectangle=getappdata(0,'stockage_rectangle');
axes(handles.plot);
hold on
%data.rectangle_view.z=rectangle('Position',stockage_rectangle(data.image_counter_matlab,:),'Edgecolor','b');
rectangle_view.z=rectangle('Position',stockage_rectangle(data.image_counter_matlab,:),'Edgecolor','b');
%-----Save projectz first frame
storage_frame=getappdata(0,'storage_frame');
storage_frame(1)=getframe(gca);
setappdata(0,'storage_frame',storage_frame);
guidata(4000, handles)
end
end
%

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by