Disclosure of Invention
The invention aims to provide a method for processing background color bleeding and denoising of an image, aiming at the defects of the prior art.
The technical scheme adopted by the invention for solving the technical problem comprises the following steps:
the method comprises the following steps of (1) binarizing an original picture, expressing an R value set in picture pixel RGB values by using SrcImage, expressing the R value of a certain pixel point (x, y) of the picture by using SrcImage [ x ] [ y ] (the x axis and the y axis respectively express the length and the width), and expressing the width and the height of the picture by using ImageWidth and Imageheight respectively;
step (2), externally providing parameter values: RGBThresholdPercent (color threshold ratio, unit float), SamplingInterval (sampling interval, unit int), ImageRect (segmentation graph side length, unit int)
Step (3), creating a two-bit array DscImage for storing R value information of each pixel point after picture processing, wherein the DscImage [ x ] [ y ] and the SrcImage [ x ] [ y ] coordinate correspond to each other one by one;
and (4) carrying out block statistics on the picture according to the segmentation image edge length value ImageRect in order to improve the accuracy of image processing. The width of the picture is divided into WidthNum, WidthNum ═ ImageWidth/ImageRect + (ImageWidth% ImageRect >01: 0); the height of the picture is divided into height num ═ ImageHeight/ImageRect + (ImageHeight% ImageRect >01: 0); pictures are divided into ImageNum, width num, height num.
Step (5), acquiring the area information of the nth block diagram:
the upper, lower, left and right values of the block are ItemTop, ItemBottom, ItemLeft, ItemRight, respectively:
ItemTop=n/WidthNum*ImageRect;
ItemBottom ═ ItemTop + ImageRect, ItemBottom ═ ImageHeight if ItemBottom > ImageHeight;
ItemLeft=n%WidthNum*ImageRect;
ItemRight ═ ItemLeft + ImageRect, ItemRight ═ ImageWidth if ItemRight > ImageWidth.
The total pixel point ItemPointTotalNum of the block:
ItemPointTotalNum=(ItemRight–ItemLeft+1)*(ItemBottom–ItemTop+1)。
step (6), according to the RGB color values, calculating a sampling point array DSB for the nth block diagram at a color sampling interval SamplingInterval: DSB { { Ai, Weight i } }; a. theiRepresenting the current sample color value, WeightiRepresenting the current sample color value as AiWhen the color value in the block map is AiThe number of the pixel points;
step (7), counting the color threshold RGBThreshold of the nth block diagram,
circularly sampling point array DSB, accumulating sampling color value A from i-0iStatistic value of (3)iThe loop is skipped until the accumulated value is greater than ItemPointTotalNum RGBThresholdPercent. RGBThreshold ═ (Weight 0+ Weight 1+ … + Weight i)
Step (8), traversing each pixel point of the nth block diagram, if SrcImage [ x ] [ y ] < (RGBThreshold) and DscImage [ x ] [ y ] < 0, otherwise, DscImage [ x ] [ y ] < 255
And (9) calculating each minimap according to the steps (5) to (8) to obtain the final DscImage.
Step (10), externally calculating the value of parameters such as RGBThresholdPercent and the like through parameter quality
RGBThresholdPercent1=0.6+0.15*quality;
ImageRect1=700*quality;
SamplingInterval1=RGBThresholdPercent1*4;
RGBThresholdPercent2=0.45+0.15*quality;
ImageRect2=35/quality;
SamplingInterval2=RGBThresholdPercent2*4;
Step (11), performing steps (2) to (9) by using RGBThresholdPercent1, SamplingInterval1 and ImageRect1 to obtain DscImage 1;
performing steps (2) - (9) with RGBThresholdPercent2, SamplingInterval2, ImageRect2 to obtain DsciImage 2;
and (12) sequentially traversing the pixels of the DscImage1 and DscImage2, wherein if the DscImage1[ x ] [ y ] ═ 255, the DscImage2[ x ] [ y ] ═ 255.
And (13) using the traversed DscImage2 to generate a picture.
The value of n according to the invention is from 0;
the quality of the invention can adjust the image processing effect, the quality is more than 0.0 and less than 1.0, the standard value is 0.8, more noise can be caused when the standard value is less than 0.8, and partial text information can be lost when the standard value is more than 0.8.
The invention has the following beneficial effects:
the method is different from other image processing software, aims at processing the character and the picture, binarizes the image, changes the background color of the image into white, highlights characters, removes interference points or lines, enhances the display effect of the title characters, and shields the influence of factors such as paper, light and the like on the picture. Therefore, when students assemble subjects into words for printing, the problems of graying of the background color, unclear characters and the like can be avoided. The method is currently applied to post-session web wrong answer books.
According to the invention, through steps (10) - (13), the image processing effect is adjusted through quality, the standard value is 0.8, noise is excessive when the standard value is less than 0.8, and partial text information is lost when the standard value is more than 0.8. The positioning is accurate through quality, and noise points and text information loss are reduced.
Detailed Description
The present invention will be further described with reference to the following examples.
A picture ground color bleeding and denoising processing method specifically comprises the following steps:
the method comprises the following steps of (1) binarizing an original picture, expressing an R value set in picture pixel RGB values by using SrcImage, expressing the R value of a certain pixel point (x, y) of the picture by using SrcImage [ x ] [ y ] (the x axis and the y axis respectively express the length and the width), and expressing the width and the height of the picture by using ImageWidth and Imageheight respectively;
step (2), externally providing parameter values: RGBThresholdPercent (color threshold ratio, unit float), SamplingInterval (sampling interval, unit int), ImageRect (segmentation graph side length, unit int)
Step (3), creating a two-bit array DscImage for storing R value information of each pixel point after picture processing, wherein the DscImage [ x ] [ y ] and the SrcImage [ x ] [ y ] coordinate correspond to each other one by one;
and (4) carrying out block statistics on the picture according to the segmentation image edge length value ImageRect in order to improve the accuracy of image processing. The width of the picture is divided into WidthNum, WidthNum ═ ImageWidth/ImageRect + (ImageWidth% ImageRect >01: 0); the height of the picture is divided into height num ═ ImageHeight/ImageRect + (ImageHeight% ImageRect >01: 0); pictures are divided into ImageNum, width num, height num.
Step (5), acquiring the area information of the nth block diagram:
the upper, lower, left and right values of the block are ItemTop, ItemBottom, ItemLeft, ItemRight, respectively:
ItemTop=n/WidthNum*ImageRect;
ItemBottom ═ ItemTop + ImageRect, ItemBottom ═ ImageHeight if ItemBottom > ImageHeight;
ItemLeft=n%WidthNum*ImageRect;
ItemRight ═ ItemLeft + ImageRect, ItemRight ═ ImageWidth if ItemRight > ImageWidth.
The total pixel point ItemPointTotalNum of the block:
ItemPointTotalNum=(ItemRight–ItemLeft+1)*(ItemBottom–ItemTop+1)。
step (6), according to the RGB color values, calculating a sampling point array DSB for the nth block diagram at a color sampling interval SamplingInterval: DSB { { Ai, Weight i } }; a. theiRepresenting the current sample color value, WeightiRepresenting the current sample color value as AiWhen the color value in the block map is AiThe number of the pixel points;
step (7), counting the color threshold RGBThreshold of the nth block diagram,
circularly sampling point array DSB, accumulating sampling color value A from i-0iStatistic value of (3)iThe loop is skipped until the accumulated value is greater than ItemPointTotalNum RGBThresholdPercent. RGBThreshold ═ (Weight 0+ Weight 1+ … + Weight i)
Step (8), traversing each pixel point of the nth block diagram, if SrcImage [ x ] [ y ] < (RGBThreshold) and DscImage [ x ] [ y ] < 0, otherwise, DscImage [ x ] [ y ] < 255
And (9) calculating each minimap according to the steps (5) to (8) to obtain the final DscImage.
Step (10), externally calculating the value of parameters such as RGBThresholdPercent and the like through parameter quality
RGBThresholdPercent1=0.6+0.15*quality;
ImageRect1=700*quality;
SamplingInterval1=RGBThresholdPercent1*4;
RGBThresholdPercent2=0.45+0.15*quality;
ImageRect2=35/quality;
SamplingInterval2=RGBThresholdPercent2*4;
Step (11), performing steps (2) to (9) by using RGBThresholdPercent1, SamplingInterval1 and ImageRect1 to obtain DscImage 1;
performing steps (2) - (9) with RGBThresholdPercent2, SamplingInterval2, ImageRect2 to obtain DsciImage 2;
and (12) sequentially traversing the pixels of the DscImage1 and DscImage2, wherein if the DscImage1[ x ] [ y ] ═ 255, the DscImage2[ x ] [ y ] ═ 255.
And (13) using the traversed DscImage2 to generate a picture.
The value of n according to the invention is from 0;
the quality of the invention can adjust the image processing effect, the quality is more than 0.0 and less than 1.0, the standard value is 0.8, more noise can be caused when the standard value is less than 0.8, and partial text information can be lost when the standard value is more than 0.8.