How can I display two images at once?

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 Commenti

Hi guys,
I do have the same problem, but I am just starting with psychotoolbox and I can't really figure it out despite your anwswers, sorry!
I read in the images, then I make a texture and use Screen('DrawTexture',window,imagedata1);
Screen('Flip',window); to display them. This works perfectly fine for one picture, but when I want to use two where do exactly do I have to put the imshowpair function?
Do I also have to make a texture of the two images or how can I project them to the screen?
Your help would be really much appreciated!
Then just stitch them together
imshow([imagedata1, imagedata2]);
Laurie Gerstenberger
Laurie Gerstenberger il 23 Set 2016
Modificato: Laurie Gerstenberger il 23 Set 2016
Thanks for your answer! I still can not really figure out what my mistake is. I tried several different things:
1.) %% read in image data imagedata1=imread('1.jpg') imagedata2=imread('2.jpg')
imagedata1=Screen('MakeTexture',window,imaegdata1) imagedata2=Screen('MakeTexture',window,imagedata2); Then I tried to project them to the screen
with %% Screen('DrawTexture',window,imagedata1) Screen('DrawTexture',window,imagedata2)
%%stick them together imshow ([imagedata1,imagedata2]) and flip them to the screen. This does not work because it shows me both images on top of each other. So I tried to make textures of both images, stick them together with imshow and apply DrawTexture. This does not work either because I can not treat the combined image as one image. I also tried to use imshow directly after I read the images in. This gives me the following error: error using horzcat//Dimensions of matrices being concatenated are not consistent. Thanks again!
If you're going to stitch them together like I showed, the must be of the same vertical height. If they're not, you must use padarray() or imresize() to make them the same height.
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.
Start your own question and be sure to post your two images.

Accedi per commentare.

Risposte (2)

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 Commenti

Thank you!!
subplot(1,2,2);
what does (1,2,2) means ?
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);

Accedi per commentare.

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 Commenti

imshowpair is perfect for that. It has the methods 'falsecolor', 'blend', 'diff' and 'montage' - whilst the latter is the one you need, as Anand and Image Analyst said.
But: you need the Image Processing Toolbox for that. If you don't have it, subplot seems to be the best solution.
How about if we want to show the image on top of each others instead of side by side?
imshowpair(imrotate(im1,90), imrotate(im2,90), 'montage');
set(gca,'view',[90 90])

Accedi per commentare.

Richiesto:

il 5 Nov 2014

Commentato:

il 11 Gen 2022

Community Treasure Hunt

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

Start Hunting!

Translated by