function []=Program_1();
clc;echo off;close all;
A=[ 30,31,12, 9,
17,12,25,10,
12, 8,17, 9,
31,12,26,22];
A=double(A);B=A;
disp('original image matrix');disp(A);
image_depth=31;tones=8;
B=My_plot(A,tones);
value=1;
switch value
case 1
WW=20;WL=20;
B=My_simple_window(A,image_depth,tones,WW,WL);
case 2
gray_val=5;im_val=21;
B=My_broken_window(A,image_depth,tones,gray_val,im_val);
case 3
ww1=10;ww2=10;wl1=10;wl2=25;
B=My_double_window(A,image_depth,tones,ww1,ww2,wl1,wl2);
end
disp(round(B));
function [C]=My_plot(A,tones);
x=size(A,1);y=size(A,2);
for i=1:x
for j=1:y
ival=A(i,j);
tone_ival=(tones-1)*(double(ival)-0)/(31-0);
C(i,j)=tone_ival;
end;
end;
disp(round(C));
function [C]=My_simple_window(A,image_depth,tones,WW,WL);
x=size(A,1);y=size(A,2);
We=(2.0*WL+WW)/2.0;
if(We>image_depth) We=image_depth;end;
Ws=We-WW;
if(Ws<0) Ws=0;end;
for i=1:x,
for j=1:y,
ival=A(i,j);
if (ival<=Ws) tone_ival=0; end;
if (ival>=We) tone_ival=tones-1;end;
if ( ival>=Ws & ival<=We)
tone_ival=(tones-1)*(double(ival)-Ws)/(We-Ws);
end;
C(i,j)=tone_ival;
end;
end;