2011-09-13 8 views
5

Sé que es solo una advertencia y no afectará el código ... pero mi problema es que necesito mostrar la imagen en su tamaño real sin ningún zoom out .. ¿es posible en la función imshow hay algún parámetro que haga esto?la imagen es demasiado grande para caber en la pantalla (MATLAB)

gracias a todos

+1

¿Ha considerado utilizar [IMTOOL] (http://www.mathworks.com/help/toolbox/images/ref/imtool.html)? – Amro

+0

Lo intenté ... funciona ... pero quiero 'imshow' para hacer eso debido a problemas de guardado usando' print' .. 'imtool' no me permitirá guardar la cifra –

+0

pregunta similar: [MATLAB: mostrando una imagen en su tamaño original] (http://stackoverflow.com/questions/1427602/matlab-showing-an-image-in-its-original-size) – Amro

Respuesta

3

Una solución que debería funcionar es para mostrar la imagen y luego cambiar los límites de los ejes de manera que haya un píxel de pantalla para cada píxel de la imagen:

%# read an image and make it large 
img = imread('autumn.tif'); 
img = repmat(img,[10,10]); 

%# turn off the warning temporarily, we're going to fix the problem below 
%# Note that in R2011b, the warning ID is different! 
warningState = warning('off','Images:initSize:adjustingMag'); 
figure 
imshow(img) 
warning(warningState); 


%# get axes limits in pixels 
set(gca,'units','pixels') 
pos = get(gca,'position') 

%# display the top left part of the image at magnification 100% 
xlim([0.5 pos(3)-0.5]),ylim([0.5 pos(4)-0.5]) 

Ahora puede seleccionar la mano (herramienta de desplazamiento) y mueva la imagen según sea necesario.

+0

@Jonas Heidelberg: se arregló. – Jonas

+1

muy genial :-). Puede agregar 's = warning ('off', 'Images: initSize: adjustingMag'); figura, imshow (img); advertencia (s); 'para evitar el mensaje de advertencia ... –

+0

(borrar comentarios antiguos que ya no se aplican ...) –

3

La solución dada por @Jonas, que ya he votado anteriormente, es realmente buena. Permítanme sugerir algunas mejoras menores para que maneje el caso cuando se cambia el tamaño de la figura:

%# read an image and make it large 
img = imread('autumn.tif'); 
img = repmat(img, [10 10]); 

%# new figure 
hFig = figure; 

%# try show image at full size (suppress possible warning) 
s = warning('off', 'Images:initSize:adjustingMag'); 
imshow(img, 'InitialMagnification',100, 'Border','tight') 
warning(s); 

%# handle figure resize events 
hAx = gca; 
set(hFig, 'ResizeFcn',{@onResize,hAx}) 

%# call it at least once 
feval(@onResize,hFig,[],hAx); 

%# enable panning tool 
pan on 

la siguiente es la función de cambio de tamaño de devolución de llamada:

function onResize(o,e,hAx) 
    %# get axes limits in pixels 
    oldUnits = get(hAx, 'Units'); %# backup normalized units 
    set(hAx, 'Units','pixels') 
    pos = get(hAx, 'Position'); 
    set(hAx, 'Units',oldUnits)  %# restore units (so it auto-resize) 

    %# display the top left part of the image at magnification 100% 
    xlim(hAx, [0 pos(3)]+0.5) 
    ylim(hAx, [0 pos(4)]+0.5) 
end 

screenshot

Probablemente se podría mejorar esta más allá para que al cambiar el tamaño de la figura, no siempre regrese a la esquina superior izquierda, sino que mantenga la posición actual.

+0

Nice additions! – Jonas

+0

gracias .. :) .. pero no funciona .. Creo que no funcionó debido al gran tamaño de la imagen .. es '1914-by-2294' –

+0

@OmarOsama: ¿qué tiene exactamente ¿fué mal? Está funcionando bien para mí. Por cierto, el tamaño de la imagen en mosaico en el ejemplo anterior es 2060x3450 .. – Amro

0

Nota: Para centrar la imagen (en lugar de mostrar la parte superior izquierda), utilice

xlim([(w_image - w_window)/2, (w_image + w_window)/2]); 
    ylim([(h_image - h_window)/2, (h_image + h_window)/2]); 

donde w_image y h_image son dimensiones de la imagen, y w_window y h_window son pos las respuestas anteriores (3) y pos (4), respectivamente.

Cuestiones relacionadas