Invalid axes handle error message
11 views (last 30 days)
Show older comments
Hello all,
I have a GUI with two axes showing CT images (each with a slider to access different slices) and a image blend button. Before hitting the image blend button, the axes 1 shows the original stack of images, while axes 2 displays all white (set as default). Both sliders work without problems at this stage. After hitting blend, axes 2 correctly shows the slice of the blended image based on its current slider location. However, the same slider ceases to work at that point. When I try to move the slider, I get the error message "Error using axes Invalid axes handle". What is the problem here? Oddly, when I use "keyboard" to look at axes2, it still has a reasonable value (i.e. 14), so it is not accidentally cleared.
I am unable to get the needed support from my institution, thank you very much for your time.
if true
% --- Executes on button press in viewblend.
function viewblend_Callback(hObject, eventdata, handles)
% hObject handle to viewblend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SliderLocation = round(get(handles.slider1,'Value'));
Threshold = str2num(char(get(handles.threshold,'String')));
Iformatted40flip = handles.Iformatted40flip;
Coord = [307 128 17; 285 86 20; 258 126 23];
bin_mask = double(magicwand3(Iformatted40flip, Coord(:,1), Coord(:,2), Coord(:,3), Threshold));
se = strel('disk',8);
for i =1:33
bin_mask_c(:,:,i)= imclose(bin_mask(:,:,i),se);
bin_mask_cf(:,:,i)= imfill(bin_mask_c(:,:,i),'holes');
end
clear i
for n = 1:33
res(:,:,n) = Iformatted40flip(:,:,n).*bin_mask_cf(:,:,n)+Iformatted74flip(:,:,n).*~bin_mask_cf(:,:,n);
end
clear n
axes(handles.axes2)
handles.axes2 = imshow(bin_mask(:,:,SliderLocation), [0 1]);
% Update handles structure
guidata(hObject, handles)
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SliderLocation = round(get(handles.slider1,'Value'));
axes(handles.axes1)
Iformatted40flip = handles.Iformatted40flip;
handles.axes1 = imshow(Iformatted40flip(:,:,SliderLocation), [-335 223]);
set(handles.slider2,'Value', SliderLocation);
axes(handles.axes2)
bin_mask = handles.bin_mask;
handles.axes2 = imshow(bin_mask(:,:,34-SliderLocation), [0 1]);
set(handles.imindicator, 'String', 33-SliderLocation+1);
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SliderLocation = round(get(handles.slider2,'Value'));
axes(handles.axes2)
bin_mask = handles.bin_mask;
handles.axes2 = imshow(bin_mask(:,:,34-SliderLocation), [0 1]);
set(handles.slider1,'Value', SliderLocation);
axes(handles.axes1)
Iformatted40flip = handles.Iformatted40flip;
handles.axes1 = imshow(Iformatted40flip(:,:,34-SliderLocation), [-335 223]);
set(handles.imindicator, 'String', 33-SliderLocation+1);
end
0 Comments
Accepted Answer
Image Analyst
on 3 Feb 2016
Do not assign the output of imshow() to anything. It returns the handle to the image in the axes. You are overwriting the actual handle to the actual axes control itself, with the handle to an image inside of it, thus destroying it and making it unable to be used once you have done that.
More Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!