Subplotting images with different scale

Hello,
I need some help. I want to show two different images (100x100 and 400x400). I could show them in different figures respecting their scale factor, but what I would like is to show both of them in the same figure. I mean one next to the other but respecting their scale, because what Matlab do is to show both image at the same scale but I want to respect their proportion to compare them (one smaller and one bigger)
Thank you for your help.
Regards,
Daniel

 採用された回答

Lucas García
Lucas García 2011 年 8 月 25 日

2 投票

Hi Daniel, I am not sure if I understand your question correctly, but maybe linkaxes is what you are looking for:
I1 = rand(100,100,3);
I2 = rand(400,400,3);
h1 = subplot(2,1,1);
image(I1)
h2 = subplot(2,1,2);
image(I2)
linkaxes([h2,h1])

5 件のコメント

Daniel
Daniel 2011 年 8 月 25 日
Hey! I tried but it didn't work. My code is like that:
img=imread('Princeton.jpg');
img_gray=rgb2gray(img);
img_crop=imcrop(img, [1786 1102 99 99]);
%Different types for scale an image. We are going to use a scale value
%equal 4 for the cropped image in Problem 1
scale=4;
%Nearest
img_nearest=imresize(img_crop,scale,'nearest');
% show_image(img_crop);
% show_image(img_nearest)
figure('name','Text String Specifying Interpolation Method')
subplot(1,2,1), imshow(img_crop), title('Original');
subplot(1,2,2), imshow(img_nearest), title('Nearest');
% %Bilinear
img_bil=imresize(img_crop,scale,'bilinear');
subplot(2,2,3), imshow(img_bil), title('Bilinear');
% %Bicubic
img_bic=imresize(img_crop,scale,'bicubic');
subplot(2,2,4), imshow(img_bic), title('Bicubic');
and I want to plot them in the same figure but with its scale factor, so the first one should look smaller than the other three. Thank you for your help!
Lucas García
Lucas García 2011 年 8 月 25 日
How about this Daniel:
img=imread('Princeton.jpg');
img_gray=rgb2gray(img);
img_crop=imcrop(img, [1786 1102 99 99]);
% Different types for scale an image. We are going to use a scale value
% equal 4 for the cropped image in Problem 1
scale=4;
% Nearest
img_nearest=imresize(img_crop,scale,'nearest');
figure('name','Text String Specifying Interpolation Method')
subplot(2,2,1); imshow(img_crop), title('Original');
subplot(2,2,2); imshow(img_nearest), title('Nearest');
% Bilinear
img_bil=imresize(img_crop,scale,'bilinear');
subplot(2,2,3); imshow(img_bil), title('Bilinear');
% Bicubic
img_bic=imresize(img_crop,scale,'bicubic');
subplot(2,2,4); imshow(img_bic), title('Bicubic');
h = get(gcf,'Children');
[~,sizeInd]= sort([numel(img_crop),numel(img_nearest),numel(img_bil),numel(img_bic),],'descend');
linkaxes(h(sizeInd))
Daniel
Daniel 2011 年 8 月 25 日
Thank you!!! That is working really good!
But can you explain a bit more what exactly you did?
Thanks again :)
Lucas García
Lucas García 2011 年 8 月 25 日
I'm glad it was what you were looking for.
The function linkaxes links the axes in the subplot of a figure so that all have the same axes length. However, axes must be provided in decreasing size, if we want the largest image to be the reference for all axes.
So, in "h" we obtain handles for all 4 axes. Then we sort the size images from largest to smallest. And finally, apply that order ("sizeInd") to the handles and link the axes in that specified order.
Daniel
Daniel 2011 年 8 月 25 日
Good to know!
Thank you very much for your help ;)

サインインしてコメントする。

その他の回答 (4 件)

Pramod Bhat
Pramod Bhat 2011 年 8 月 25 日

0 投票

I don think your need has any particular application.

3 件のコメント

Daniel
Daniel 2011 年 8 月 25 日
Well I just want to show both images in the same figure and I am asking if this is possible.
Anyway, thank you for your fast reply.
Sean de Wolski
Sean de Wolski 2011 年 8 月 25 日
There are dozens of applications for this. A simple one, that I used in my MS thesis, was for a block matching program, I wanted to show the small block at its real scale (16x16 pixels) and the big block at its real scale (32x32 pixels). On top of that I can think of numerous different reasons for it.
Sean de Wolski
Sean de Wolski 2011 年 8 月 25 日
*instead of dozens, I meant to say millions*

サインインしてコメントする。

BF83
BF83 2011 年 8 月 25 日

0 投票

I'm not sure, but perhaps you can use 'pbaspect'.
Sean de Wolski
Sean de Wolski 2011 年 8 月 25 日

0 投票

Create the figure and axes explicitly and then use them:
H.f = figure; %new figure
set(H.f,'units','pix','position',[100 100 700 500]); %needed size and pixels as units
H.A(1) = axes('units','pix','position',[50 50 100 100]); %small image axis
H.A(2) = axes('units','pix','position',[250 50 400 400]); %big image axis
%
axes(H.A(1));
imshow(magic(100),[]); %small magic square
axes(H.A(2));
imshow(magic(400),[]); %big magic square
Walter Roberson
Walter Roberson 2011 年 8 月 25 日

0 投票

image() and imagesc() allow you to specify the coordinates of the lower-left and upper-right pixel centers (not edges). You can place two images on the same axes in arbitrary relation to each other by choosing appropriate offsets and taking in to account the half-width to the pixel edges. The coordinates are data coordinates by default.

Community Treasure Hunt

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

Start Hunting!

Translated by