Multiple points using drawpoint in a panel with imscrollpanel
Show older comments
I have a code that opens two images and a scroll panel of the same images, and using drawpoint to select points to get the coordinates. I need to scroll the draggable window to select the points from different location of the image. The problem is when I drag the draggable window, the program selects a points before I even click the top image. Any solution will be greatly appreciated.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
scr_siz = get(0,'ScreenSize') ;
hFigL = figure ('Name','Control Point Selection','NumberTitle','off', 'Renderer',...
'painters', 'Position', [10 10 1800 1200], 'Toolbar', 'none',...
'Menubar', 'none');
movegui(hFigL,'center');
subplot(121)
ImageL= rgb2gray(imread('saturn.png'));
ImageL= imrotate(ImageL, -45);
hImL = imshow(ImageL);
axes1Handle=gca;
[M1, N1]= size(ImageL);
subplot(122)
ImageR= rgb2gray(imread('saturn.png'));
hImR= imshow(ImageR);
axes2Handle=gca;
[M2, N2]= size(ImageR);
hSPL = imscrollpanel(hFigL,hImL); % Handle to scroll panel.
set(hSPL,'Units', 'normalized',...
'Position', [0, .5, 0.5, .5])
hSPR = imscrollpanel(hFigL,hImR);
set(hSPR,'Units','normalized',...
'Position',[0.5 0.5 0.5 0.5])
hMagBox = immagbox(hFigL, hImL);
boxPositionL = get(hMagBox, 'Position');
set(hMagBox,'Position', [0, 0, boxPositionL(3), boxPositionL(4)]);
hOvPanelL = imoverviewpanel(hFigL,hImL);
set(hOvPanelL,'Units','Normalized', 'Position',[0 0 0.5 .5]);
hMagBoxR = immagbox(hFigL, hImR);
boxPositionR = get(hMagBoxR, 'Position');
set(hMagBoxR,'Position', [0, 0, boxPositionR(3), boxPositionR(4)])
hOvPanelR = imoverviewpanel(hFigL,hImR);
set(hOvPanelR,'Units','Normalized','Position',[0.5 0 0.5 .5]);
% Get the scroll panel API to programmatically control the view.
apiL = iptgetapi(hSPL);
apiL.setMagnification(2);
apiR = iptgetapi(hSPR);
apiR.setMagnification(2);
% Get the current magnification and position.
mag1 = apiL.getMagnification();
r1 = apiL.getVisibleImageRect();
%
apiL.setVisibleLocation(0.5,0.5);
apiR.setVisibleLocation(0.5,0.5);
%
mag2 = apiR.getMagnification();
r2 = apiR.getVisibleImageRect();
%
apiL.setMagnification(apiL.findFitMag())
apiL.setMagnificationAndCenter(4,M1/2,N1/2)
%
apiR.setMagnification(apiR.findFitMag())
apiR.setMagnificationAndCenter(4,N2/2,M2/2)
i=1;
while (i < 6)
axes(axes1Handle)
h1= drawpoint('Color','r');
h1.Label = sprintf('%d', i);
h1.LabelAlpha= 0;
h1.LabelTextColor= 'g';
x1(i)= h1.Position(1);
y1(i)= h1.Position(2);
axes(axes2Handle)
h2 = drawpoint('Color','r');
h2.Label = sprintf('%d', i);
h2.LabelAlpha= 0;
h2.LabelTextColor= 'g';
x2(i)= h2.Position(1);
y2(i)= h2.Position(2);
i = i + 1;
end
P= [x1; y1]
Q= [x2; y2]
Answers (0)
Categories
Find more on Build Interactive Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!