How can I reduce the space between images?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
The following source code has three problems:
- it can't show only one image.
- it doesn't preserve the original aspect ration of images
- space between images is too wide.
How can I fix these three issues?
draw_multiple_images.m
function draw_multiple_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;
2 Kommentare
Adam
am 18 Jul. 2017
You are better off creating and positioning your own axes than using subplot for images. subplot leaves a lot of space to allow for things like titles, axes labels, ticks etc, most or all of which you don't want for an image so you just get blank space instead.
doc axes properties
will guide you to settings regarding aspect ratio - DataAspectRatio and PlotBoxAspectRatio in particular.
I don't understand your first point - 'can't only show one image'?
Antworten (1)
Jan
am 18 Jul. 2017
Use axes image to use the original dimensions.
You can find a lot of tools for adjusting the space between subplots in the FileExchange: FEX: Serach "subplot"
Beside searching in the FileExchange, you can find these solutions by using an internet search engine also.
Please explain "can't show only one image": What input are you using and what do you observe?
4 Kommentare
Image Analyst
am 28 Jul. 2017
Also attach annotated screenshots indicating what you want to be positioned and sized where.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!