Lost in "Handle Land"...
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
Steven Lord
le 1 Fév 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!