cannot show full image in folder
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone !
Ask permission. why can't it show all the pictures in one folder. The results displayed in excel are only 1 image.
this is my code :
image_folder ='E:\coba11gambar';
filenames = dir (fullfile(image_folder,'*.jpeg'));
total_images = numel(filenames);
for n= 1:total_images;
f= fullfile(image_folder, filenames(n).name)
our_images= imread (f);
% CONTRAST STRECHING
s = imadjust (our_images,stretchlim(our_images,[0.01 0.99]),[]); %menentukan nilai maksimum dan minimum untuk peregangan
% SEGMENTASI DETEKSI TEPI CANNY
g=edge(s,'canny')
% GLCM
offsets = [0 1; -1 1; -1 0; -1 -1];
glcm=graycomatrix(g,'Offset',[0 1]);%sudut 0
% mmengambil properti yang ada dalam matriks kookurensi
stats=graycoprops(glcm,{'Contrast','Energy','Correlation','Homogeneity'});
% membaca fitur glcm
rata=mean(mean(glcm));
standar=std(std(double(glcm)));
energi=stats.Energy;
entropi=entropy(glcm);
kontras=stats.Contrast;
korelasi=stats.Correlation;
homog=stats.Homogeneity;
vari=var(var(double(glcm)));
training= [energi;entropi;kontras;korelasi;homog;vari;rata;standar]';
cd('..');
xlswrite('Cobaaaa1.xls',training) %menyimpan file dalam bentuk excel
end;
%%
disp 'done'
채택된 답변
Image Analyst
2022년 5월 30일
This will do it. Just make up the whole array without writing to Excel. Then get rid of the cd and call xlswrite just once. Tested code:
image_folder ='E:\coba11gambar';
if ~isfolder(image_folder)
image_folder = pwd;
end
fileList = dir (fullfile(image_folder,'*.jp*'));
total_images = numel(fileList);
training = zeros(total_images, 8);
allFileNames = {fileList.name}';
for n = 1 : total_images
fullFileName = fullfile(image_folder, fileList(n).name);
fprintf('Processing #%d of %d : %s\n', n, total_images, fileList(n).name)
thisImage = imread(fullFileName);
% Convert to gray scale if necessary
if ndims(thisImage) == 3
thisImage = rgb2gray(thisImage);
end
% CONTRAST STRECHING
s = imadjust (thisImage,stretchlim(thisImage,[0.01 0.99]),[]); %menentukan nilai maksimum dan minimum untuk peregangan
% SEGMENTASI DETEKSI TEPI CANNY
g = edge(s,'canny');
% GLCM
offsets = [0 1; -1 1; -1 0; -1 -1];
glcm=graycomatrix(g,'Offset',[0 1]);%sudut 0
% mmengambil properti yang ada dalam matriks kookurensi
stats=graycoprops(glcm,{'Contrast','Energy','Correlation','Homogeneity'});
% membaca fitur glcm
rata=mean(mean(glcm));
stdDev=std(std(double(glcm)));
energi=stats.Energy;
entropi=entropy(glcm);
kontras=stats.Contrast;
korelasi=stats.Correlation;
homog=stats.Homogeneity;
vari=var(var(double(glcm)));
% Add on measurements for this image to our final results matrix.
training(n, :) = [energi, entropi, kontras, korelasi, homog, vari, rata, stdDev];
end
outputFileName = fullfile(image_folder, 'Cobaaaa1.xlsx');
fprintf('Please wait. Writing Excel workbook "%s",\n', outputFileName);
xlswrite(outputFileName, allFileNames, 'Sheet1', 'A1') %menyimpan file dalam bentuk excel
xlswrite(outputFileName, training, 'Sheet1', 'B1') %menyimpan file dalam bentuk excel
% Open it if using Windows
if ispc
winopen(outputFileName);
end
fprintf('All done processing %d images.\n', total_images);
추가 답변 (2개)
Walter Roberson
2022년 5월 30일
xlswrite('Cobaaaa1.xls',training) %menyimpan file dalam bentuk excel
That is asking to write to the same file and same sheet and same range each time.
Unfortunately in your release you cannot use the more modern writematrix(), and the writetable() in your release did not support 'WriteMode' 'append'
I suggest you specify a range, such as
sheet = 1;
range = sprintf('A%d', i);
xlswrite('Cobaaaa1.xls', sheet, range, training);
Note: you need to specify the sheet in order to be able to use a range that just specifies a starting corner without an ending corner.
댓글 수: 1
Walter Roberson
2022년 5월 30일
sheet = 1;
range = sprintf('A%d', n);
xlswrite('Cobaaaa1.xls', sheet, range, training);
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!