meshCanopy and imhist problem

6 views (last 30 days)
Aman
Aman on 8 May 2013
Answered: Hari on 11 Jun 2025
I used meshCanopy function due to its wonderful visualization output and when I used it inside a GUI and a pushbutton I noticed a problem (code is below).
I used meshcanopy1 since I changed Line86 to %figure as was advised before in this section. Unfortunately, when I run the code the imhist loses its axes. I tried to changed the imhist NextPlot to all the options in the GUIDE property inspector but still it does not work well. Furthermore, it seems that it also effect the imshow axes.
Can someone please help to solve this issue and explain me why?
Code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output = hObject;
[file,path] = uigetfile({'*.tif','TIFF Image Files'},'Select image');
tifFile = strcat(path,file);
I = imread(tifFile);
axes(handles.Input);
imshow(I,[]);
grayImage = rgb2gray(I);
axes(handles.hist);
imhist(grayImage);
axes(handles.meshplot);
M = stdfilt(grayImage);
meshCanopy1(grayImage,M,@jet), title('');

Answers (1)

Hari
Hari on 11 Jun 2025
Hi,
I understand that you're using the meshCanopy1 function inside a GUI with multiple axes, and you're noticing that the histogram (imhist) and image display (imshow) stop rendering correctly after using meshCanopy1.
I assume that your GUI is built with GUIDE and that you have dedicated axes for displaying the image, histogram, and mesh plot.
In order to fix the issue of losing axes content and interaction, you can follow the below steps:
  1. Understand the source of the issue: The meshCanopy1 function likely changes the figure or axes context internally (such as by calling figure or implicitly switching axes). This disrupts the active axes in your GUI and causes MATLAB to draw in a new or unintended figure.
  2. Re-focus axes before plotting: Before each visual element is plotted (e.g., the image, histogram, and mesh), make sure that the GUI explicitly tells MATLAB which axes to use. This prevents plotting from being redirected to an unintended axes or figure.
  3. Clear axes before plotting: Use a method to clear the content of the axes before new content is plotted. This ensures the axes remains consistent and ready for the next image or plot.
  4. Prevent meshCanopy1 from altering figures: If you can modify the meshCanopy1 function, ensure it does not call figure internally or that it accepts an axes handle to draw in. Alternatively, make sure all plotting inside it is constrained to the correct GUI axes.
  5. Check GUIDE settings: In GUIDE’s property inspector, ensure the NextPlot property of each axes is set appropriately. For GUI work, it’s often best to use values like replacechildren to allow re-plotting without erasing the axes itself.
Hope this helps!

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!