BW pixel count

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Octave script for black or white pixels count in .jpg images

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

files = dir('*1.*.jpg'); % Read all images in current folder

fileID = fopen('OilRedConcentration.txt','w');

pas=pwd;

for i=1:length(files)

[pathname,filename,extension] = fileparts(files(i).name);

I = imread(files(i).name);

imshow(I)

figure % Equalize. (optional)

I_eq = imadjust(I);

imshow(I_eq)

figure % Convert to black and white.

bw = im2bw(I_eq, graythresh(I_eq));

imshow(bw)

I = imcomplement(bw); % Invert image colors (optional) Useful for very bright images.

imshow(I)

V=sum(I);

OilRedConectration(i)=sum(V)*1e-2;

fprintf(fileID, ' %s %s %s\t %s\t %6.0f\n', pas, '/', filename,'OilRedConcent= ', OilRedConectration(i));

close all

end

Mu=mean(OilRedConectration);

Sigma=std(OilRedConectration);

c=1;

for n=1:length(OilRedConectration)

if OilRedConectration(n)<(Mu+0.5*Sigma)&&OilRedConectration(n)>(Mu-0.5*Sigma)

new(c)=OilRedConectration(n);

c=c+1;

end

end

m1=mean(new)

s1=std(new)

save('m1.mat','m1')

save('s1.mat','s1')

fclose(fileID);