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?

2 ビュー (過去 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 Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by