Pixel Selection within a GUI

12 次查看(过去 30 天)
Okay soi have four small pictures within a GUI, i need the user select a single pixel from one of these four images. How would i go about selecting a pixel and getting the RGB value from that pixel. When i use impixel() it doesnt terminate after one click, is there a way to make it terminate after the user clicks once? I also keep getting NaN NaN NaN as the values when i use impixel() any idea why that would be happening? I would add code but its a GUI and there is just way too much to post here.

采纳的回答

Image Analyst
Image Analyst 2013-4-24
Like I said in your duplicate question you should be able to get the RGB values once you have the row and column from ginput as
rgbTriplet = rgbImage(row, column, :);
or
rgbTriplet = impixel(rgbImage, column, row);

更多回答(1 个)

Matt Kindig
Matt Kindig 2013-4-24
Easiest (although not particularly clean) way might be to use ginput(), and then round the return coordinates to select the pixel:
[x,y]=ginput(1);
pixel_x=round(x);
pixel_y= round(y);
pixel_val = img(pixel_x, pixel_y);
For a more "professional" look, you can set a ButtonDownFcn callback when the user clicks the image, and retrieve the 'CurrentPoint' property of the axes (which is set when the user clicks the underlying axes).

Community Treasure Hunt

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

Start Hunting!

Translated by