[Digital image processing] calculated image area perimeter

 

Binarized image area marker

In the binary image, black pixels interconnected into a set (black) regions, each region within the image by marking operation, the number of regions is obtained.
Before treatment value of f is two, the pixel is either 0 (black), or 255 (white)
value of each pixel is the post treatment processing region it numeral (1,2,3, ...)

Marking rules
1. Initialize flag is 0, from left to right, top to bottom by-pixel scanning
2. If the color point of the object, it is determined to continue the upper left point, on the positive, whether or not the upper-right and front-left point of the object , plus the reference numeral 1, if the point is a background color, is skipped.
3. The priority order of the upper right point, is the point, the left front upper left point and point. The highest priority lowest priority, front left point of the upper right point.
4. Continue traversing the image, if the upper right of the object, the point marks on the upper right of the same value.
5. If the object is not an upper right, a positive point is determined, and the left front upper left point Point
special cases: the front left and upper right of the current point is different label point, an upper left point and the point n on the object is not, then the current point with the upper right mark opposite points of the same value, all the marks left front point the same pixel value are marked with the same values of the upper-right point.

FIG following black spots, if the special case of the above occurs, it can be treated:

 

 

 

int sign_count = 0 ;
 int SUM [ . 5 ] = { 0 };
 int sign_temp;
 for ( int Y = . 1 ; Y < 120 - . 1 ; Y ++ )
     for ( int X = . 1 ; X < 180 [ - . 1 ; X ++ ) 
    {    
        / / only when the pixel of the object, performs the following determination. 
        IF (IMG [Y] [X] == 0 ) 
        { 
         // address the special case where 
          IF (IMG [Y- . 1 ] [X + . 1] != img [y][x-1] && img[y-1][x-1] == img[y-1][x])
            {
            img[y][x] = img[y - 1][x + 1];
            sign_temp = img [y][x-1];
            for(int i = 0; i<y; i ++)
                for(int j = 0; j<x;j++)
                {
                    if(img[i][j] == sign_temp)
                    img[i][j] = img[y][x]
                } 
            
            } 
            
           // if four points are all points around the background, the new object point is illustrated, marked accumulation, and assign the mark point. 
           IF ((IMG [Y] [X - . 1 ] + IMG [Y - . 1 ] [X - . 1 ] + IMG [Y - . 1 ] [X] + IMG [Y - . 1 ] [X + . 1 ]) / . 4 ! = 0 ) 
            { 
                   sign_count + = . 1 ; 
                IMG [Y] [X] = sign_count; 
            } 
              // if an object exists around this point, press priority, assigning to the reference point. 
           the else {
             IF (IMG [Y - . 1 ] [X + . 1 !] = 0 )
                img[y][x] = img[y - 1][x + 1];

            else if(img[y - 1][x] != 0)
                img[y][x] = img[y - 1][x];

            else if(img[y - 1][x - 1] != 0)
                img[y][x] = img[y - 1][x - 1];

            else
                img[y][x] = img[y][x - 1];
            }

        }
    }    
//图像面积统计
for(int y = 1; y<120 - 1;y++)
    for(int x = 1; x<180 - 1;x++)
    {      
        switch(img[y][x])
        {
        case 0:{sum[0]++;break;}
        case 1:{sum[1]++;break;}
        case 2:{sum[2]++;break;}
        case 3:{sum[3]++;break;}
        case 4:{sum[4]++;break;}
        }
    }
}

 

  • Binarized image region area measurement

In the binarized image by each pixel in the image marking operation, the pixel value of the object to the reference, the sum of seeking various grade, i.e., to obtain the number of different regions of the area.

 

  • Circumference measurements binarized image

On the basis of the binarized marked area on the pixel value of the object to reference, and then use the boundary tracing method, tracing each numeral enclosed area boundary line (contour line) for each black pixel, binary image recording object boundary.

 

  • Small area of ​​the binary image of the elimination

Then binarized image based on the area marked by the marker region within each image is calculated, determined to give the total number of areas and each area obtained by the area (number of pixels) equal to the threshold value, the erasing region, all set to 255 (white), to thereby obtain a new pattern.

 

Guess you like

Origin www.cnblogs.com/-wenli/p/11722469.html