How can I reduce the space between images?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Adam
2017 年 7 月 18 日
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'?
回答 (1 件)
Jan
2017 年 7 月 18 日
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 件のコメント
Image Analyst
2017 年 7 月 28 日
Also attach annotated screenshots indicating what you want to be positioned and sized where.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!