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

조회 수: 1 (최근 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
Rik
Rik 2018년 3월 30일
And what is your question/error?
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