フィルターのクリア

Concatenate series of images from different folders

4 ビュー (過去 30 日間)
awa
awa 2016 年 7 月 15 日
コメント済み: Azzi Abdelmalek 2016 年 7 月 18 日
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
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.
awa
awa 2016 年 7 月 15 日
The original cold is correct. The ones I pasted here is typo because I changed the original folder same into a simpler one.
I corrected the typo now here.

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

回答 (2 件)

Azzi Abdelmalek
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)

Walter Roberson
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 件のコメント
awa
awa 2016 年 7 月 18 日
I tried you code, but I always encountered an error saying that "Error: Unexpected MATLAB expression.".
I debugged the code, found the error appears when executing the code at
oriDir = '/home/folder1/';
oriList = dir(fullfile(oriDir, '*.jpg'));
I don't why this would occur. I don't there are any expression contained in the beginning.
Could you please help?
Thank you.
Azzi Abdelmalek
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!

Translated by