Concatenate series of images from different folders
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Adam
2016 年 7 月 15 日
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.
回答 (2 件)
Azzi Abdelmalek
2016 年 7 月 15 日
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 件のコメント
Walter Roberson
2016 年 7 月 15 日
編集済み: Walter Roberson
2016 年 7 月 15 日
%%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 件のコメント
Azzi Abdelmalek
2016 年 7 月 18 日
Repmove one bracket, instead of
oriList = dir(fullfile(oriDir, '*.jpg'));
it should be
oriList = dir(fullfile(oriDir, '*.jpg');
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!