1,Basic Principles of image binarization
The binarization processing of images is about Set the gray level of the vertex 0 Or255 That is to say, the entire image shows a significant black/white effect. Coming soon 256 Gray-scale images of different brightness levels are obtained by selecting appropriate thresholds, which can still reflect the overall and local features of the image. Binary Images play a very important role in digital image processing. Especially in practical image processing, there are many systems that are implemented by binary image processing, to process and analyze a binary image, first binarization the gray image to obtain a binary image, which facilitates further processing of the image, the set nature of the image is only consistent with the pixel value 0 Or 255 It does not involve the multi-level values of pixels, which makes processing simple and has a small amount of data processing and compression. To obtain an ideal binary image, a closed and connected boundary is usually used to define areas that do not overlap. All pixels whose gray level is greater than or equal to the threshold value are determined to belong to a specific object, and their gray level value is 255 Otherwise, these pixels are excluded from the object area and the gray value is0 Indicates the background or the area of the exception object. If a specific object has an even and consistent gray value inside and is in an even background with a gray value of other levels, you can use the threshold method to obtain a better segmentation effect. If the difference between the object and the background is not displayed on the gray level (for example, the texture is different), you can convert the difference feature to the gray level difference, and then use the threshold value selection technology to split the image. The dynamic control valve value achieves image binarization and can dynamically observe the specific results of its segmentation image.
2,Binarization of imagesProgramImplementation
The following procedures are implemented using QT
bool convertgray: converttobinary (INT threshold)
{< br> qimage rgbimage (rgbfile);
qsize size = rgbimage. size ();
qimage binaryimage (size, qimage: format_rgb32);
int width = size. width ();
int Height = size. width ();
for (INT I = 0; I for (Int J = 0; j {< br> qrgb pixel = rgbimage. pixel (I, j);
int r = qred (pixel) * 0.3;
int G = qgreen (pixel) * 0.59;
int B = qblue (pixel) * 0.11;
int RGB = R + G + B; // grayscale the image first, convert to grayscale image
If (RGB> threshold) // perform binarization based on a threshold value
{< br> RGB = 255;
}else
{< br> RGB = 0;
}< br> qrgb newpixel = qrgb (RGB, RGB, RGB);
binaryimage. setpixel (I, j, newpixel);
}< br> binaryimage. save (binaryfile);
UI. graylabel-> setpixmap (qpixmap (binaryfile);
return true;
}
3,Processing results