cannot show full image in folder

1 visualización (últimos 30 días)
Armylia Dewi
Armylia Dewi el 30 de Mayo de 2022
Comentada: Armylia Dewi el 31 de Mayo de 2022
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'

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mayo de 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 comentario
Armylia Dewi
Armylia Dewi el 31 de Mayo de 2022
Oh i see, Okey..
Thank you for helping me in solving this problem..

Iniciar sesión para comentar.

Más respuestas (2)

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

Iniciar sesión para comentar.


Armylia Dewi
Armylia Dewi el 30 de Mayo de 2022
the results I get from the script only show 1 only.
like this

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by