A kind of method of detected image grey scale change
Technical field
The present invention relates to the image detecting technique in the Flame Image Process, particularly a kind of method of detected image grey scale change.
Background technology
In image detecting technique, it is an important step that the grey scale change of image is detected, and for example: during rim detection, texture detected, the testing result that all is based on grey scale change was handled, thereby finally detects the texture of edge of image or image.
At present, the method of detected image grey scale change is to realize by the Grad of difference operation acquisition pixel, its ultimate principle is exactly the difference that calculates the neighbor gray scale, calculate the Grad of pixel by difference, the big more rate of gray level of just representing of Grad is big more, therefore embodies the situation of variation of image grayscale with Grad.
Referring to Fig. 1, Fig. 1 is the principle schematic of prior art detected image grey scale change.Wherein, pixel P point and pixel P1, pixel P2 point are distinguished adjacent.The Grad that P is ordered by respectively with the P1 point and with the P2 point calculate the level error score value and vertically difference value obtain.Its concrete processing procedure is referring to Fig. 2, and Fig. 2 is the process flow diagram of prior art detected image grey scale change.This flow process may further comprise the steps:
Step 201, the coordinate figure of each pixel of reading images and gray value data store function f (x into, y) in, wherein stored the horizontal ordinate of each pixel, represented with x, y, also stored the gray-scale value (being also referred to as pixel value usually) of each pixel, by f (x, value representation y).
Step 202, the traversal entire image calculates the Grad of each pixel with formula (1), (2), (3), and stores.
At first, calculate level error score value Δ with formula (1), (2)
x(x is y) with vertical difference value Δ for f
yF (x, y):
Δ
xf(x,y)=f(x,y)-f(x+1,y) (1)
Δ
yf(x,y)=f(x,y)-f(x,y-1) (2)
Then, calculate Grad f with formula (3).
Wherein, Grad can also use formula (4) to calculate acquisition.
|f|=|Δxf|+|Δyf| (4)
Step 203 according to the Grad of each pixel of storing, obtains the variation of image grayscale situation.
So just can be according to the bigger principle of texture grey scale change of the edge or the image of general pattern, according to the variation of image grayscale situation that obtains, finally detect the texture of edge of image or image, common way is to judge whether to be edge or texture by predetermined threshold value, if greater than predetermined threshold, then be judged as edge or texture, otherwise be not edge or texture.
But in fact, a lot of images do not have tangible edge, the gray-scale value at its edge is gradual change, place, the image border grey scale change that has is violent, situation for example shown in Figure 3, Fig. 3 is grey scale pixel value first curve map on the horizontal direction of image border, and wherein neighbor P point and the P2 gray-scale value of ordering differs bigger.Place, the image border that has grey scale change is slow, situation for example shown in Figure 4, and Fig. 4 is grey scale pixel value second curve map on the horizontal direction of image border, wherein neighbor P point and the P2 gray-scale value of ordering differs less.
For situation shown in Figure 3, the Grad that obtains with said method is bigger, so can detect the edge; And for situation shown in Figure 4, human eye can distinguish grey scale change and determine the edge, but in said method, because a gray-scale value calculated difference with each pixel adjacent pixels, obtain Grad then, the Grad that obtains under gray scale gradual change situation will be smaller like this.If Grad is less than threshold value, then can't judge is the edge.
Summary of the invention
In view of this, fundamental purpose of the present invention is to provide a kind of method of detected image grey scale change, and this method can detect grey scale change under the situation that gray scale slowly changes, help detecting exactly the texture of edge of image or image.
For achieving the above object, technical scheme of the present invention specifically is achieved in that a kind of method of detected image grey scale change, this method sets in advance first sensing range of calculated level difference value and calculates second sensing range of vertical difference value, and the process of detected image grey scale change comprises:
A, obtain each pixel data of image;
B, traversal entire image, each pixel is carried out:
B1, for a be separated by pixel of first sensing range of pixel selection and this pixel level is set to the horizontal reference pixel, and be set to vertical reference pixel with vertically a be separated by pixel of second sensing range of this pixel;
B2, with the gray-scale value of all pixels in pixel first sensing range and and horizontal reference pixel first sensing range in all pixels gray-scale value and, obtain the level error score value;
B3, with the gray-scale value of all pixels in pixel second sensing range and and vertically in reference pixel second sensing range gray-scale value of all pixels and, obtain vertical difference value;
B4, with the level error score value that calculates and vertical difference value, calculate the Grad of this pixel;
The Grad that C, basis calculate obtains the variation of image grayscale situation.
Wherein, the value that described first sensing range can be set equates with the value of second sensing range or does not wait.
The described selection horizontal reference of step B1 pixel and vertically reference pixel method can for:
Step B2 is described obtain the level error score value method can for:
With the gray-scale value of all pixels in horizontal reference pixel first sensing range and with pixel first sensing range in all pixels gray-scale value and ask poor, obtain the level error score value.
Step B3 is described obtain vertical difference value method can for:
With the gray-scale value of all pixels in vertical reference pixel second sensing range and with pixel second sensing range in all pixels gray-scale value and ask poor, obtain vertical difference value.
The method of the Grad of described this pixel of calculating can for:
With the level error score value of pixel and vertically difference value respectively square after addition, the result of addition is carried out evolution, obtain the Grad of this pixel.
The method of the Grad of described this pixel of calculating also can for:
With the level error score value of pixel and the vertically difference value back addition that takes absolute value respectively, obtain the Grad of this pixel.
As seen from the above technical solutions, the method of this detected image grey scale change of the present invention, widen the scope of detection, statistics with one section zone around each pixel is come the compute gradient value, just is extended to contrast between regional area from point and the contrast of putting, and gray scale difference has been widened, the Grad that obtains has also strengthened, therefore can under the situation that gray scale slowly changes, detect grey scale change, help detecting exactly the texture of edge of image or image.
Description of drawings
Fig. 1 is the principle schematic of prior art detected image grey scale change;
Fig. 2 is the process flow diagram of prior art detected image grey scale change;
Fig. 3 is grey scale pixel value first curve map on the horizontal direction of image border;
Fig. 4 is grey scale pixel value second curve map on the horizontal direction of image border;
Fig. 5 is the preferred embodiment principle schematic of detected image grey scale change of the present invention;
Fig. 6 is a process flow diagram embodiment illustrated in fig. 5;
Fig. 7 is grey scale pixel value the 3rd curve map on the horizontal direction of image border.
Embodiment
For making purpose of the present invention, technical scheme and advantage clearer, below with reference to the accompanying drawing embodiment that develops simultaneously, the present invention is described in more detail.
The main thought of the method for detected image grey scale change of the present invention is: the scope of widening detection, statistics with one section zone around each pixel is come the compute gradient value, just be extended to contrast between regional area from point and the contrast of putting, gray scale difference has been widened, the Grad that obtains has also strengthened, therefore can under the situation that gray scale slowly changes, detect grey scale change, help detecting exactly the texture of edge of image or image.
Referring to Fig. 5, Fig. 5 is the preferred embodiment principle schematic of detected image grey scale change of the present invention.Set in advance first sensing range value n of calculated level difference value and the second sensing range value m of the vertical difference value of calculating in the present embodiment, easy in order to handle, n=m in the present embodiment also can be unequal in the practical application.
Among Fig. 5, the P point is detected pixel, the horizontal reference pixel that the P2 point is ordered for P; P1 selects the vertical reference image vegetarian refreshments of selecting into P.P1 point and P point n, P2 point and the P point level n of being separated by of vertically being separated by, the n/2 of being separated by respectively between A point, P point, B point, P2 point, C point.The n/2 of being separated by respectively between D point, P point, E point, P1 point, F point.
Referring to Fig. 6, Fig. 6 is a process flow diagram embodiment illustrated in fig. 5.This flow process may further comprise the steps:
Step 601, data such as the gray-scale value of each pixel of reading images, coordinate figure and storage.
In this step, the method for storage can be same as the prior art, promptly store into function f (x, y) in.Certainly adopt other modes to store, as long as can be with the gray-scale value and the coordinate figure corresponding stored of each pixel.
Step 602 is selected a pixel.
Step 603, calculate to select pixel level direction all neighbors in the n scope gray-scale value with 1.
Step 604 is set to the horizontal reference pixel with selecting the be separated by pixel of n of pixel level, obtain horizontal reference pixel level direction all adjacent pixels in the n scope gray-scale value with 2.
Step 605, the gray-scale value that step 604 is obtained with 2 gray-scale values that obtain with step 603 with 1 ask difference to calculate, obtain level error score value Δ
xF (x, y).
Step 603~step 605 can be represented by formula (5):
Wherein, a is the abscissa value that P is ordered.
Step 606, calculate to select pixel vertical direction all neighbors in the n scope gray-scale value with 3.
Step 607 is set to vertical reference pixel with selecting vertically the be separated by pixel of n of pixel, obtain vertical reference pixel horizontal direction all adjacent pixels in the n scope gray-scale value with 4.
Step 608, gray-scale value that step 607 is obtained with 4 gray-scale values that obtain with step 606 with 3 ask difference to calculate, obtain vertical difference value Δ
yF (x, y).
Step 606~step 608 can be represented by formula (6):
Wherein b is the ordinate value that P is ordered.
The level error score value Δ that step 609, usefulness calculate
x(x is y) with vertical difference value Δ for f
y(x y), calculates the Grad f and the storage of this pixel to f.
Can employing formula same as the prior art (3) or formula (4) computing acquisition in this step.
Step 610 judges whether to also have non-selected pixel, if having then return execution in step 602, selects next pixel; Otherwise execution in step 611.
Step 611 according to the Grad of each pixel of storing, obtains the variation of image grayscale situation.
By above-mentioned process as seen, obtain horizontal difference and perpendicular value difference value with the gray-scale value of all pixels between detected pixel and the reference pixel in the present embodiment, the obvious result who obtains directly obtains horizontal difference than adjacent two pixels and vertically difference is big.
Referring to Fig. 7, Fig. 7 is grey scale pixel value the 3rd curve map on the horizontal direction of image border.Wherein the P point is a check point, and the P2 point is a horizontal reference point, and P point and P2 point standoff distance are the first sensing range value n of the calculated level difference value that sets in advance, the n/2 of being separated by respectively between A point, P point, B point, P2 point, C point.
As seen from Figure 7, in the horizontal direction, by with [B, C] all interior pixel values summation backs and [A of scope, B] the back horizontal difference that obtains of interior all pixel values summations of scope, it is big obviously directly to obtain horizontal difference than adjacent two pixels, and the Grad that calculates is also big.Principle is identical on the vertical direction, repeats no more here.Therefore, this method can detect grey scale change under the situation that gray scale slowly changes, help detecting exactly the texture of edge of image or image.