Lost in "Handle Land"...

1 次查看(过去 30 天)
Roger Breton
Roger Breton 2022-2-1
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.

回答(1 个)

Steven Lord
Steven Lord 2022-2-1
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by