Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Rik
Rik am 30 Mär. 2018
And what is your question/error?
zakaria siad
zakaria siad am 31 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 31 Mär. 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 Kommentare
zakaria siad
zakaria siad am 31 Mär. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by