Thursday, March 12, 2009

Local enhancement

% Local enhancement
% Read a gray scale image and compute its global mean and standard
% deviation. divide the image in to masks of size 3 x 3 and compute the
% local mean and standard deviation. Replace the value of center pixel of
% the mask with the local mean. Slide the mask and plot the resultant image.
% Replace the value of center pixel of the mask with the local std dev.
% Slide the mask and plot the resultant image.
% Compare the localdeviation and local mean against global and local mean.
% For chosen condition multiply the intensity by the enhancement factor(E) and plot the same.
clear all; close all; clc;
Isem=imread('sem.jpg');
f=double(Isem);
[m n]=size(f);
f1 = f;
f2 = zeros(m,n);
f3 = zeros(m,n);
M=mean2(f);
D=std2(f);
k=[0.4 0.02 0.4];
E=4.0;
for i=2:m-1
for j=2:n-1
con=0; s=0;
for i1=i-1:i+1
for j1=j-1:j+1
con=con+1;
s(con)=f(i1,j1);
end
end
Mloc = mean(s);
f2(i,j)=mean(s);
Dloc = std(s);
f3(i,j)=std(s);

if (Mloc=k(2)*D) && (Dloc<=k(3)*D)
f1(i,j)=E*f(i,j);
else
f1(i,j)=f(i,j);
end
end
end
figure,imshow(Isem),title('Original Image');
figure,imshow(uint8(f2)),title('Image formed from local means');
figure,imshow(uint8(f3)),title('Image formed from local standard deviation');
figure,imshow(uint8(f1)),title('Image formed from all multiplication constants'),xlabel('Enhanced Image');

1 comment:

Anonymous said...

%good answer
clear all; close all; clc;
Isem=imread('Fig0327_a_tungsten_original_.tif');
f=double(Isem);
[m n]=size(f);
f1 = f;
f2 = zeros(m,n);
f3 = zeros(m,n);
M=mean2(f);
D=std2(f);
k=[0.4 0.02 0.4];
E=9.0;
for i=2:m-1
for j=2:n-1
con=0; s=0;
for i1=i-1:i+1
for j1=j-1:j+1
con=con+1;
s(con)=f(i1,j1);
end
end
Mloc = mean(s);
f2(i,j)=mean(s);
Dloc = std(s);
f3(i,j)=std(s);

if (Mloc<=k(1)*M)&&(Dloc>=k(2)*D) && (Dloc<=k(3)*D)
f1(i,j)=E*f(i,j);
else
f1(i,j)=f(i,j);
end
end
end
figure,imshow(Isem),title('Original Image');
figure,imshow(uint8(f2)),title('Image formed from local means');
figure,imshow(uint8(f3)),title('Image formed from local standard deviation');
figure,imshow(uint8(f1)),title('Image formed from all multiplication constants'),xlabel
('Enhanced Image');