cannot show full image in folder

1 view (last 30 days)
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'

Accepted Answer

Image Analyst
Image Analyst on 30 May 2022
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);
  1 Comment
Armylia Dewi
Armylia Dewi on 31 May 2022
Oh i see, Okey..
Thank you for helping me in solving this problem..

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 30 May 2022
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 Comment
Walter Roberson
Walter Roberson on 30 May 2022
sheet = 1;
range = sprintf('A%d', n);
xlswrite('Cobaaaa1.xls', sheet, range, training);

Sign in to comment.


Armylia Dewi
Armylia Dewi on 30 May 2022
the results I get from the script only show 1 only.
like this

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!