Hello. I need to have this code write the entropy and edge of each image using kmeans to a file. Here is my code so far. Ignore or add some of the code i have commented out with %.
files = dir('*.jpg'); % specigy the extension of your image file
C=zeros(20,2);
for i = 1:numel(files)
filename = files(i).name;
image = imread(filename);
% apply processing to the loaded image
% save the image to an array or back to the folder using
imshow(image);
title('Original Image');
%Calculating Smoothness and filtering noise.
gs = im2gray(image);
gs = imadjust(gs);
BW = imbinarize(gs, "adaptive", "ForegroundPolarity", "dark");
imshowpair(gs, BW, "montage");
H = fspecial("average", 3);
gssmooth = imfilter(gs,H);
BWsmooth = imbinarize(gssmooth,"adaptive", "ForegroundPolarity", "dark");
gssmooth = imfilter(gs, H, "replicate");
BWsmooth = imbinarize(gssmooth,"adaptive","ForegroundPolarity","dark");
imshow(BWsmooth);
%Edge detection
%S = edge(BWsmooth);
%S1 = edge(BWsmooth, 'canny');
%imshowpair(S, S1, "montage");
%SedgeSum = sum(S(:))/(800*800)
%S1edgeSum = sum(S1(:))/(800*800)
%Texture Filters
%X = entropyfilt(image);
%Y = stdfilt(image, ones(11));
%Z = rangefilt(image, ones(11));
%E = entropy(gs)
%E1 = entropy(BWsmooth)
%SumEntropy = sum(E(:))
%Xim = rescale(X);
%Yim = rescale(Y);
%montage({Xim, Yim, Z}, 'Size', [1,3],'BackgroundColor', 'w', 'BorderSize', 20)
%title('Texture Images Showing Local Entropy, Local Standard Deviation, and Local Range');
test=rgb2gray(image);
test=imresize(370,560);
C(i,1)=sum(sum(edge(test,'canny')));
C(i,1)=entropy(test);
J=entropyfilt(test,ones(11));
len=length(J(:));
C(i,2:len+1)=J(:);
[idx, centers] = kmeans(C,3);
end
%test=rgb2gray(image);
%test=imresize(370,560);
%C(i,1)=sum(sum(edge(test,'canny')));
%C(i,1)=entropy(test);
%J=entropyfilt(test,ones(11));
%len=length(J(:));
%C(i,2:len+1)=J(:);
%
%[idx, centers] = kmeans(C,3);
filename = 'testdata.xlsx';
for j=1:length(idx)
name=files(i).name;
writematrix(name,filename,'Sheet',1,'Range',strcat('A',num2str(j)));
writematrix(name,filename,'Sheet',1,'Range',strcat('B',num2str(idx(j))));
end