MATLAB: Save one image as part of a larger image

digital image processing

Hi all,
I have processed image data into a 10×512 pixel array. I have multiple images all this size and I would like to display them all side by side on a single larger image. I have created a blank image using zeros of size 1000×512 (i.e. I have 100 images in total, therefore 10 pixels x 100 images) but am having trouble getting my smaller image to display. How could I approach this?
Kind regard and thanks, Susan

Best Answer

Let's just assume that all your images are in a 3D matrix and you want to slap them onto a canvas:
canvas = zeros(1000, 512); % Target image
images = rand(10, 512, 100); % 100 very useless images =)
Now, in this case, there are clever MatLab functions, but I'll stick to a simple loop so you see what's going on (and that's adaptable if your images are stored in some other way).
for n = 1:100
rows = (n-1) * 10 + (1:10);
canvas(rows, :) = images(:,:,n);
end
So, for each image (indexed by n), you calculate a range of row indices for your 10 rows. The value (n-1) * 10 gives the zero-based position of the first row of the 'n'th image, and then you add that to the vector 1:10. ie image 1 is rows 1:10, image 2 is rows 11:20, etc...
The slice canvas(rows, :) is then a 10-by-512 address, into which you assign the values from your 'n'th image (also 10-by-512).