Note: I have solved the problem on GUI closing down completely. There was a rogue close all in the ginput() routine. Calling by value and handles from other callbacks not updating during a specific nested callback routine still is a problem.
How can we select multiple pixels,multiple times from a Figure object in GUI (developed using GUIDE) ?
2 次查看(过去 30 天)
显示 更早的评论
I am writing a code which takes in a volume of MR image, displays the volume in 2D (squeezing 1 dimension). After selecting suitable anatomical plane, I select some pixels using ginput(), store the coordinates (3D) in an array, and then repeat the same process for a user defined number of times (multiple groups of pixels). I have the following problems:
1) While in callback routine for "Selecting Pixels", I found no way to update a check for button press ( where button press is to Squeeze Dimensions). Upon debugging, I observed the variable value is not being updated using guidata since the function is being called by value. 2) When the selectpixels routine executes a second time, the GUI created vanishes, and a blank figure appears.
I am unable to understand how to ensure the same GUI remains active, as I select multiple pixels. I have included my code here. Any help will be sincerely appreciated, thank you.
% --- Executes on button press in squeeze_1.
function squeeze_1_Callback(hObject, eventdata, handles)
% hObject handle to squeeze_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.vol;
pos = round(get(handles.volume_traverse,'Value'));
handles.bpress = 1;
% save the changes to the structure
guidata(hObject,handles)
I = squeeze(I(pos,:,:));
imshow(I,[]);
% --- Executes on button press in squeeze_2.
function squeeze_2_Callback(hObject, eventdata, handles)
% hObject handle to squeeze_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.vol;
pos = round(get(handles.volume_traverse,'Value'));
handles.bpress = 2;
I = squeeze(I(:,pos,:));
imshow(I,[]);
% save the changes to the structure
guidata(hObject,handles)
% --- Executes on button press in squeeze_3.
function squeeze_3_Callback(hObject, eventdata, handles)
% hObject handle to squeeze_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = handles.vol;
pos = round(get(handles.volume_traverse,'Value'));
handles.bpress = 3;
I = squeeze(I(:,:,pos));
imshow(I,[]);
% save the changes to the structure
guidata(hObject,handles)
% --- Executes on button press in pixelselect.
function pixelselect_Callback(hObject, eventdata, handles)
% hObject handle to pixelselect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% loopcheck = handles.num_groups;
% for i = 1:loopcheck
%Disabling unnecessary handles
set(handles.squeeze_1,'Enable','off')
if true
% code
endset(handles.squeeze_2,'Enable','off')
set(handles.squeeze_3,'Enable','off')
set(handles.pixelselect,'Enable','off')
count = 1;
n = handles.pixel_count;
while(count<handles.num_groups)
f_vt = @volume_traverse_Callback; %Handle for slider function to allow sliding while pixel select
[c1,c2] = getpixels(n,f_vt); %Get 2D coordinates
switch handles.bpress
case 1
pos = handles.pos.*ones(length(c1),1); %Create coordinates
M = zeros(length(pos),3);
M(:,1) = pos;
M(:,2) = c1;
M(:,3) = c2;
disp(M)
%Update structure with label here
case 2
pos = handles.pos.*ones(length(c1),1); %Create coordinates
M = zeros(length(pos),3);
M(:,1) = c1;
M(:,2) = pos;
M(:,3) = c2;
disp(M)
%Update structure with label here
case 3
pos = handles.pos.*ones(length(c1),1); %Create coordinates
M = zeros(length(pos),3);
M(:,1) = c1;
M(:,2) = c2;
M(:,3) = pos;
disp(M)
%Update structure with label here
end
count = count + 1;
end
set(handles.exportdata,'Enable','on')
0 个评论
回答(1 个)
Samarth Singh
2018-10-12
2 个评论
Image Analyst
2018-10-12
Glad it's solved. In the future, people could help you if you attach BOTH the m file AND the .fig file.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!