フィルターのクリア

image pixel info on

1 回表示 (過去 30 日間)
nirit
nirit 2016 年 8 月 18 日
コメント済み: nirit 2016 年 8 月 22 日
Hello.
I have 2 different images (image1, image2). I want to place the mouse (or click with it) on image1 (to get the (x,y) of that pixel), and to view the pixel value of image2 on that (x,y) location (the one I choose on image1).
how can that be done?
thanks.

採用された回答

Martin
Martin 2016 年 8 月 18 日
編集済み: Martin 2016 年 8 月 18 日
Hi Nirit, you can use the WindwoButtonMotionFunction of the Figure, your image 1 is in. Here is a quick example:
function m_easy_mouse_handling_example()
%example data
a = [1,1,1;2,2,2;3,3,3];
b = [10,12,14;16,18,20; 22 24 26];
%show the two figures
h_fig1 = figure()
h_ax1 = axes('Parent',h_fig1);
h_im1 = imagesc(a,'Parent',h_ax1);
h_fig2 = figure()
h_ax2 = axes('Parent',h_fig2);
h_im2 = imagesc(b,'Parent',h_ax2);
%set function which is used when mouse is over figure 1 (h_fig1)
set(h_fig1,'WindowButtonMotionFcn', @MouseMoveFcn)
function MouseMoveFcn(varargin)
try
mouse_pos = get(h_ax1, 'CurrentPoint');
ii = round(mouse_pos(1,1));
jj = round(mouse_pos(1,2));
%show value of image 2 in command line
disp(num2str(b(jj,ii))) %please check, if order of dimensions is correct
catch
%catch error, if you are outside the image (to do)
end
end
  1 件のコメント
nirit
nirit 2016 年 8 月 22 日
This seems to answer it. but now I have another problem:
both of the images are in unit16 (960x600). when I try to send them to MouseMoveFcn.m , for some reason, MouseMoveFcn.m receives them as:
WindowMouseData with properties:
Source: [1x1 Figure]
EventName: 'WindowMouseMotion'
what am i doing wrong? I only change the set to this:
set(h_fig1,'WindowButtonMotionFcn', {@MouseMoveFcn,h_ax1,a,b});
and :
function MouseMoveFcn (varargin)
display(varargin{2});
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by