%ÅªÀÉ®× ÀÉ®×size¬°100*100
m=100; n=100;
fin=fopen('ler.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(3,2,1);
imshow(Y)
title('ler.raw');
subplot(3,2,2);
histogram(Y);

%By Otsu
%Otsu's method chooses a threshold that minimizes the intraclass variance of the thresholded black and white pixels. 
level = graythresh(Y)   %computes a global threshold level from grayscale image Y. The threshold is normalized to the range [0, 1].
subplot(3,2,3);
BW = imbinarize(Y,level); %Convert the image into a binary image using the threshold.
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);

%By Kittler
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);

m=512; n=512;
fin=fopen('Whorl.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
level = graythresh(Y)
figure;
subplot(3,2,1);
imshow(Y)
title('Whorl.raw');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('Bu Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);


m=512; n=512;
fin=fopen('Rloop.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(3,2,1);
imshow(Y)
title('Rloop.raw');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);

m=640; n=896;
fin=fopen('linsfN.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(3,2,1);
imshow(Y)
title('linsfN.raw');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);


m=640; n=896;
fin=fopen('linsfT.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(3,2,1);
imshow(Y)
title('linsfT.raw');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);

m=200; n=256;
fin=fopen('shipj.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
figure;
subplot(3,2,1);
imshow(Y)
title('shipj.raw');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);


m=256; n=256;
fin=Tiff('circleB.tiff ','r');
Y = read(fin);
figure;
subplot(3,2,1);
imshow(Y)
title('circleB.tiff');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);

m=256; n=256;
fin=Tiff('rectB.tiff ','r');
Y = read(fin);
figure;
subplot(3,2,1);
imshow(Y)
title('rectB.tiff');
subplot(3,2,2);
histogram(Y);
subplot(3,2,3);
BW = imbinarize(Y,level);
imshow(BW)
title('By Otsu');
subplot(3,2,4);
histogram(BW);
subplot(3,2,5);
YK = kittler(Y);
imshow(YK)
title('By Kittler');
subplot(3,2,6);
histogram(YK);
