Clear Filters
Clear Filters

How can I display two images at once?

101 views (last 30 days)
Chelsea
Chelsea on 5 Nov 2014
Commented: hsinchia chen on 11 Jan 2022
Hi,
I can't seem to figure out how to display two images at the same time. I've read about subplots, figures, etc., but I just want to show two pictures side by side on the screen. Below is what I've tried with Psychtoolbox, but if you have any suggestions I would appreciate it!
win = Screen('OpenWindow',0); % Full sized screen
black=BlackIndex(win);
Screen('FillRect', win, black);
imagedata1=imread('11a.BMP');
imagedata2=imread('12b.BMP');
TexturePointer1=Screen('MakeTexture',win,imagedata1);
TexturePointer2=Screen('MakeTexture',win,imagedata2);
clear imagedata1;
clear imagedata2;
Screen('DrawTexture',win,TexturePointer1, 0);
Screen('DrawTexture',win,TexturePointer2, 0);
Screen('Flip',win);
WaitSecs(10);
sca;
  6 Comments
Laurie Gerstenberger
Laurie Gerstenberger on 23 Sep 2016
Sorry I did not say that but I have tried that too. I read in both images with imread. Then I resize them. Put them together with imshow(as you said). Then I make a texture of the concatenated image ( this is where the mistake probably is but I have not worked around yet :( ). and then i use Screen('DrawTexture'). If anyone knows where my mistake is I`d be truly happy.
Image Analyst
Image Analyst on 23 Sep 2016
Start your own question and be sure to post your two images.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 5 Nov 2014
Lots of ways
subplot(1,2,1);
imshow(imagedata1);
subplot(1,2,2);
imshow(imagedata2);
or
imshow([imagedata1, imagedata2]); % Assumes same number of rows in each.
Or you can use imshowpair() or imfuse().
  3 Comments
HARSH SHEDSHALE
HARSH SHEDSHALE on 21 Jan 2021
subplot(1,2,2);
what does (1,2,2) means ?
Image Analyst
Image Analyst on 21 Jan 2021
subplot() sets up a grid of "slots" where you can place a graph or image. The first number is the number of rows or images, the second number is the number of columns in the layout, and the third number is the plot number in natural left-to-right, top-to bottom manner. So if you wanted an array of 12 plots with 3 rows and 4 columns, it would be
subplot(3, 4, n);
where n is defined like in the 3,4 layout below
1 2 3 4
5 6 7 8
9 10 11 12
You can also combine numbers, so for example if you wanted one image to take up the whole 3rd row, you could do
subplot(3, 4, 9:12);
imshow(rgbImage);
If you wanted a plot in the 4th column you'd do
subplot(3, 4, [4,8,12]);
plot(x, y);

Sign in to comment.


Anand
Anand on 5 Nov 2014
Use imshowpair like Image Analyst suggests and you should be all fine.
The following gives you a side-by-side display:
imshowpair(im1, im2, 'montage')
  3 Comments
Hadeel H
Hadeel H on 2 Jun 2021
How about if we want to show the image on top of each others instead of side by side?
hsinchia chen
hsinchia chen on 11 Jan 2022
imshowpair(imrotate(im1,90), imrotate(im2,90), 'montage');
set(gca,'view',[90 90])

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!