Image segmentation is an important image technology, which has been paid much attention in theory research and practical application. There are many methods and kinds of image segmentation, some of which can be directly applied to any image, while others can only be applied to special categories of images. Some algorithms require rough segmentation of the image, because they need to extract the information from the image. For example, you can split the threshold of the grayscale level of an image. Many different kinds of images or scenery can be divided into image data, different types of images, there is already a corresponding segmentation method for its segmentation, at the same time, some segmentation methods are only suitable for some special types of image segmentation. The quality of the segmentation result needs to be measured according to the specific occasion and requirement. Image segmentation is a key step from image processing to image analysis, it can be said that the image segmentation results directly affect the understanding of the image.
Pulse-coupled neural Network (PCNN) is a new kind of neural network, which is different from the traditional artificial neural network, and it has important biological background, which is proposed by Eckhorn to explain the phenomenon of neuron synchronization which is observed by experiments in the cat's brain visual cortex. PCNN's biological background makes it have the innate advantage in the image processing, has the superiority which does not compare with the traditional method image processing. The following program is based on PCNN most basic image segmentation of the MATLAB implementation, segmentation effect is better.
Main program:
FUNCTION[EDGE,NUMBEROFAERA]=PCNN (X)
%x: Input grayscale image, Edge: Some boundary points detected, Numberofaera indicates the block area activated at each iteration
Clear
CLC
I=imread (' lena1.bmp ');
[Xa,ya]=size (I);
Subplot (1,2,1);
Imshow (I);
%imshow (I);
X=double (I);
%x=double (Imread (' lena.bmp '));
weight=[0.5 1 0.5;1 0 1;0.5 1 0.5]; % what is the selection principle (or basis) of the weighted matrix?
beta=0.32;
yuzhi=200;
decay=0.31;
[A,b]=size (X);
Threshold=zeros (A,B);
S=zeros (a+2,b+2);
B=zeros (A,B); % mark Sample, indicating whether the pixel has been activated;
Y=zeros (A,B);
Edge=zeros (A,B); Numberofaera=zeros (A,B); Numberofaera_1=zeros (A,B);
num_1=0; num=0;
N=1;
while (sum (B)) ~=xa*ya, it should be noted that the 128*128 image is used.
For i0=2:a+1
For i1=2:b+1
V=[s (i0-1,i1-1) s (i0-1,i1) s (i0-1,i1+1);
S (i0,i1-1) s (i0,i1) s (i0,i1+1);
S (i0+1,i1-1) s (i0+1,i1) s (i0+1,i1+1)];
L=sum (sum (v.*weight));
F=x (i0-1,i1-1);
U=double (F) * (1+beta*double (L));
If U>=threshold (i0-1,i1-1) | Threshold (i0-1,i1-1) <95
T (i0-1,i1-1) = 1; % what is this?
Threshold (i0-1,i1-1) =yuzhi;
Y (i0-1,i1-1) = 1;
If N==1
B (i0-1,i1-1) = 0; % avoid the impact of first-time full excitation
Else
B (i0-1,i1-1) = 1; % has been launched by the mark
Threshold (i0-1,i1-1) =1000000;% equivalent to not being activated for a second time
End
Else
T (i0-1,i1-1) = 0; %no use?
Y (i0-1,i1-1) = 0;
End
End
End
Threshold (Find (B~=1)) =exp (-decay) *threshold (Find (b~=1));
% activated like no longer involved in the iterative process
If N~=1
Edge=edge+judge_edge (Y,n);
Y (Find (edge<0)) = 0; The% boundary point is set to zero, Y would have been the excited pixel, now the boundary is set to zero,
% also can not be white inspired, B matrix has a record! Of course, next time, you won't be fired.
[Numberofaera_1,num_1]=bwlabel (y,4);
For i=1:a
For J=1:B
If Numberofaera_1 (i,j) ~=0
Numberofaera_1 (i,j) =numberofaera_1 (i,j) +num;
End
End
End
numberofaera=numberofaera+numberofaera_1;
Num=num_1;
End
If N==1
S=zeros (a+2,b+2);
Else
S=bianhuan (T);
End
n=n+1;
Numberofaera_1=zeros (A,B);
Subplot (1,2,2);
Imshow (S);
End%while
Edge Detection:
function Y=judge_edge (x,n)%x: Two-valued images pcnn output after each iteration, how to accurately determine the boundary point is the key
[A,b]=size (X);
T=jiabian (X);
Y=zeros (A,B);
W=zeros (A,B);
For i=2:a+1
For j=2:b+1
if (t (i,j) ==1) & ((i-1,j) ==0&t (i+1,j) ==0) | ( T (i,j-1) ==0&t (i,j+1) ==0) | (T (i-1,j-1) ==0&t (i+1,j+1) ==0) | (T (i+1,j-1) ==0&t (i-1,j+1) ==0))
Y (i-1,j-1) =-n;
End
End
End
This step is also very important--plus side, the so-called overtime is in the two-dimensional direction of the image expansion, the expansion of the edge of the image as the edge of the image, the following program to achieve the expansion of the image
function Y=jiabian (X)
[M,n]=size (X);
Y=zeros (m+2,n+2);
For i=1:m+2
For j=1:n+2
If i==1&j~=1&j~=n+2
Y (i,j) =x (1,j-1);
ElseIf j==1&i~=1&i~=m+2
Y (i,j) =x (i-1,1);
ElseIf i~=1&j==n+2&i~=m+2
Y (i,j) =x (i-1,n);
ElseIf i==m+2&j~=1&j~=n+2
Y (i,j) =x (m,j-1);
ElseIf i==1&j==1
Y (i,j) =x (I,J);
ElseIf i==1&&j==n+2
Y (i,j) =x (1,n);
ElseIf i== (m+2) &j==1
Y (i,j) =x (m,1);
ElseIf i==m+2&j==n+2
Y (i,j) =x (m,n);
Else
Y (i,j) =x (i-1,j-1);
End
End
End
Transform:
function Y=bianhuan (X)
[M,n]=size (X);
Y=zeros (m+2,n+2);
For i=1:m+2
For j=1:n+2
If i==1|j==1|i==m+2|j==n+2
Y (I,J) = 0;
Else
Y (i,j) =x (i-1,j-1);
End
End
End
Transformations and extensions are used in almost every image processor, and extensions are also called edges, plus steps to go.
Processing effect:
This procedure is the most basic pcnn image segmentation, can be expanded from the following two aspects
1. As we all know, the parameters of the pcnn are more, and generally based on the experience of the experiment, the parameters are really very difficult, you can use some intelligent algorithms to train their parameters
2. This is the most basic pcnn, the use of improved pcnn effect will be better