Image 'CurrentPoint' properties does not exist? (appDesigner Image Component)

1 次查看(过去 30 天)
I found some code designed to retrieve an UIAxes component x,y coordinates when 'traversed' by the mouse :
pm.enterFcn = [];
pm.exitFcn = @(~,~) set(app.CurrentPositionEditField, 'Value', '');
pm.traverseFcn = @(~,~) set(app.CurrentPositionEditField, 'Value', sprintf('%.2f, %.2f', app.UIAxes.CurrentPoint(1,1:2)));
iptSetPointerBehavior(app.UIAxes, pm)
iptPointerManager(app.UIFigure,'enable');
set(app.UIFigure,'WindowButtonMotionFcn',@(~,~)NaN)
It works like a charm, except my application is not after 'charts' but 'images', RGB images. So I add an Image component to the interface and got this :
You see the image on the right? I would like to retrieve the mouse position when it hovers the image. And eventually use those coordinates to retrieve the image RGB pixel values.
So I tried to modify the above code, by changing the 'traverseFcn' and 'iptSetPointerBehavior' to use an Image component instead but, as it turns out, Image components don't have CurrentPoint properties?
I've been searching the Community, the internet and Matlab Help on how to do this to no avail.
Any help is appreciated.
  1 个评论
Rik
Rik 2022-1-4
As far as I can tell, uiaxes do have the current point property. Have you tried putting your callback in a separate function so you can do the indexing in a variable instead of the property?

请先登录,再进行评论。

采纳的回答

Roger Breton
Roger Breton 2022-1-5
I diverged quite a bit... Matlab's graphics is hard to conceptualize. But I'm sloooowly getting there. I had to put appDesigner on the back burner and go back to simple script file, in order to make some progress in my humble project. Here's the code I finally got :
global img
img=imread('Bird.jpg');
h = imshow(img);
set (gcf, 'WindowButtonMotionFcn', @mouseMove);
function mouseMove (object, eventdata)
global img;
C = get (gca, 'CurrentPoint');
SmallX = num2str(C(1,1));
SmallY = num2str(C(1,2));
RGB = img(SmallX, SmallY, :)
title(gca, ['(X,Y) = (', SmallX, ', ',SmallY, ') RGB = ', num2str(RGB(1)), ', ', num2str(RGB(2)), ' ,', num2str(RGB(3))]);
end
I tried very hard to stick with impixelinfo(). I found a way to extract the RGB values returned in the 'string' but I still had to convert RGB to Lab with a cform. My current solution may not be every elegant but it does what I want. Next step is to enhance the mouseMove function with a call to applycform or sRGB2Lab to obtain the Lab values for the image pixels. At that point, I'll add them to the title and be done.
I'm not sure I'll be able to "port" this code to my appDesigner app? We'll see. Thank you for your interest. Hope this helps someone. I'm really a Matlab newbie...
  1 个评论
Rik
Rik 2022-1-5
For general advice and examples for how to create a GUI, have look at this thread.
Using a global variable is not required.
For the title I would suggest using sprintf to compose the text.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by