<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">

Exported from Notepad++
clc; close all; clear all; y=imread('cameraman.tif'); figure,imshow(y); [m,n]=size(y); T1=128; while(1) for i=1:m for j=1:n if y(i,j)<T1 a1(i,j)=0; else a1(i,j)=255; end end end % figure,imshow(a1); for i=1:m for j=1:n if a1(i,j)==0 b1(i,j)=y(i,j); else b2(i,j)=y(i,j); end end end % figure,imshow(b1); % figure,imshow(b2); m1=mean2(b1); m2=mean2(b2); T2=(m1+m2)/2; if abs(T1-T2)<=00.01 break; end T1=T2; end z=(y>T1); figure,imshow(z);