How can we select multiple pixels,multiple times from a Figure object in GUI (developed using GUIDE) ?

2 vues (au cours des 30 derniers jours)
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')

Réponses (1)

Samarth Singh
Samarth Singh le 12 Oct 2018
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.
  2 commentaires
Image Analyst
Image Analyst le 12 Oct 2018
Glad it's solved. In the future, people could help you if you attach BOTH the m file AND the .fig file.
Samarth Singh
Samarth Singh le 12 Oct 2018
Modifié(e) : Samarth Singh le 12 Oct 2018
Sorry about that @Image Analyst - I shall keep that in mind. Please note I have still not been able to solve the callback nested routine issue. My handles do not update as I wish them , since they are called by value. Also, I have attached the m file as well as the .fig file, as advised. Both are WIP.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by