pixel value of image using mouse
24 views (last 30 days)
Show older comments
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
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?
Accepted Answer
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!