How do I link an image and a histogram of that image so the histogram only represents what is shown in the image, i.e. if I zoom in on the image, the histogram updates?

7 vues (au cours des 30 derniers jours)
I have a gui with two axes, an image (created using imagesc) and a histogram of that image. I want to add a menu item that will allow the user to turn on/off the ability to link the histogram to the image so if the user zooms in/out, the histogram automatically updates with the image data that is shown (and ignore the image data that is not shown).
I am using Matlab 2016a.
Any suggestion is welcome.
Thanks!

Réponse acceptée

Jason
Jason le 15 Juin 2017
I was able to get this to work by setting the ActionPostCallback for the zoom function to call a custom function.
set(zoom(obj.ax1), 'ActionPostCallback',@(x,y) obj.redrawHistogram(obj.ax1));
and inside the redrawHistogram function I redraw the histogram based on the data being displayed.

Plus de réponses (1)

Image Analyst
Image Analyst le 15 Juin 2017
Use an imscrollpanel to contain your image and then call "getVisibleImageRect()":
% Here's the example from the documentation:
% Create a scroll panel with a Magnification Box and an Overview tool.
hFig = figure('Toolbar', 'none',...
'Menubar', 'none');
hIm = imshow('saturn.png');
hSP = imscrollpanel(hFig,hIm); % Handle to scroll panel.
set(hSP,'Units', 'normalized',...
'Position', [0, .1, 1, .9])
% Add a Magnification Box and an Overview tool.
hMagBox = immagbox(hFig, hIm);
boxPosition = get(hMagBox, 'Position');
set(hMagBox,'Position', [0, 0, boxPosition(3), boxPosition(4)])
imoverview(hIm)
% Get the scroll panel API to programmatically control the view.
api = iptgetapi(hSP);
% Get the current magnification and position.
mag = api.getMagnification();
r = api.getVisibleImageRect();
The full demo is attached.

Community Treasure Hunt

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

Start Hunting!

Translated by