Lost in "Handle Land"...
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!