Invalid axes handle error message
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2016-2-3
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!