Azzera filtri
Azzera filtri

ginput with scroll panel does not work when running from a gui

1 visualizzazione (ultimi 30 giorni)
I have a code that opens an image and a scroll panel of the same image, and using ginput i select points to get the coordinates. The code works fine when i run it from the workspace, but doesn't work when i run it from a gui. The problem is that when i run it from the gui, matlab uses the ginput function on the scroll panel and not on the image. Any help will be appreciate it.
here's the code:
drawnow
[nomb, direc]=uigetfile('*.jpg', 'Abrir Imagen para análisis');
if nomb == 0
return
end
rgbImage = imread(fullfile(direc,nomb));
% 1. Create a scroll panel.
hFig = figure('Toolbar','none',...
'Menubar','none');
hIm = imshow(rgbImage);
hSP = imscrollpanel(hFig,hIm);
set(hSP,'Units','normalized',...
'Position',[0 0 1 1])
% 2. Add a Magnification Box and an Overview tool.
hMagBox = immagbox(hFig,hIm);
pos = get(hMagBox,'Position');
set(hMagBox,'Position',[0 0 pos(3) pos(4)])
imoverview(hIm)
% 3. Get the scroll panel API to programmatically control the view.
api = iptgetapi(hSP);
% 4. Get the current magnification and position.
mag = api.getMagnification();
r = api.getVisibleImageRect();
% 5. View the top left corner of the image.
api.setVisibleLocation(0.5,0.5)
% 6. Change the magnification to the value that just fits.
api.setMagnification(api.findFitMag())
% 7. Zoom in to 1600% on the dark spot.
api.setMagnificationAndCenter(2,306,800)
v = ginput;
[var1,var2] = size(v);
v2 = zeros(var1,var2);
v2(:,1) = v(:,2);
v2(:,2) = v(:,1);

Risposta accettata

Geoff Hayes
Geoff Hayes il 1 Giu 2014
According to the documentation for ginput (type help ginput in the Command Window), this function/command ...gets N points from the current axes and returns the X- and Y-coordinates…. So if you can switch the axes to that of your image, ginput should work for that.
Suppose that I and J are two images that I want to display in two figures:
figure;image(I);axes1Handle=gca;
figure;image(J);axes2Handle=gca;
Two images are displayed, and the axes handles for each are stored in two variables. Now when I type ginput, the cross-hairs naturally appear on the second image. And will continue to do so unless I manually select the other figure OR type the following
axes(axes1Handle)
which sets the current axis to that of the first image/figure. Now typing ginput brings up the cross-hairs on the first image.
You should be able to do the same in your script. Get the axes of the figure for the image and save it to a local variable. Just prior to using the command ginput switch the current axes to that of the image.
See if this helps. I can't test out your code since I don't have the Image Processing Toolbox.

Più risposte (0)

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by