Using Coordinates from Figure(1) to index into Figure(2) scatter

1 次查看(过去 30 天)
I have a small difficulty... As you can see below, my script loads an image into a first Figure and then display a second figure using part of this image data :
The white 'circles' you see on the right Figure represents some of the image data (in CIE Lab).
I have created a MouseClick callback in Figure1 which gives me the x,y coordinates, that I use to index into the RGB image. Now, I would like to use these RGB / Lab coordinates to display a big square of some kind into the Figure on the right, so that, when the student click anywhere inside the image, they can 'see' in the right CIE ab diagram, where the color plots.
I will need to switch the 'slider' position around in order to show the correct L* slice. So that, for example, suppose the clicked RGB data is 0,0,255 (blue) then, this translated to Lab being L* = 32, I will need to update the plot to the L = 32 slice and THEN plot the a* and b* data, which are 79 and -107.
The "cherry on the icing", so to speak, would be for the student to click on one of the white circle, in the right Figure, and have its corresponding pixel show up in the image.
Any help is appreciated. I include the full m file, in case it helps.
I'm going to continue searching how to do this on my own...
  2 个评论
Roger Breton
Roger Breton 2022-2-1
Made some progress... I'm able to activate the correct Figure. The problem I run into is how to call the callback function using the new parameter ? I have this code executing in the First Figure :
RGB = inpict(IntY,IntX, :);
h = findall(0,'name',figurename);
figure(h); % Activate 'main' figure
ClickedPixel = rgb2lab([RGB(1) RGB(2) RGB(3)]);
sliderCB(ClickedPixel(1));
% sliderval = ClickedPixel(1);
% set(SliderH,'value',sliderval/100);
% update text label
% set(handles.lsliderdisplay,'String',num2str(round(sliderval)));
% updateplot();
I was considering manuall executing all the statements that are normally triggered by the Slider event but I 'reasoned' (?) I may only need to pass the new slider value to the slider call back? Which is defined this way :
function sliderCB(SliderH,~)
sliderval = SliderH.Value * 100;
% snap slider to closest bin center
[~,graylevelidx] = min(abs(sliderval - graylevels));
sliderval = graylevels(graylevelidx);
set(SliderH,'value',sliderval/100);
% update text label
set(handles.lsliderdisplay,'String',num2str(round(sliderval)));
updateplot();
end
I am aware that, as coded, the sliderCB callback only process the first parameter it receives as part of the event, since the is the presence of the tilde in the argument list. But Matlab gives me an error if I try to call the sliderCB function with only the first parameter :
Dot indexing is not supported for variables of this type.
Somehow, I have the intuition that I must "fill" the rest of the event parameters in my function call...
Roger Breton
Roger Breton 2022-2-1
I'm probably going about this the wrong way but here's my latest findings. I got this code :
ClickedPixel = rgb2lab([RGB(1) RGB(2) RGB(3)]);
Test = ClickedPixel(1) / 100
Roger = handles.lslider;
% Roger.Value = 0.62
Roger.Value = Test
sliderCB(handles.lslider);
If I execute the statement "Roger.Value" = 0.62 then Matlab is happy, the slider is updated and the plot is updated. Everything is hunky-dorey. But if I try to supply the value in not a litteral form, for some reason, as in "Test", then I get this error :
202 Roger = handles.lslider;
Invalid or deleted object.
Going in circles...

请先登录,再进行评论。

采纳的回答

Roger Breton
Roger Breton 2022-2-2
Can't say for sure why I was having an error in the first place, when trying to set the slider value through a variable, but Matlab is happy now to take it AND the trick was to use the notify command :
ClickedPixel = rgb2lab([RGB(1) RGB(2) RGB(3)]);
Test = ClickedPixel(1) / 100
Roger = handles.lslider;
Roger.Value = Test;
notify(Roger, 'Action');
I am not 100% sure I understand everything that I am doing but, in order to manually trigger the event, I need to use the notify command with the handle of the uicontrol and the 'Action' value. Patience...

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by