Clear Filters
Clear Filters

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

2 views (last 30 days)
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 Comments
zakaria siad
zakaria siad on 31 Mar 2018
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.

Sign in to comment.

Accepted Answer

Rik
Rik on 31 Mar 2018
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 Comments
zakaria siad
zakaria siad on 31 Mar 2018
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

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!