Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

code works when running from workspace, but doesn't work when running from gui

2 vues (au cours des 30 derniers jours)
Alejandro
Alejandro le 29 Mai 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have a code that display an image and an overview image with a scroll panel(from the same image). Using ginput i select some points and i get the coordinates from those points. The overview image allows me to move around (scroll panel), because the original image is too big (1800X1920). The code works fine when i run it from the workspace, but when i run it from a gui (button callback), does not. what happen is that when i run it from a gui, matlab thinks the overview image with the scroll panel is the principal image, and restrict the cross-hair to this image. The cross-hair has to be in the larger or principal image
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)
%plot_size = get(0,'ScreenSize');
%fg = figure(1);
%set(fg, 'Color', [1 1 1], 'Position', plot_size, 'Visible', 'on');
%imshow(a),
%title('lalala')
%figure, imshow(a,'InitialMagnification',1000);
%axis on
v = ginput;
[var1,var2] = size(v);
v2 = zeros(var1,var2);
v2(:,1) = v(:,2);
v2(:,2) = v(:,1);

Réponses (1)

Guillermo Soriano
Guillermo Soriano le 15 Jan 2018
variables made in the gui are not saved therefore workspace do not find values

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by