Summary of the invention
The histogram adjustment method and the debug system thereof that the purpose of this invention is to provide a kind of coloured image; To overcome the deficiency of prior art; To realize that the image to different intensity profile carries out the debugging of effective man-machine interaction; Realize the histogram adjustment and balanced coloured image gray scale of more optimization, further promote the quality of coloured image.
The present invention makes full use of the RGB color model of using in multi-purpose computer and the iconic model; Realize coloured image is debugged through this gradation of image information representation of the histogram mode that obtains that converts via the RGB color model; Only need to set the gray areas and the threshold value of image adjustment through man-machine interaction mode; Just can use the present invention that coloured image is handled, obtain result to different Luminance Distribution images.
A kind of histogram adjustment method of coloured image at first obtains the histogram of this coloured image, it is characterized in that this method may further comprise the steps:
(1) histogram subregion node is set, promptly set arbitrarily 0 to 255 with interior gray scale as the subregion node, does not perhaps set node and whole histogram is used as a subregion debugs, and the groups of nodes that obtains respective numbers is a subregion;
(2) histogram subregion threshold value is set, promptly each subregion in the step (1) is set an interior gray scale of this subregion as threshold value;
(3) greyscale transformation is promptly calculated the skew gray-scale value to each groups of nodes and corresponding threshold thereof, comprises following content:
Begin from the lower limit of each groups of nodes, read the GTG in the groups of nodes defined range, and judge the relation of GTG and threshold value: if current GTG is less than threshold value, then according to left side GTG function calculation skew gray-scale value; If current GTG is greater than threshold value, then according to right side GTG function calculation skew gray-scale value; If current GTG equals threshold value, then threshold value is left the skew gray-scale value, under the computing formula:
Right grayscale function:
Formula 1
Wherein:
Left side grey exponent number=threshold value-nodal value lower limit
The right side ash exponent number=nodal value upper limit-threshold value+1; Formula 2
If 1/2 total grey exponent number is not an integer, then round numbers part, fractions omitted part; If the result that above-mentioned skew gray-scale value computing formula obtains is not integer, then round numbers part, fractions omitted part;
(4) coloured image is revised, each gray-scale value that is about to original colorful image replaces with the skew gray-scale value that calculates according to step (3);
(5) generate the result.
In the above-mentioned steps (1), can be according to the histogrammic situation of successively decreasing that increases progressively, histogrammic each local peak or local minimum point are set to node, promptly through the subregion node is set, and make the GTG in the groups of nodes of gained be monotone increasing or successively decrease.
When above-mentioned steps (2) was provided with the subregion threshold value to each subregion, the difference that makes the pixel quantity of threshold value both sides in the subregion was in 5000 point ranges.Since the resolution of screen often hundreds of thousands in addition up to a million more than, the difference of the pixel quantity of threshold value both sides is equal basically with the pixel number of these threshold value both sides of interior sufficient to guarantee at 5000 point ranges.
A kind of histogram debug system of coloured image is characterized in that this system comprises to be respectively applied for subregion node module and the subregion threshold module that subregion node and groups of nodes threshold value are set; Histogram is carried out the histogram division module of subregion according to the subregion joint; The threshold setting module of the joining property of judgment threshold and histogram subregion; Histogram is carried out the greyscale transformation module of greyscale transformation; Original gray scale is replaced with conversion image gray correcting module afterwards;
Above-mentioned greyscale transformation module comprises following content: accept subregion groups of nodes and threshold information from the threshold setting module; Be offset gray-scale value calculating according to subregion groups of nodes and threshold information, computation process adopts the mode of formula 1,2 to carry out, and result of calculation is saved as skew gray scale array, and export to image modification module.
Above-mentioned histogram division module comprises following content: according to the subregion node of user input the histogram of coloured image is carried out subregion, the subregion result is exported to the threshold setting module in order.
Above-mentioned threshold setting module comprises following content: accept the subregion result from the histogram division module; According to the threshold information judgment threshold of user's setting and the matching of subregion groups of nodes; Deposit classification results in array, and export to the greyscale transformation module.
Above-mentioned image modification module comprises following content: initialization target image and storage pixel address information; Acceptance is from the skew gray scale array of greyscale transformation module; According to skew gray scale array revise goal image and the preservation accepted.
At last, generating the result gets final product.
Adopt said system to realize the method that coloured image is debugged, may further comprise the steps through the histogram of regulating coloured image:
At first with pending coloured image input computing machine; The system that image modification module, histogram division module, threshold setting module, greyscale transformation module are formed is installed in the computing machine;
The histogram division module is accepted the subregion nodal information that the user is provided with, and the subregion node is divided into groups, and the subregion groups of nodes is transferred to the threshold setting module with the array form; The threshold setting module receives the threshold value that the user is provided with; Reception is from the node array of histogram division module; And to the matching of judging both according to threshold value and groups of nodes information (so-called matching be meant threshold value must in groups of nodes interval); With array stores matching result, the array that will comprise matched node group and threshold information is transferred to the greyscale transformation module; The greyscale transformation module receives the match information from the threshold setting module, calculates the skew gray-scale value, presses skew gray scale array correction original image gray-scale value through image modification module; The result of output entire image, debug process finishes.
The present invention has the function novelty, realizes advantages such as simple, with low cost, debugging effect is obvious.Realized the debugging of user through utilizing histogram to the RGB gradation of image; Not only overcome the limitation of existing software on the gray scale debug function; And the user also can set arbitrary threshold in any interval of image histogram and this interval according to self-demand, embodied very strong interactivity, dirigibility and versatility.The computing formula 1 and 2 of step of the present invention (3) has adopted the method for weighting translation; The weighting shift method has fully been safeguarded the gray scale structure of histogram itself; No matter what kind of subregion and threshold value are set; Can realize the weighted transformation of threshold value both sides gray scale; This method is more stable than the method for traditional linear translation; The gradation of image distribution is undergone mutation, thereby guaranteed the steady conversion of entire image.What be worth explanation is; Because the present invention allows in 0 to 255, at random to set subregion; And any gray scale all can be set to threshold value in the subregion; Therefore not only can realize this basic effect of gray balanceization of coloured image; But more as a kind of method in common or instrument, pass through the characteristics that subregion and threshold value arbitrariness thereof are set; Coloured image is carried out any conversion and debugging via histogram, be with a wide range of applications undoubtedly.
Embodiment
As shown in Figure 1, a kind of histogram adjustment method of coloured image at first obtains the histogram of this coloured image, and is further comprising the steps of:
(1) user is provided with histogram subregion node, promptly the user set arbitrarily 0 to 255 with interior gray scale as the subregion node, does not perhaps set node and whole histogram is used as a subregion debugs, and the groups of nodes that obtains respective numbers is a subregion;
(2) user is provided with histogram subregion threshold value, and promptly the user sets an interior gray scale of this subregion as threshold value to each subregion in the step (1);
(3) greyscale transformation is promptly calculated the skew gray-scale value to the array of each groups of nodes and corresponding threshold value thereof, comprises following content:
Begin from the lower limit of each groups of nodes, read the GTG in the groups of nodes defined range, and judge the relation of GTG and threshold value: if current GTG is less than threshold value, then according to left side GTG function calculation skew gray-scale value; If current GTG is greater than threshold value, then according to right side GTG function calculation skew gray-scale value; If current GTG equals threshold value, then threshold value is left the skew gray-scale value, computing formula is following:
Right grayscale function:
Formula 1
Wherein:
Left side grey exponent number=threshold value-nodal value lower limit
The right side ash exponent number=nodal value upper limit-threshold value+1; Formula 2
If 1/2 total grey exponent number is not an integer, then round numbers part, fractions omitted part; If the result that above-mentioned skew gray-scale value computing formula obtains is not integer, then round numbers part, fractions omitted part;
(4) coloured image is revised, each gray-scale value that is about to original colorful image replaces with the skew gray-scale value that calculates according to step (3);
(5) generate the result.
As shown in figure 10; In the above-mentioned steps (1); The user can be according to the histogrammic situation of successively decreasing that increases progressively; Histogrammic each local peak or local minimum point are set to node; Be that the user is through being provided with the subregion node; And make the interior GTG of groups of nodes of gained be monotone increasing or successively decrease, and can more help making debug results level and smooth as far as possible like this, improve image quality; The user also can set node arbitrarily according to self needs, and every width of cloth histogram can be set a node arbitrarily, is divided into a subregion arbitrarily, but node must be more than or equal to zero and less than 255, because be 0 to 255 between gray area; The user also can not set node, so whole histogram is used as a subregion and is debugged; After the user has set the subregion node, carry out the threshold value setting of subregion groups of nodes again.
When above-mentioned steps (2) user was provided with the subregion threshold value to each subregion, the difference that makes the pixel quantity of threshold value both sides in the subregion was in 5000 point ranges.Since the resolution of screen often hundreds of thousands in addition up to a million more than, the difference of the pixel quantity of threshold value both sides is equal basically with the pixel number of these threshold value both sides of interior sufficient to guarantee at 5000 point ranges.The user also can be according to any setting threshold of self needs, but each subregion can only be provided with a threshold value, otherwise prompting makes mistakes.
As shown in Figure 1, a kind of histogram debug system of coloured image is characterized in that this system comprises to be respectively applied for the subregion node module 101 and subregion threshold module 102 that subregion node and groups of nodes threshold value are set; Histogram is carried out the histogram division module 103 of subregion according to the subregion joint; The threshold setting module 104 of the joining property of judgment threshold and histogram subregion; Histogram is carried out the greyscale transformation module 105 of greyscale transformation; Original gray scale is replaced with conversion image gray correcting module 106 afterwards;
Above-mentioned greyscale transformation module 105 comprises following content: accept subregion groups of nodes and threshold information from threshold setting module 104; Be offset gray-scale value calculating according to subregion groups of nodes and threshold information, computation process adopts the mode of formula 1,2 to carry out, and result of calculation is saved as skew gray scale array, and export to image modification module 106.
Fig. 5 representes above-mentioned greyscale transformation module 105, comprises following content: accept subregion groups of nodes and the array 509 of corresponding threshold value thereof after the coupling that comprise from 104; The legitimacy 502 of decision instruction; The legitimacy of query statement value; Calculate skew gray-scale value 505 according to 509 dope vectors that received; Generate skew gray scale array 506; Judge to use whether finish 507.
Fig. 8 representes aforementioned calculation skew gray-scale value subprocess 505, comprises following content: read groups of nodes and corresponding threshold value 802 thereof; The computing function factor 803 comprises grey exponent number 804, the 1/2 total grey exponent numbers 805 in left side, and right side ash exponent number 806 calls in order to calculating the skew gray-scale value.Computing formula is suc as formula shown in 2:
Left side grey exponent number=threshold value-nodal value lower limit
The right side ash exponent number=nodal value upper limit-threshold value+1
Formula 2 function factor calculation formula
If 1/2 total grey exponent number is not an integer, then round numbers part, fractions omitted part; Begin from the nodal value lower limit, read the GTG 807 in the groups of nodes defined range; That judges GTG and threshold value concerns 808, and situation in three is arranged: current GTG is less than threshold value 809, and current GTG is greater than threshold value 810, and current GTG equals threshold value 811; If current GTG less than threshold value, then calculates the skew gray-scale value according to left side GTG function 812; If current GTG greater than threshold value, then calculates the skew gray-scale value according to right side GTG function 813; If current GTG equals threshold value, then threshold value is left the skew gray-scale value.Computing formula is shown in formula 1:
Right grayscale function:
Formula 1 skew gray-scale value computing formula
If the result that above-mentioned skew gray-scale value computing formula obtains is not integer, then round numbers part, fractions omitted part; After current GTG skew gray scale is calculated and finished, judge whether GTG arrives position, end 815, judges promptly whether gray scale reaches the nodal value upper limit, if reach then calculate end, if do not reach then grey exponent number adds 1 816, circulate 807 to 815 process of continuation.
Fig. 3 representes above-mentioned histogram division module 103, comprises following content: accept the subregion node 309 from 101; The legitimacy 302 of decision instruction; The legitimacy 304 of query statement value; The subregion node is divided into groups 305; The subregion groups of nodes is exported to 104 306 in order; Judge to use whether finish 307.
Fig. 6 represent above-mentioned with the border pair principle to the subregion node subprocess 305 that divides into groups, comprise following content: receive the subregion node, with in 0 and 255 two gray scale adding subregion node 602; Sort 603 to comprising 0 and 255 node; Deposit the ranking results order in array 604; Read current address and next address information 605 from the ranking results array, and store 606, judge whether second bit address is position, end 607, if the position, end then divides into groups to finish, then the address variable increases by 1608 if not the position, end, continues operation 605 to 607 processes.
Fig. 4 representes above-mentioned histogram thresholding setting module 104, comprises following content: accept the subregion node array 410 from 103; The legitimacy 402 of decision instruction; The legitimacy 404 of query statement value; Reception is from 102 threshold information 405; The decision threshold matching also classifies 406; Classification results is sent to greyscale transformation module 105 with the array form; Judge to use whether finish 408.
Fig. 7 representes above-mentioned decision threshold matching and classification and storage subprocess 406, comprises following content: the array 702 that reads groups of nodes by the address from the first place successively; Circulation read threshold information 706; To groups of nodes data and threshold value; Recycling and logic determines; Threshold value that and if only and if groups of nodes satisfy following relation: < the groups of nodes upper limit then deposits the corresponding threshold value of groups of nodes in new array 704, then reports an error and points out and revise input value 707 as not satisfying for groups of nodes lower limit≤threshold value and threshold value; Whether the group address of decision node group arrives last one 705, if end position then edge determination finish, then group address increases by 1708 if not the position, end, continues the process of circulation 702 to 705.
Fig. 2 representes above-mentioned image modification module 106, comprises following content: initialization is also duplicated by original image and to be generated target image 202; Acceptance is from 105 skew gray scale array 209; Judge the legitimacy 204 of access instruction; The legitimacy 205 of query statement value; According to skew gray scale correction image process 206; Judge to use whether finish 207; Preserve new images 208.
Fig. 9 representes above-mentioned according to skew gray scale correction image subprocess 206, comprises following content: accept skew gray scale array 902; Read current target image 903; In the groups of nodes interval, get gray-scale value 904; The pixel 905 of this gray scale of search in original image; Write down the address 907 of this pixel; In skew gray scale array, get the skew gray scale 906 of respective pixel; The gray scale of revise goal image 909 respective pixel is skew gray scale 908; Judge whether this gray scale reaches interval border 910.
After revising the end of from 0 to 255 GTG through image modification module 106, the GTG of the new images after then expression is debugged, i.e. debugging generates result 107.
Adopt said system to carry out the method that the coloured image debugging is handled, may further comprise the steps through regulating the coloured image histogram:
A, at first with pending coloured image input computing machine; The system that image modification module 106, histogram division module 103, threshold setting module 104, greyscale transformation module 105 are formed is installed in the computing machine;
B, user interactions mode: the user is provided with subregion node 101, and sends the subregion nodal information to histogram division module 103; The user is provided with subregion threshold value 102, and sends the subregion threshold information to histogram thresholding setting module 104.
C, the subregion node is carried out matched packet 305, comprise following content: receive the subregion node, in 0 and 255 two gray scale adding subregion node 602; Sort 603 to comprising 0 and 255 node; Deposit the ranking results order in array 604; Read current address and next address information 605 from the ranking results array, and store 606, judge whether second bit address is position, end 607, if the position, end then divides into groups to finish, then the address variable increases by 1 608 if not the position, end, continues operation 605 to 607 processes.
D, decision threshold matching also classify 406, comprise following content: the array 702 that reads groups of nodes by the address from the first place successively; Circulation read threshold information 706; To groups of nodes data and recycling and logic determines; Threshold value that and if only and if groups of nodes satisfy following relation: groups of nodes lower limit≤threshold value and threshold value < the groups of nodes upper limit; Then deposit the corresponding threshold value of groups of nodes in new array 704, then report an error and point out and revise input value 707 as not satisfying; Whether the group address of decision node group arrives last one 705, if the then edge determination end of position, end, then group address increases by 1 708 if not the position, end, continues the process of circulation 702 to 705.
E, calculating skew gray-scale value 505 comprise following content: read groups of nodes and corresponding threshold value 802 thereof; According to the formula 1 computing function factor 803; Begin from the nodal value lower limit, read the GTG 807 in the groups of nodes defined range; That judges GTG and threshold value concerns 808, and situation in three is arranged: current GTG is less than threshold value 809, then according to the left side GTG function calculation of formula 2; Current GTG is greater than threshold value 810, then according to the right side GTG function calculation of formula 2; Current GTG equals threshold value 811, then threshold value is kept; After current GTG skew gray scale is calculated and finished, judge whether GTG arrives position, end 815, if reach then calculate end, if do not reach then grey exponent number adds 1 816, circulate 807 to 815 process of continuation.
F, according to the skew gray-scale value correction original color image that above-mentioned greyscale transformation module 105 calculates, generate result 107 at last.
Embodiment 1
As shown in figure 10, Figure 10 a is the histogram of certain coloured image, and its situation of change from 0~255 is to change little (keeping sustained height basically) earlier, suddenly rises then until peak, descends then.The user can only establish a subregion node, shown in Figure 10 b, peak can be made as the subregion node and obtain two subregions, thereby previous subregion is monotone increasing trend, and a back subregion is monotone decreasing trend.
The user is provided with two subregions threshold value separately then, and for the pixel number that makes the threshold value both sides is equal basically, shown in Figure 10 b, the threshold value of previous subregion is near subregion node (being mxm.), and then the threshold value of a subregion is the centre position at this subregion basically.
After utilizing the present invention to debug, the histogram of this coloured image is shown in Figure 10 c.Because the present invention is the algorithm that adopts the weighting translation; Can make some gray scale integral body be adjusted into other gray scales after the debugging; The situation that the gray scale vacancy therefore can occur; This is because for the same area; The histogram thresholding both sides necessarily have a side to have the stretching phenomenon; Be that original number of greyscale levels is wanted during weighting moves between a wideer gray area; Therefore necessarily having some gray scales is in the vacancy state after conversion; But this variation can not exert an influence for the improvement of entire image effect, shows as gray balanceization generally.
Embodiment 2
Below in conjunction with accompanying drawing, be embodiment with the debugging of a width of cloth RGB image histogram, the present invention is realized that through regulating the coloured image histogram embodiment of Digital Image Processing does further detailed description:
Import a width of cloth RGB image, the user node a and b (0 < a <b < 255=, and subregion threshold value 102 is set threshold value m, n, k (0 < m < a < n <b < k < 255=are set through subregion node 101 is set.Like Fig. 1, the subregion node of setting sends to histogram division module 103, and the subregion threshold value of setting sends to histogram thresholding setting module 104.
Like Fig. 3, subregion node input 309, instruct judge 302 with inquiry legitimacy 304, do not report an error and the error message process 303 of resetting then be provided if conform to rule, if legal then get into the subregion node is carried out packet link 305.As shown in Figure 6,0 and 255 two gray scale is added subregion node 602, form a, b, 0,255 groups of nodes; It is sorted 603, form 0, a, b, 255 groups of nodes; Deposit its ranking results in array 604; Read array first address 0 and the second address a 605, and save as [0, a] 606 in proper order by two one group; Judge that a is not position, array end 607, so group address+1 608 continued circulation, read array second address a and the three-address b 605, and save as [a, b] 606 in proper order by two one group; Judge that b is not that therefore position, array end 607 is circulated and 605,606 stored according to [b, 255].As judge 255 for position, array end, then finish this process and get into next process 609; The subregion groups of nodes is exported to 104306 in order.
Like Fig. 4; Acceptance is from 103 subregion groups of nodes 410; Instruct judge 402 with inquiry legitimacy 404; If not conforming to rule reports an error and the error message process 403 of resetting then is provided; If legal then get into the decision threshold matching and classify 406, accept user's threshold information 405 simultaneously from 102; Like Fig. 7, read groups of nodes [0, a] 702,102 threshold values [m, n, k] that are provided with are read in circulation, satisfy [0 < m and m < a], then save as [[0, a], m] 704, and wherein last number his-and-hers watches show the subregion groups of nodes, and a back value representation is to threshold value that should groups of nodes; Judge whether [0, a] address is position, end 705, so because of not being the process 702 to 705 of end position address+1 708 cyclings [a, b] and [b, 255]; Through above process, produce three group node groups and corresponding threshold information and be respectively [[0, a], m], [[a, b], n], [[b, 255], k], order sends to greyscale transformation module 105.
Like Fig. 5, accept groups of nodes and corresponding threshold information 509 from 104, instruct judge 502 with inquiry legitimacy 504, do not report an error and the error message process 503 of resetting then be provided if conform to rule, if legal then get into the skew gray-scale value and calculate 505; Like Fig. 8, read groups of nodes and corresponding threshold thereof [[0, a], m] 802, calculate 804,805 and 806 in order to calling according to formula 1 respectively; Read groups of nodes [0 successively since 0; A] interior GTG, because of 0 < m 808, judge that thus current gray level is less than threshold value 809; Through type 2 left side GTG functions 812 calculate the skew gray-scale value and deposit array 814 in; Judge whether [0, a] address reaches position, end 815, do not reach the node region upper limit because of 0 < a; Current GTG+1 of circulating thus; Repeat 807 to 815 process, current gray level reaches the zone to be gone up in limited time, calculates for the skew gray scale of this node region and finishes and import array as a result into next process 817; Generation contain the array that is offset gray scale [[0, a], m, [0 ' ..., a ']] 506.
Like Fig. 2, initialization also generates target image 202 by original image; Acceptance from 105 skew gray scale group [[0, a], m, [0 ' ..., a ']] 209; Instruct the legitimacy of judgement 204 and value to inquire about 205; Like Fig. 9, read the target image 903 of generation, read skew gray scale array [[0, a], m, [0 ' ..., a ']] 902, from [0, a], get gray-scale value 0904, all gray-scale values of search are 0 pixel 905 and the memory address 907 that writes down this pixel in original image; Skew gray scale array [0 ' ..., a '] in get corresponding 0 skew gray scale 0 ' 906; Gray scale according to the relative address point that this address in the target image 909 is corresponding is transformed to 0 ' 908 by 0, judges whether 0 reach a, because of 0 < a; Institute is so that GTG 0 increases by 1, the process of circulation 904 to 910; Judge whether the corresponding skew of each node region gray scale group of target image is all accepted 207, then continues 209 as not accepting, and as all accepting, then the current goal image is saved as new images 208.
The new images that obtains is the result 107 of this debugging.