Skip to content

Instantly share code, notes, and snippets.

@drhirsch
Created September 5, 2016 15:20
Show Gist options
  • Save drhirsch/faf4c3259f8b6aed037d5f3beb293e59 to your computer and use it in GitHub Desktop.
Save drhirsch/faf4c3259f8b6aed037d5f3beb293e59 to your computer and use it in GitHub Desktop.
Montage() for Matlab and Octave
% note images must be exactly identically sized width x height
path = '~'
flist = {'1.png','2.png'}; % create this list with another function for real use
Nimg = length(flist);
finf = imfinfo([path,'/',flist(1).name]);
% this axis ordering needed by montage()
% third dimension is 1 for grayscale, 3 for color
oneorthree = 3;
data = zeros(finf.Height,finf.Width,oneorthree,Nimg);
for i = 1:Nimg
im = imread([path,'/',flist(i).name]);
data(:,:,oneorthree,i) = im;
end %for
% note optional 'DisplayRange' parameter to control contrast
montage(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment