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?

1 次查看(过去 30 天)
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!

采纳的回答

Jason
Jason 2017-6-15
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.

更多回答(1 个)

Image Analyst
Image Analyst 2017-6-15
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.

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by