Image binary: Two value based on entropy

Source: Internet
Author: User

Two value based on entropy

one-dimensional maximum entropy segmentation method , its idea is the statistical image of each gray level occurrence probability, the calculation of the gray level of entropy, assuming that the gray-level t segmentation image, the image is lower than the T gray level of the pixel points to form the target object (O), higher than the gray level T pixel composition background (B), The entropy of each gray level in the image is obtained, and the maximum entropy is chosen as the threshold of the segmented image, which is the one-dimensional maximum entropy thresholding image segmentation method.

The implementation is as follows (the return value is the threshold used to split the image):

Intgetmaxhtothrod (BYTE *pdata,int width,int Height)

{

int i,j,t;

floatp[256],a1,a2,num[256],max,pt;

if (pdata==null)

{

eturn-1;

}//initialize array p[];

for (i=0;i<256;i++)

p[i]=0.0f;

Count the occurrences of each gray level;

for (i=0;i

for (j=0;j<width;j++)

{

p[* (pdata+width*8) *i+j]++;

}

Statistic the probability of each gray level appearing;

for (j=0;j<256;j++)

{

p[j]=p[j]/(Width*height);

}

Each gray level is compared to each other;

for (i=0;i<256;i++)

{

a1=a2=0.0f;

pt=0.0f;

for (j=0;j<=i;j++)

{

PT+=P[J];

}

for (j=0;j<=i;j++)

{

a1+= (float) p[j]/pt*logf (p[j]/pt);

}

for (j=i+1;j<256;j++)

{

a2+= (float) p[j]/(1-pt) *logf (p[j]/(1-pt));

}

NUM[I]=A1+A2;

}

max=0.0f;

Find the gray level that maximizes the entropy of the class;

for (i=0;i<256;i++)

{

if (Max<num[i])

{

Max=num[i];

t=i;

}

}

Returnt;

}

The disadvantage of this method is that it only considers the gray information of pixel points, and does not take into account the spatial information of pixels, so the segmentation effect is not ideal when the Snr of the image is reduced. There is no doubt that the gray level of the pixel is the most basic characteristic, but it is sensitive to noise, for this reason, the region information of the image can be taken into account when the image is segmented, the area gray feature contains the partial spatial information of the image, and the sensitivity of the noise is lower than the gray-point feature. The two-dimensional maximum entropy thresholding segmentation method is produced by utilizing the features of the image.

When the two-dimensional maximum entropy thresholding algorithm is implemented, the first one region is composed of four pixels of each pixel in the original grayscale image and its neighborhood domain, and the mean value of the gray value I and neighborhood field of the pixel point is a two-dimensional vector (i,j), the probability of statistical (i,j) occurrence, For a given image, because most of the pixels belong to the target area or background, and the target and background area of the internal pixels of the gray level is more uniform, the gray level of the pixel point and its neighborhood mean gray scale difference is not big, so the image corresponding to the two-dimensional histogram is mainly concentrated in the i,j plane near the diagonal, And on the whole the state of Shuangfeng and a valley, the two peaks correspond to the target and the background respectively. At the coordinates away from the diagonal of the ioj plane, the height of the peak drops rapidly, which corresponds to the noise point, stray point and edge point in the image. The two-dimensional histogram of the IOJ plan is shown in figure six, the direction of the diagonal distribution of a, B, respectively, represents the target and the background, away from the diagonal distribution of C and D, respectively, represent the boundary and noise, so should be in a and B area of the point gray-area gray mean two-dimensional maximum entropy method to determine the threshold  The amount of information that divides the target and background is the largest. The algorithm of determining two-dimensional maximum entropy is similar to the one-dimensional maximum entropy algorithm, the function of this algorithm is much the same as the above one-dimensional maximum entropy algorithm, but the pixel points on the image are not only considered in the binary value, but also the gray mean of the point neighborhood.

If an image of the gray level of L, the total number of pixels is n (MXN), set Fi,j as the midpoint of the image to the gray level of I and its region gray mean is the pixel number of J, Pi,j is the point gray-area gray-scale mean pair (I,J) occurrence probability, namely: pi,j=fi,j/n, where n (mx N) is the total number of pixels of the image, then {pi,j,i,j=1,2,...,l} is a two-dimensional histogram of the image's grayscale-area gray-level mean.

In the two-dimensional thresholding method above, for each (s,t) pair, the PA (s,t) and Ha (s,t) are computed from the beginning.

The algorithm is implemented as follows:

(1) Calculate the gray value of each pixel in the original image and the average gray value of 4 neighborhood of each pixel, and calculate the statistic gray information p[i][j];

(2) Related calculations

(3) Find the best threshold (s*,t*), split the image.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.