How to combine images horizontally of slightly different heights

9 ビュー (過去 30 日間)
Stephen Devlin
Stephen Devlin 2018 年 6 月 20 日
コメント済み: Sina Zinatlou 2021 年 2 月 8 日
Hi, I have a folder of images that I want to stitch together horizontally (it would be nice to know how to do it vertically too). The images are taken from cropping an image on a screen, but as an example I have chopped up a football image. I don't need to put the football back together seamlessly, but it would be good to have the images stitched back together so that the top edges of each pic are aligned and they are side by side, no stretching of an image in either dimension. It doesn't matter if it looks a bit haphazard as long as there is no stretching.
I have commented out what is giving the following error:-
Error using horzcat Dimensions of arrays being concatenated are not consistent.
Error in stitchy_02 (line 27) imageStitch = [cStitched_start, imageStitch];
Code:-
clear all
close all
clc
hFig=figure('units','normalized','outerposition',[0 0 1 1]);
pics=dir('/Users/imagexpertinc/Desktop/ball_pics/*.png')
amount=numel(pics)
cStitched_start=imread(pics(1).name);
sizes=zeros(amount,3)%preallocate a table for size data
for k=1 : amount
imageStitch=imread(pics(k).name);
set(0,'CurrentFigure',hFig)
subplot(2,amount,k);
imshow(imageStitch)
title(['Pic ' num2str(k)])
%%Determine Image Sizes
% sizes(k,:)=size(imageStitch)%length width dimension
% BiggerImage=max(sizes)
% SmallerImage=min(sizes)
%
%
% imageStitch=imread(pics(k).name);
% imageStitch = [cStitched_start, imageStitch];
% set(0,'CurrentFigure',hFig)
% subplot(2,2, 1:2);
% imshow(imageStitch);
%
end

採用された回答

KSSV
KSSV 2018 年 6 月 20 日
編集済み: KSSV 2018 年 6 月 20 日
Read about imresize. Use imresize and get all the images to same dimensions.
files = dir('*.png') ;
N = length(files) ;
I = cell(N,1) ;
for i = 1:N
I1 = imread(files(i).name) ;
I{i} = imresize(I1,[526,134]) ;
end
I = cat(2,I{:}) ;
imshow(I) ;
  2 件のコメント
Stephen Devlin
Stephen Devlin 2018 年 6 月 20 日
編集済み: Stephen Devlin 2018 年 6 月 20 日
Thank you KSSV, it works but with a bit of stretching,I'll go off to read about imresize (I had no idea there was a function for it)
Sina Zinatlou
Sina Zinatlou 2021 年 2 月 8 日
unfortunately not working

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by