pixel value of image using mouse

24 views (last 30 days)
Jason
Jason on 18 Feb 2014
Answered: Image Analyst on 18 Feb 2014
I have loaded an image (grayscale) onto an axes (guide). I want to be able to use the mouse to extract the intensity values and although there is some useful info in the searches, I haven't yet found a solution that works.
there seems to be 2 ways, both I have put under the "axes1_ButtonDownFcn" callback. Currently neither are working. Is there an obvious mistake? Thanks Jason
function axes1_ButtonDownFcn(hObject, eventdata, handles)
method 1
IM=getappdata(0,'Image'); %previosuly saved.
axes(handles.axes2);
ah = get( imageHandle, 'Parent' );
p = get( ah, 'CurrentPoint' )
or method 2:
IM=getappdata(0,'Image'); %previosuly saved.
axes(handles.axes2);
[x,y] = ginput(1); % User to select 3 points.
x = int32(x) % Round and cast to integer.
y = int32(y)
intensity1 = IM(y(1), x(1))
% Plot those points over the image.
hold on;
plot(x, y, 'r+', 'MarkerSize', 40, 'LineWidth', 5);
  2 Comments
Image Analyst
Image Analyst on 18 Feb 2014
Edited: Image Analyst on 18 Feb 2014
Method 2 should work. What happens? Are you saying that x and y are not created? Are you saying that intensity1 is not created? Did you step on those lines in the debugger? But you probably don't want them in the buton down callback. Why don't you just call impixelinfo and have a "live" update of pixel values as you mouse around?
Jason
Jason on 18 Feb 2014
I can only get it to work if I put the code under a pushbutton callback. Its almost as if the buttondownFcn callback isn't being called :-(
I also like the following, but again only working under a push button call back.
hp = impixelinfo;
set(hp,'Position',[5 1 300 20]);
Is it possible to get either only when the mouse is over the image (which is inside the axes object?)
Thanks

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 18 Feb 2014
Putting it in the button down function is weird because you first have to click to get into that function and then you have to click again to specify the points. Are you sure you're clicking enough times?
impixelinfo will give you the gray level information live without needing to click on anything. You can set it up immediately after you call imshow(). You do not need to have it in a pushbutton callback.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!