Lost in "Handle Land"...

1 回表示 (過去 30 日間)
Roger Breton
Roger Breton 2022 年 2 月 1 日
回答済み: Steven Lord 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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by