要求
去掉给定指纹区域附近的雾气。
方法
1, Make a histogram of the origin picture, observe the gray distribution of the pixel.
2, Choose the appropriate threshold and then turn the picture into binarization.
3, Define a mask matrix and turn the black pixel into white and turn the white pixel into black, so that we can use the erosion and dilation easily.
4, Use the method of morphology such as erosion and dilation, as well as Open and Close operation, to obtain a basic area of the finger image without the noises, which are around the finger.
5, After obtain the area of finger, turn this area into the origin picture by multiply the input picture.
6, Choose the part of the picture which been smoothing slightly to fulfill the result picture, where lost some detail after masking.
7, Turn the result picture into binarization to have a better look of the result.
效果
源码(Matlab)
%picture 5
clear all;
x = imread('5.bmp');
[M,N]=size(x);
x_5 = x;
g = im2bw(x,80/255);
mask=zeros(M,N);
g =uint8(g);
for i=1:M
for j=1:N
if(g(i,j)==0)
mask(i,j)=1;
end
end
end
B1 = ones(6);
B2 = ones(3);
f1 = imdilate(mask,B2);
f1=imerode(f1,B2);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
for i =1:11
f1=imdilate(f1,B1);
end
for i =1:13
f1=imerode(f1,B1);
end
g =x.*uint8(f1);
for i=1:M
for j=1:N
if(g(i,j)==0)
g(i,j)=255;
end
end
end
g_5 = im2bw(g,220/255);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%picture 8
x = imread('8.bmp');
[M,N]=size(x);
x_8 = x;
g = im2bw(x,80/255);
mask=zeros(M,N);
g =uint8(g);
for i=1:M
for j=1:N
if(g(i,j)==0)
mask(i,j)=1;
end
end
end
B1 = ones(6);
B2 = ones(3);
f1 = imdilate(mask,B2);
f1=imerode(f1,B2);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
for i =1:8
f1=imdilate(f1,B1);
end
for i =1:11
f1=imerode(f1,B1);
end
g =x.*uint8(f1);
for i=1:M
for j=1:N
if(g(i,j)==0)
g(i,j)=255;
end
end
end
g_8 = im2bw(g,240/255);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%picture 18
x = imread('18.bmp');
[M,N]=size(x);
x_18 = x;
g_orign = x;
t = 190;
for i=1:M
for j=1:N
if (g_orign(i,j)>=t)
g_orign(i,j)=255;
else
g_orign(i,j)=0;
end
end
end
g = im2bw(x,100/255);
mask=zeros(M,N);
g =uint8(g);
for i=1:M
for j=1:N
if(g(i,j)==0)
mask(i,j)=1;
end
end
end
B1 = ones(6);
B2 = ones(3);
f1 = imdilate(mask,B2);
f1=imerode(f1,B2);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
for i =1:19
f1=imdilate(f1,B1);
end
for i =1:13
f1=imerode(f1,B1);
end
g =x.*uint8(f1);
for i=1:M
for j=1:N
if(g(i,j)==0)
g(i,j)=255;
end
end
end
for i=2*M/3:M
for j=1:N
g(i,j) = g_orign(i,j);
end
end
g_18 = im2bw(g,220/255);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%picture 22
x_rgb = imread('22.jpg');
x = rgb2gray(x_rgb);
[M,N]=size(x);
x_22 = x;
x_orign = x;
g = im2bw(x,35/255);
mask=zeros(M,N);
g =uint8(g);
for i=1:M
for j=1:N
if(g(i,j)==0)
mask(i,j)=1;
end
end
end
B1 = ones(9);
B2 = ones(3);
f1 = imdilate(mask,B2);
f1=imerode(f1,B2);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imdilate(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
f1=imerode(f1,B1);
for i =1:13
f1=imdilate(f1,B1);
end
for i =1:13
f1=imerode(f1,B1);
end
g =x.*uint8(f1);
for i=1:M
for j=1:N
if(g(i,j)==0)
g(i,j)=255;
end
end
end
for i=M/2:M
for j=1:N
g(i,j) = x_orign(i,j);
end
end
SE = [0 1 0;
1 1 1;
0 1 0;];
g_22 = imerode(g,SE);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%output the result
figure(1)
subplot(2,4,1)
imshow(x_5),title('Orign5');
subplot(2,4,2);
imshow(g_5),title('Result5');
subplot(2,4,3)
imshow(x_8),title('Orign8');
subplot(2,4,4);
imshow(g_8),title('Result8');
subplot(2,4,5)
imshow(x_18),title('Orign18');
subplot(2,4,6);
imshow(g_18),title('Result18');
subplot(2,4,7)
imshow(x_22),title('Orign22');
subplot(2,4,8);
imshow(g_22),title('Result22');