Trying to display four color images together but can't figure out the placement

6 views (last 30 days)
So I'm trying to combine four 300 x 400 x 3 pixel color images into a "2x2 grid" (two next to each other, and the other two right below those). An example image for how it's supposed to look is shown at the bottom. I started with a blank matrix of zeros, and I'm trying to fill each "spot" with the images. I'm also supposed to have a 10 pixel sized separation between the images (only in the center. if you look at the image you can see the separation as black lines in the center). This is what I have so far and don't know how to place the last 2 images. I'm not even 100% sure why the eiffel tower image shows up on the bottom right rather than to the right of the street image. Sorry if this is confusing...here's what I have so far:
fullImg = zeros(300*2+10,400*2+10,3,'uint8'); %matrix of zeros with double the length of x and y, plus 10 for the separation
fullImg(1:300,1:400,:) = img1; %fill the first "spot" with image 1
fullImg(311:610,411:810,:) = img2; %fill the second "spot" with image 2...not sure why this is in the bottom right
figure, imshow(fullImg);
How the image is supposed to look in the end:
Screen Shot 2019-01-29 at 8.05.53 PM.png

Answers (1)

KSSV
KSSV on 30 Jan 2019
I1 = imread(image1) ;
I2 = imread(image2) ;
I3 = imread(image3) ;
I4 = imread(image4) ;
% Get all images to this dimensions
m = 500 ; n = 500 ; p = 3 ;
% resize all images to same
I1 = imresize(I1,[m,n]) ;
I2 = imresize(I2,[m,n]) ;
I3 = imresize(I3,[m,n]) ;
I4 = imresize(I4,[m,n]) ;
I = [I1 I2 ; I3 I4] ;
imshow(I)
  1 Comment
Emily Bossiere
Emily Bossiere on 1 Feb 2019
Hi thank you for your response! This answer wasn't exactly what I was looking for but for anyone that's curious, I was able to figure it out:
img1 = imread('1.jpg'); %set img1 to the first image
img2 = imread('2.jpg'); %set img2 to the second image
img3 = imread('3.jpg'); %set img3 to the third image
img4 = imread('4.jpg'); %set img4 to the fourth image
fullImg = zeros(300*2+10, 400*2+10,3,'uint8'); %create a matrix of zeros (empty matrix) of size (300*2+10 x 400*2+10 x 3) aka a 610 x 810 matrix for all 4 images, with 10 pixel spacing
fullImg(1:300,1:400,:) = img1; %set img1 to be in the top (1:300) left (1:400) corner
fullImg(1:300,416:815,:) = img2; %set img2 to be in the top (1:300) right (416:815) corner
fullImg(316:615,416:815,:) = img4; %set img4 to be in the bottom (316:615) right (416:815) corner
fullImg(316:615,1:400,:) = img3; %set img3 to be in the bottom (316:615) left (1:400) corner

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!