Concatenate series of images from different folders
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I was trying to achieve following functionalities:
extract pic1 from folder2 and put it to the left part of the newImg, extract pic2 from folder2 and put it to the right part of the newImg, Then combine the left part and right part together to be a new image.
My question is I want to implement this function for a series of images, which means a series of images from folder1 and a series of images from folder2, then extract all the images from folder1, put it to the left part of the newImg; same for folder 2, extract all the images from folder2 and put it the right part of the newImg.
I have implemented to read series of images from different folders, but when trying to concatenate the images, matlab throws an error saying unexpected expression.
Please check my code below: ==========================================================================
clc;
clear all;
close all;
%%Read images from folder1
oriDir = '/home/folder1/';
oriList = dir(fullfile(oriDir,'*.jpg'));
%read images from folder2
convDir = '/home/folder2/';
convList = dir(fullfile(convDir,'*.bmp'));
for i = 1:length(oriList)
oriPath = [oriDir oriList(1).name];
oriImg = imread(oriPath);
end
for j = 1:length(convList)
convPath = [convDir convList(1).name];
convImg = imread(convPath);
end
newImg = cat(2,oriImg,convImg);
newImg = uint8(newImg);
imshow(newImage);
2 commentaires
Adam
le 15 Juil 2016
Have you debugged to check the rest of it works as expected?
e.g. you put 'foler2' instead of 'folder2' so your error may simply be because you have an empty list of files so no convolution happens.
Réponses (2)
Azzi Abdelmalek
le 15 Juil 2016
You should replace
oriPath = [oriDir oriList(1).name]
convPath = [convDir convList(1).name];
by
oriPath=fullfile(oriDir,oriList(1).name)
convPath =fullfile(convDir,convList(1).name)
0 commentaires
Walter Roberson
le 15 Juil 2016
Modifié(e) : Walter Roberson
le 15 Juil 2016
%%Read images from folder1
oriDir = '/home/folder1/';
oriList = dir(fullfile(oriDir, '*.jpg'));
num_ori = length(oriList);
%read images from folder2
convDir = '/home/folder2/';
convList = dir(fullfile(convDir, '*.bmp'));
num_conv = length(convList);
numfile = min(num_ori, num_conv);
oriImg = cell(numfile, 1);
for i = 1 : numfile
ori_name = oriList(i).name;
oriPath = fullfile(oriDir, ori_name);
ori_img = imread(oriPath);
oriImg{i} = ori_img;
conv_name = convList(i).name;
convPath = fullfile(convDir, conv_name);
conv_img = imread(convPath);
convImg{i} = conv_img;
if size(ori_img}, 1) == size(conv_img, 1) && size(ori_img, 3) == size(conv_img, 3)
newImg{i} = cat(2, ori_img, conv_img);
imshow(newImg{i});
title( sprintf('"%s" with "%s"', ori_name, conv_name) );
pause(1);
else
fprintf('ori "%s" is incompatible size [%d,%d,%d] with conv "%s" [%d,%d,%d]', ...
ori_name, size(ori_img,1), size(ori_img,2), size(ori_img,3), ...
conv_name, size(conv_img,1), size(conv_img,2), size(conv_img,3) );
newImg{i} = [];
imshow(0);
title( sprintf('"%s" incompatible with "%s"', ori_name, conv_name) );
end
end
4 commentaires
Azzi Abdelmalek
le 18 Juil 2016
Repmove one bracket, instead of
oriList = dir(fullfile(oriDir, '*.jpg'));
it should be
oriList = dir(fullfile(oriDir, '*.jpg');
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!