clc;
clear all;
I = imread('Capture.JPG');
gray_image = rgb2gray(I);
binary_image = gray_image > 40;
imshow(binary_image);
roundBlobs = regionprops(binary_image, 'BoundingBox');
for k = 1 : length(roundBlobs)
thisBB = roundBlobs(k).BoundingBox;
crop_blob=imcrop(I,[thisBB(1),thisBB(2),thisBB(3),thisBB(4)]);
resize_blob=imresize(crop_blob,[thisBB(3) thisBB(4)]);
figure,imshow(resize_blob);
redChannel = resize_blob(:, :, 1);
greenChannel = resize_blob(:, :, 2);
blueChannel = resize_blob(:, :, 3);
meanR = mean2(redChannel);
meanG = mean2(greenChannel);
meanB = mean2(blueChannel);
HSVimage = rgb2hsv(resize_blob);
H_component = HSVimage(:,:,1);
S_component = HSVimage(:,:,2);
I_component = HSVimage(:,:,3);
meanH = mean(H_component(:));
meanS = mean(S_component(:));
meanV = mean(I_component(:));
YCbCrimage = rgb2ycbcr(resize_blob);
Y_component = YCbCrimage(:,:,1);
Cb_component = YCbCrimage(:,:,2);
Cr_component = YCbCrimage(:,:,3);
meanY = mean2(Y_component);
meanCb = mean2(Cb_component);
meanCr = mean2(Cr_component);
Lab = rgb2lab(resize_blob);
L = Lab(:,:,1);
a = Lab(:,:,2);
b = Lab(:,:,3);
meanL = mean2(L);
meanLA = mean2(a);
meanLB = mean2(b);
gray_blob = rgb2gray(resize_blob);
offsets = [0 1; -1 1;-1 0;-1 -1];
glcm = graycomatrix(gray_blob, 'GrayLimits', [], 'Offset',offsets, 'Symmetric', true);
stats = graycoprops(glcm);
avgCont = mean(stats.Contrast);
avgCorrel = mean(stats.Correlation);
avgEnergy = mean(stats.Energy);
avgHomogen = mean(stats.Homogeneity);
Feats = [avgCont, avgCorrel, avgEnergy, avgHomogen, meanR, meanG, meanB, meanH, meanS, meanV, meanY, meanCb, meanCr, meanL, meanLA, meanLB];
glcm_data(k, :) = Feats(:);
end
m = matfile('gl_data.mat', 'Writable', true);
if isprop(m, 'gl_data')
s = size(m, 'gl_data');
m.gl_data(s(1)+1, :) = glcm_data;
else
m.gl_data = glcm_data;
end
load('gl_data.mat');
writematrix(gl_data, 'gl_data.csv');