I want To write a Matlab function that can display one single image, multiple images (i.e. cell arrays, vector, matrices) of images so that I don't need to worry about writing 'plots', 'subplots', and other complicated Matlab mechanisms each time I run my program with new inputs. That is also one of my requirements in my project.
The following source code has several problems:
- it can't show only one image
- occasionally it doesn't preserve the original aspect ratio of images
- resizing the window to a smaller size drastically reduces the size of the images on display
How can I fix these issues?
Source Code
function draw_images(image_list)
d = size(image_list);
l = length(d);
figure;
hold all
colormap(gray(256));
% vector or cell-array
if(l==2)
N = length(image_list);
[m, n] = factor_out(N);
% images may be of differenet dimensions
if(iscell(image_list))
for k=1:N
h = subplot(m,n,k);
image(image_list{k},'Parent',h);
set(gca,'xtick',[],'ytick',[])
end
% must be of same dimension
elseif(isvector(image_list))
for k=1:N
h = subplot(m,n,k);
image(image_list(k),'Parent',h);
set(gca,'xtick',[],'ytick',[])
end
end
% 3D matrix of images (!!!)
elseif(l==3)
N = d(3) ;
[m, n] = factor_out(N);
for k=1:N
I = image_list(:,:,k);
subplot(m,n,k);
imshow(I);
set(gca,'xtick',[],'ytick',[])
end
end
hold off
function [m, n] = factor_out(input_number)
sqrtt = ceil(sqrt(input_number));
m = sqrtt;
n = sqrtt;