i want to write 25 sample image after treatment and save in 10 folders

2 次查看(过去 30 天)
NSamples=25; NClasses=9;
for i =1:T
for s=1:NSamples
for c=0:NClasses
%traitement---------------------------------------------------------
img=imread([P I(i).name]);
R = imresize (img,[100 100]);
G = rgb2gray(R);
BW1 = edge(G,'sobel');
classfile =mkdir( sprintf('c%d',c));
imgfile = sprintf('%d.png',s);
fulfile = fullfile(classfile,imgfile);
dir_file = dir(fulfile)
imwrite(BW1,dir_file);
end
end
end
  2 个评论
zakaria siad
zakaria siad 2018-3-31
An unknown error occurred in FULLFILE while constructing the file specification.
Error in Creat_Files_Class(line 21) fulfile = fullfile(classfile,imgfile);
Caused by: Error using horzcat The following error occurred converting from logical to char: Error using char Conversion to char from logical is not possible.

请先登录,再进行评论。

采纳的回答

Rik
Rik 2018-3-31
In the code below I fixed some issues with your code. Compare the lines I changed and read the documentation for those functions to better understand their input and output. Especially the output for mkdir and dir.
for c=0:NClasses
classfoldername=sprintf('c%d',c);
if ~exist(classfoldername,'dir')
mkdir(classfoldername);
end
end
for i =1:T
for s=1:NSamples
for c=0:NClasses
%traitement---------------------------------------------------------
img=imread([P I(i).name]);
R = imresize (img,[100 100]);
G = rgb2gray(R);
BW1 = edge(G,'sobel');
classfoldername=sprintf('c%d',c);
imgfile = sprintf('%d.png',s);
fulfile = fullfile(classfoldername,imgfile);
imwrite(BW1,fulfile);
end
end
end
  2 个评论
zakaria siad
zakaria siad 2018-3-31
I modified my code but i have problem his create same image into all of folder class
NSamples=25; NClasses=9;
for c=0:NClasses
classfoldername=sprintf('N%d',c);
if ~exist(classfoldername,'dir')
mkdir(classfoldername);
end
end
for i =1:250
for s=0:NSamples
imgfile = sprintf('%d.png',s);
for c=0:NClasses
classfoldername=sprintf('N%d',c);
%traitement---------------------------------------------------------
img=imread([P I(i).name]);
R = imresize (img,[100 100]);
G = rgb2gray(R);
G1 = YCrCb(R);
%BW1 = HOG(R);
BW1 = edge(G1,'sobel');
%-------------------------------------------------------------------
fulfile =fullfile(classfoldername,imgfile);
imwrite(BW1,fulfile);
end
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by