Lost in "Handle Land"...

1 view (last 30 days)
Roger Breton
Roger Breton on 1 Feb 2022
Answered: Steven Lord on 1 Feb 2022
I'm trying to index into a clicked image. I first read the image in and then, inside a nested function, I call imshow() :
A = imread('Oiseaux - Fairywren.jpg');
ciediagram_scatter(A);
function ciediagram_scatter(inpict)
imageHandle = imshow(inpict);
set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
In the ImageCallback function, I want to retrieve the RGB values corresponding the clicked x,y coordinates. So I use this code :
CP = round(get (axesHandle, 'CurrentPoint'));
x = CP(1,1)
y = CP(1,2)
IntX = cast(x, 'uint8');
IntY = cast(y, 'uint8');
% Image = 537 High x 360 Wide
% XData: [1 360]
% YData: [1 537]
RGB = inpict(IntY,IntX, :); <<<<< This call works
RGB = imageHandle(IntY,IntX, :); <<<<< This call does NOT work?
Whenever I try to execute the second call above, I invariably receive the following error :
Index in position 1 exceeds array bounds (must not exceed 1).
There must some kind of handle 'dereferencing' I am not doing? But I have no idea how to do this?
Any help is appreciated.

Answers (1)

Steven Lord
Steven Lord on 1 Feb 2022
The imshow function creates a scalar image object representing the picture as a whole. That object contains the color data as one of its properties. You will need to index into the CData property of that object.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!