An image processing method, apparatus, device and medium
By constructing and correcting dissimilar histogram vectors and remapping them, the problems of low signal-to-noise ratio and blurriness in infrared images were solved, achieving enhanced contrast and improved target clarity.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG PIXFRA TECH CO LTD
- Filing Date
- 2023-08-02
- Publication Date
- 2026-05-12
Smart Images

Figure CN117115052B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of network technology and security technology, and in particular to an image processing method, apparatus, device and medium. Background Technology
[0002] In infrared imaging technology, due to the inherent resolution limitations of infrared sensors and the absorption and scattering of infrared light during transmission by the atmosphere, infrared images suffer from drawbacks such as low signal-to-noise ratio and blurred target edges and details. To accurately identify targets, infrared images must undergo enhancement preprocessing. Summary of the Invention
[0003] This application provides an image processing method, apparatus, device, and medium for improving image contrast.
[0004] Firstly, an image processing method is provided, including:
[0005] For each pixel in the original image, a dissimilarity factor is determined based on the pixel value and the pixel values of multiple pixels in the pixel's neighborhood.
[0006] Determine the dissimilarity histogram vector corresponding to the original image; wherein the k-th element of the dissimilarity histogram vector is the sum of the dissimilarity factors of the pixels corresponding to the k-th gray level in the gray value range of the original image, and the gray value range of the original image is 0 to 2. L -1, where k ranges from 0 to 2. L -1, where L is an integer greater than or equal to 8;
[0007] Based on the gray value corresponding to each element in the dissimilar histogram vector and at least one adjustment threshold, the dissimilar histogram vector is divided into at least two sub-dissimilar histogram vectors.
[0008] For each sub-dissimilar histogram vector, the sub-dissimilar histogram vector is corrected based on the dissimilar mean of the sub-dissimilar histogram vector to obtain the corrected sub-dissimilar histogram vector;
[0009] Based on the at least one adjustment threshold, at least two of the modified sub-dissimilar histogram vectors are remapped to obtain the target image.
[0010] In one possible implementation, the sub-dissimilarity histogram vectors are modified based on the dissimilarity mean of the sub-dissimilarity histogram vectors to obtain modified sub-dissimilarity histogram vectors, including:
[0011] Determine the dissimilarity mean of each of the sub-dissimilarity histogram vectors;
[0012] For each sub-dissimilarity histogram vector, the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean are set to the dissimilarity mean, while the values of the elements in the sub-dissimilarity histogram vector that are not greater than the dissimilarity mean remain unchanged, thus obtaining the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector;
[0013] The dissimilarity compensation value of the restricted sub-dissimilarity histogram vector is obtained by averaging the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector using the number of non-zero elements in the sub-dissimilarity histogram vector.
[0014] The value of element A in the restricted sub-dissimilarity histogram vector is kept unchanged, and the value of element B in the restricted sub-dissimilarity histogram vector is set to the sum of the value of element B and the dissimilarity compensation value corresponding to the restricted sub-dissimilarity histogram vector, to obtain the modified sub-dissimilarity histogram vector; wherein, element A is an element that is greater than or equal to the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector, and element B is an element that is less than the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector.
[0015] In one possible implementation, determining the dissimilarity mean of each of the said sub-dissimilarity histogram vectors includes:
[0016] For each of the sub-dissimilarity histogram vectors, the values of the elements in the sub-dissimilarity histogram vector are added together, and then divided by the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity mean of the sub-dissimilarity histogram vector.
[0017] In one possible implementation, based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, the dissimilar histogram vector is divided into two sub-dissimilar histogram vectors, including:
[0018] Keep the value of the first element in the dissimilar histogram vector unchanged, and set the value of the second element in the dissimilar histogram vector to 0 to obtain a sub-dissimilar histogram vector;
[0019] Set the value of the first element in the dissimilar histogram vector to 0, and keep the value of the second element in the dissimilar histogram vector unchanged to obtain another sub-dissimilar histogram vector;
[0020] Wherein, the first element is the element in the dissimilar histogram vector that corresponds to a gray value less than or equal to the adjustment threshold, and the second element is the element in the dissimilar histogram vector that corresponds to a gray value greater than or equal to the adjustment threshold.
[0021] In one possible implementation, the dissimilarity compensation value for the restricted sub-dissimilarity histogram vector is obtained by averaging the values of elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector, using the number of non-zero elements in the sub-dissimilarity histogram vector, including:
[0022] For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; average the sum of multiple differences using the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector; or;
[0023] For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; determine the sum S1 of the differences between multiple elements 1 and the corresponding sub-dissimilarity histogram mean in multiple sub-dissimilarity histogram vectors; average the sum S1 using the sum S2 of the number of non-zero elements in multiple sub-dissimilarity histogram vectors to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to each sub-dissimilarity histogram vector.
[0024] In one possible implementation, before dividing the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, the method further includes:
[0025] The average gray value Tm1 of the pixel is determined based on the sum of the gray values of the pixels in the original image and the number of pixels in the original image.
[0026] Based on the dissimilarity histogram vectors corresponding to the original image, the average gray value Tm2 of the dissimilarity factor is determined.
[0027] The adjustment threshold Tm is determined based on the average gray value Tm1 of the pixel and the average gray value Tm2 of the similarity factor.
[0028] In one possible implementation, the average gray value Tm2 of the dissimilarity factor is determined based on the dissimilarity histogram vector corresponding to the original image, including:
[0029] Determine the product of the gray value of each pixel in the original image and the dissimilarity factor of that pixel;
[0030] Add the products corresponding to all pixels;
[0031] The average gray value Tm2 of the dissimilarity factors is obtained by averaging the sum of the dissimilarity factors of the original images and the products of the products.
[0032] In one possible implementation, based on the at least one adjustment threshold, at least two of the modified sub-dissimilarity histogram vectors are remapped to obtain the target image, including:
[0033] Determine the probability density function vector corresponding to each modified sub-histogram vector;
[0034] Based on the probability density function vector corresponding to each modified sub-histogram vector, determine the cumulative distribution function vector corresponding to the modified sub-histogram vector;
[0035] Based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, determine the mapping function vector from the grayscale range of the original image to the preset grayscale range;
[0036] The target image is determined based on the mapping function vector.
[0037] In one possible implementation, a mapping function vector from the grayscale range of the original image to a preset grayscale range is determined based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, including:
[0038] Using the following formula:
[0039] F(i) = tmpmin + Tm * CDF L (i), where 1≤i≤Tm;
[0040] F(i)=Tm+1+[(tmpmax-tmpmin)-(Tm+1)]*CDF R (i), where Tm+1
[0041] ≤i≤2 L -1;
[0042] Determine the value F(i) of the i-th element in the mapping function vector F, where tmpmin ≤ tmpmax, 0 < tmpmin < 2. L-1 0 < tmpmax < 2 L-1 Tm represents the adjustment threshold, CDF L (i) represents the value of the i-th element in a cumulative distribution function vector, CDF R (i) represents the value of the i-th element in another cumulative distribution function vector.
[0043] Secondly, an image processing apparatus is provided, comprising:
[0044] The dissimilarity histogram module is used to determine the dissimilarity factor of each pixel in the original image based on the pixel value and the pixel values of multiple neighboring pixels; and to determine the dissimilarity histogram vector corresponding to the original image; wherein the k-th element of the dissimilarity histogram vector is the sum of the dissimilarity factors of the pixels corresponding to the k-th gray level in the gray value range of the original image, where the gray value range of the original image is 0 to 2. L -1, where k ranges from 0 to 2. L -1, where L is an integer greater than or equal to 8;
[0045] The correction module is used to divide the dissimilar histogram vector into at least two sub-dissimilar histogram vectors based on the gray value corresponding to each element in the dissimilar histogram vector and at least one adjustment threshold; for each sub-dissimilar histogram vector, the sub-dissimilar histogram vector is corrected based on the dissimilarity mean of the sub-dissimilar histogram vector to obtain a corrected sub-dissimilar histogram vector.
[0046] The remapping module is used to remap at least two of the modified sub-dissimilar histogram vectors based on the at least one adjustment threshold to obtain the target image.
[0047] In one possible implementation, the correction module, when used to correct the sub-dissimilarity histogram vector based on the dissimilarity mean of the sub-dissimilarity histogram vector to obtain a corrected sub-dissimilarity histogram vector, is specifically used for:
[0048] Determine the dissimilarity mean of each of the sub-dissimilarity histogram vectors;
[0049] For each sub-dissimilarity histogram vector, the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean are set to the dissimilarity mean, while the values of the elements in the sub-dissimilarity histogram vector that are not greater than the dissimilarity mean remain unchanged, thus obtaining the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector;
[0050] The dissimilarity compensation value of the restricted sub-dissimilarity histogram vector is obtained by averaging the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector using the number of non-zero elements in the sub-dissimilarity histogram vector.
[0051] The value of element A in the restricted sub-dissimilarity histogram vector is kept unchanged, and the value of element B in the restricted sub-dissimilarity histogram vector is set to the sum of the value of element B and the dissimilarity compensation value corresponding to the restricted sub-dissimilarity histogram vector, to obtain the modified sub-dissimilarity histogram vector; wherein, element A is an element that is greater than or equal to the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector, and element B is an element that is less than the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector.
[0052] In one possible implementation, the correction module, when determining the dissimilarity mean of each of the sub-dissimilarity histogram vectors, is specifically used for:
[0053] For each of the sub-dissimilarity histogram vectors, the values of the elements in the sub-dissimilarity histogram vector are added together, and then divided by the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity mean of the sub-dissimilarity histogram vector.
[0054] In one possible implementation, the correction module, when used to divide the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, is specifically used for:
[0055] Keep the value of the first element in the dissimilar histogram vector unchanged, and set the value of the second element in the dissimilar histogram vector to 0 to obtain a sub-dissimilar histogram vector;
[0056] Set the value of the first element in the dissimilar histogram vector to 0, and keep the value of the second element in the dissimilar histogram vector unchanged to obtain another sub-dissimilar histogram vector;
[0057] Wherein, the first element is the element in the dissimilar histogram vector that corresponds to a gray value less than or equal to the adjustment threshold, and the second element is the element in the dissimilar histogram vector that corresponds to a gray value greater than or equal to the adjustment threshold.
[0058] In one possible implementation, the correction module, when averaging the values of elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector using the number of non-zero elements in the sub-dissimilarity histogram vector, to obtain the dissimilarity compensation value for limiting the sub-dissimilarity histogram vector, is specifically used for:
[0059] For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; average the sum of multiple differences using the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector; or;
[0060] For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; determine the sum S1 of the differences between multiple elements 1 and the corresponding sub-dissimilarity histogram mean in multiple sub-dissimilarity histogram vectors; average the sum S1 using the sum S2 of the number of non-zero elements in multiple sub-dissimilarity histogram vectors to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to each sub-dissimilarity histogram vector.
[0061] In one possible implementation, the correction module, before dividing the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, is further configured to:
[0062] The average gray value Tm1 of the pixel is determined based on the sum of the gray values of the pixels in the original image and the number of pixels in the original image.
[0063] Based on the dissimilarity histogram vectors corresponding to the original image, the average gray value Tm2 of the dissimilarity factor is determined.
[0064] The adjustment threshold Tm is determined based on the average gray value Tm1 of the pixel and the average gray value Tm2 of the similarity factor.
[0065] In one possible implementation, the correction module, when determining the average gray value Tm2 of the dissimilarity factor based on the dissimilarity histogram vector corresponding to the original image, is specifically used for:
[0066] Determine the product of the gray value of each pixel in the original image and the dissimilarity factor of that pixel;
[0067] Add the products corresponding to all pixels;
[0068] The average gray value Tm2 of the dissimilarity factors is obtained by averaging the sum of the dissimilarity factors of the original images and the products of the products.
[0069] In one possible implementation, the remapping module, when used to remap at least two of the modified sub-dissimilarity histogram vectors based on the at least one adjustment threshold to obtain the target image, is specifically used for:
[0070] Determine the probability density function vector corresponding to each modified sub-histogram vector;
[0071] Based on the probability density function vector corresponding to each modified sub-histogram vector, determine the cumulative distribution function vector corresponding to the modified sub-histogram vector;
[0072] Based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, determine the mapping function vector from the grayscale range of the original image to the preset grayscale range;
[0073] The target image is determined based on the mapping function vector.
[0074] In one possible implementation, the remapping module, when determining the mapping function vector from the grayscale range of the original image to a preset grayscale range based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, is specifically used for:
[0075] Using the following formula:
[0076] F(i) = tmpmin + Tm * CDF L (i), where 1≤i≤Tm;
[0077] F(i)=Tm+1+[(tmpmax-tmpmin)-(Tm+1)]*CDF R (i), where Tm+1
[0078] ≤i≤2 L -1;
[0079] Determine the value F(i) of the i-th element in the mapping function vector F, where tmpmin ≤ tmpmax, 0 < tmpmin < 2. L-1 0 < tmpmax < 2 L-1 Tm represents the adjustment threshold, CDF L (i) represents the value of the i-th element in a cumulative distribution function vector, CDF R (i) represents the value of the i-th element in another cumulative distribution function vector.
[0080] Thirdly, this application provides an electronic device, including: a processor, optionally further including a memory; the processor and the memory are coupled; the memory is used to store computer programs or instructions; the processor is used to execute part or all of the computer programs or instructions in the memory, and when the part or all of the computer programs or instructions are executed, it is used to implement the function in any of the above methods.
[0081] In one possible implementation, the apparatus may further include a transceiver for transmitting signals processed by the processor or receiving signals input to the processor. The transceiver may perform either the transmitting or receiving action of any of the methods.
[0082] Fourthly, a computer-readable storage medium is provided for storing a computer program, the computer program including instructions for implementing any of the functions.
[0083] Alternatively, a computer-readable storage medium for storing a computer program, which, when executed by a computer, causes the computer to perform any of the methods described above.
[0084] Fifthly, a computer program product is provided, the computer program product comprising: computer program code, which, when run on a computer, causes the computer to perform any of the methods described above.
[0085] In this embodiment, the dissimilar histogram is divided into a first sub-dissimilar histogram and a second sub-dissimilar histogram by adjusting the threshold. Then, the first sub-dissimilar histogram and the second sub-dissimilar histogram are adaptively redistributed to obtain a corrected histogram. The range of the corrected histogram is then remapped according to the adjusted threshold to obtain a contrast-enhanced visualization image. Attached Figure Description
[0086] To more clearly illustrate the implementation methods in the embodiments of this application or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings.
[0087] Figure 1 This illustration shows a schematic diagram of an image processing flow provided in an embodiment of this application;
[0088] Figure 2 This illustration shows a schematic diagram of an image processing flow provided in an embodiment of this application;
[0089] Figure 3This invention provides a structural diagram of an image processing apparatus according to an embodiment of the present application.
[0090] Figure 4 A structural diagram of an electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0091] To make the objectives and implementation methods of this application clearer, exemplary embodiments of this application will be clearly and completely described below with reference to the accompanying drawings of the exemplary embodiments. Obviously, the described exemplary embodiments are only a part of the embodiments of this application, and not all of the embodiments. The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms can be used interchangeably where appropriate.
[0092] It should be noted that the embodiments of this application are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0093] Figure 1 This illustration shows a flowchart of an image processing method provided in an embodiment of this application. The process includes the following steps:
[0094] Step 100: Obtain the original image Img.
[0095] Step 101: Determine the grayscale histogram vector H corresponding to the original image. Step 101 is optional.
[0096] Step 102: Determine the dissimilarity histogram vector Hfactor corresponding to the original image.
[0097] Step 103: Determine the adjustment threshold based on the gray-level histogram H and the dissimilar histogram vector Hfactor corresponding to the original image.
[0098] Step 104: Correct the dissimilar histogram vector HFactor based on the adjustment threshold.
[0099] Step 105: Determine the mapping function vector.
[0100] Step 106: Determine the contrast-enhanced image based on the mapping function vector.
[0101] The following is a description of step 101:
[0102] 1a: The k-th gray value r in the gray value range corresponding to the original image k Count the number of pixels H(r) at the k-th gray level in the original image. k If the k-th gray level does not appear, the quantity is 0. k ranges from 0 to 2. L -1, where L is an integer greater than or equal to 8, for example, L is an integer greater than or equal to 8 and less than or equal to 16.
[0103] 1b: The number of pixels H(r) appearing at the k-th gray level in the grayscale range. k The value of the k-th element in the grayscale histogram vector H corresponding to the original image is determined.
[0104] Generally, bad pixels account for a small percentage of the overall image grayscale and are located at the two ends of the histogram. Bad pixels can be filtered out by truncating the left and right endpoints of the grayscale histogram. One possible example is to preset the grayscale value range [minVal, maxVal], filtering out pixels with grayscale levels less than minVal and greater than maxVal in the original image. Another possible example is to preset the number of pixels to be filtered on each side (e.g., 60, 30, etc.), filtering out a subset of pixels with smaller grayscale levels and a subset of pixels with larger grayscale levels in the original image, leaving pixels with grayscale values in the range [minVal, maxVal].
[0105] Step 102: Determine the dissimilarity histogram vector Hfactor corresponding to the original image.
[0106] The following describes step 102:
[0107] 2a: For each pixel in the original image (e.g., coordinates (x, y)), determine the dissimilarity factor factor(x, y) of the pixel based on the pixel value of the pixel and multiple pixels in the neighborhood of the pixel.
[0108] The dissimilarity factor factor(x, y) represents the dissimilarity factor of the pixel at coordinates (x, y) in the original image; where 1 ≤ x ≤ M and 1 ≤ y ≤ N.
[0109] The neighborhood of a certain pixel (x, y) is an n*n window region centered on the pixel (x, y), where n is an odd number greater than or equal to 3.
[0110] The smaller the difference in pixel values between two pixels, the more similar the two pixels are, and the lower the contrast between the two pixels.
[0111] One way to determine the dissimilarity factor is: factor = func_grad(Img);
[0112] The func_grad() function can use the Sobel operator, Roberts operator, Prewitt operator, or Laplace operator, etc. The func_grad() function can calculate the gradient magnitude of the center pixel in an n×n neighborhood window.
[0113] factor represents the dissimilarity factor matrix corresponding to the original image. The size of the factor matrix is M*N. The value of the element at (x, y) in the factor matrix is the dissimilarity factor factor(x, y) of the pixel at coordinate (x, y) in the original image.
[0114] Another way to determine the dissimilarity factor is:
[0115] factor = func_mean(diff n×n (diff n×n >TH)=TH) / TH
[0116] The function `func_mean()` is the matrix mean function, and `diff` is the matrix mean function. n×n The diff matrix represents the absolute value of the grayscale difference between the center pixel in an n×n window and every pixel in the n×n window. n×n The size is n*n; TH is a pre-configured threshold, for example, TH is the variance or standard deviation of the grayscale values of the original image. (diff) n×n >TH) = TH, indicating that the diff will be... n×n Pixel values in the region that are greater than TH are set to TH, while pixel values that are less than or equal to TH remain unchanged.
[0117] 2b: For the k-th gray level in the gray value range corresponding to the original image, determine the sum of dissimilarity factors Hfactor(d) of the pixels appearing at the k-th gray level in the original image. k ).
[0118] It is understandable that if the kth gray level does not appear, then the sum of the dissimilarity factors corresponding to the kth gray level is 0.
[0119] For example, the original image contains 4*4 pixels, with 16 pixels corresponding to dissimilarity factors f1 to f16. The grayscale values of these 16 pixels range from 0 to 7, containing a total of 8 grayscale values. The specific grayscale values of these 16 pixels are 0, 0, 2, 4, 6, 7, 4, 6, 7, 2, 4, 1, 2, 4, 6, and 7. Pixels with grayscale values 3 and 5 are not included in the original image. The pixel appearing at the 0th grayscale level (i.e., grayscale value 0) is the 1st and 2nd pixel, so the sum of the dissimilarity factors corresponding to the 1st grayscale value is f1 + f2. The pixel appearing at the 1st grayscale level (i.e., grayscale value 1) is the 12th pixel, so the sum of the dissimilarity factors corresponding to the 1st grayscale level is f12. The sum of the dissimilarity factors corresponding to the 3rd grayscale level (i.e., grayscale value 3) is 0.
[0120] It should be noted that the grayscale value range corresponding to the original image can be the grayscale value range [0, 2] of the unfiltered bad pixels. L-1 [], or it can be the range of gray values after filtering out bad pixels [minVal, maxVal]. Here, the gray value range used when determining the dissimilar histogram vector will be the same gray value range used in subsequent processes related to the dissimilar histogram vector.
[0121] 2c: The sum of the dissimilarity factors of the pixels corresponding to the kth gray level in the gray value range is used as the value of the kth element in the dissimilarity histogram vector Hfactor of the original image. k ), that is, Hfactor(r) k ) represents the sum of dissimilarity factors corresponding to the k-th gray level.
[0122] Step 103: Determine the adjustment threshold Tm based on the gray-level histogram vector H and the dissimilar histogram vector Hfantor corresponding to the original image.
[0123] The following describes step 103:
[0124] 3a: Determine the average gray value Tm1 of each pixel based on the sum of the gray values of the M*N pixels in the original image and the number of pixels M*N in the original image. Specifically, the average gray value Tm1 of the pixel is determined by dividing the sum of the gray values of the M*N pixels in the original image by the number of pixels M*N in the original image.
[0125] For example, if the original image contains 4*4 pixels and the gray values of the 16 pixels are 0, 0, 2, 4, 6, 7, 4, 6, 7, 2, 4, 1, 2, 4, 6, 7, then Tm1 = (0+0+2+4+6+7+4+6+7+2+4+1+2+4+6+7) / 16.
[0126] In one specific example, the average gray value Tm1 of a pixel is determined based on the gray-level histogram vector H corresponding to the original image.
[0127] Specifically, based on the following formula, Determine the average gray value Tm1 of the pixel. Where r k H(r) represents the k-th gray level in the gray value range of the original image. k This represents the number of pixels appearing at the k-th gray level, where k ranges from 0 to 2. L -1, The value can also represent the number of pixels included in the original image.
[0128] 3b: Determine the average gray value Tm2 of the dissimilarity factor based on the dissimilarity histogram vector Hfactor corresponding to the original image.
[0129] For example, first determine the product of the gray value of each of the M*N pixels in the original image and the dissimilarity factor of the pixel; then add the products of the M*N pixels; then, use the sum of the dissimilarity factors of the original image to average the sum of the products to obtain the average gray value Tm2 of the dissimilarity factors.
[0130] For example, the original image contains 4*4 pixels, and the gray values of the 16 pixels are 0, 0, 2, 4, 6, 7, 4, 6, 7, 2, 4, 1, 2, 4, 6, 7. The dissimilarity factors corresponding to the 16 pixels are F1 to F16, and Tm2 = [0*(F1+F2)+1*F12+2*(F3+F10+F13)+3*0+4*(F4+F7+F11+F14)+5*0+6*(F5+F8+F15)+7*(F6+F9+F16)] / (F1+……+F16).
[0131] In a specific example, based on the following formula, Determine the average gray value Tm2 of the dissimilarity factor; where r k Hfactor(r) represents the k-th gray level in the gray value range of the original image. k () represents the sum of dissimilarity factors corresponding to the k-th gray level, where k ranges from 0 to 2. L -1, The value represents the sum of the dissimilarity factors of the original images.
[0132] 3c: Determine the adjustment threshold Tm based on Tm1 and Tm2.
[0133] For example, by setting weights for Tm1 and Tm2 and weighting them together, the adjustment threshold Tm can be obtained.
[0134] In a specific example, Tm = α*Tm1 + (1-α)*Tm2, where α∈[0,1].
[0135] In other alternative examples, the adjustment threshold Tm is a preset value and does not need to be determined based on Tm1 and Tm2; or the adjustment threshold Tm is determined based on Tm1, for example, Tm1 is determined as the adjustment threshold Tm; or the adjustment threshold Tm is determined based on Tm2, for example, Tm2 is determined as the adjustment threshold Tm.
[0136] In other optional examples, there are multiple adjustment thresholds. For example, two adjustment thresholds are determined, namely Tm1 and Tm2. As another example, three adjustment thresholds are determined, namely Tm1, Tm2, and the mean of Tm1 and Tm2; optionally, the mean of Tm1 and Tm2 can also be replaced by a weighted value Tm of Tm1 and Tm2.
[0137] Step 104: Correct the dissimilar histogram vector Hfactor based on the adjustment threshold.
[0138] The process of step 104 is described below:
[0139] 4a: Based on the gray value corresponding to each element in the dissimilar histogram vector Hfactor and at least one adjustment threshold, the dissimilar histogram vector is divided into at least two sub-dissimilar histogram vectors.
[0140] This paper takes dividing the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector Hfactor and an adjustment threshold as an example. Specifically, the value of the first element in the dissimilar histogram vector Hfactor remains unchanged, while the value of the second element in the dissimilar histogram vector Hfactor is set to 0, resulting in a sub-dissimilar histogram vector, hereinafter referred to as the first sub-dissimilar histogram vector Hfactor. L Set the first element of the dissimilar histogram vector Hfactor to 0, and keep the second element unchanged to obtain another sub-dissimilar histogram vector, which will be referred to as the second sub-dissimilar histogram vector Hfactor. R .
[0141] The first element is the element in the dissimilar histogram vector Hfactor whose gray value is less than or equal to the adjustment threshold, and the second element is the element in the dissimilar histogram vector whose Hfactor is greater than or equal to the adjustment threshold. It is understood that an element whose gray value corresponds to the adjustment threshold can be classified as either the first element or the second element, but cannot be both.
[0142] One adjustment threshold can divide a dissimilar histogram vector into two sub-dissimilar histogram vectors. Two adjustment thresholds can divide it into three classes of elements. By keeping the value of one class of elements unchanged each time and setting the values of the other two classes of elements to 0, the dissimilar histogram vector can be divided into three sub-dissimilar histogram vectors. Three adjustment thresholds can divide the dissimilar histogram vector into four sub-dissimilar histogram vectors, and so on. The principle of segmentation is similar and will not be described in detail here.
[0143] Next, for each sub-dissimilar histogram vector, the sub-dissimilar histogram vector is corrected based on the dissimilarity mean of the sub-dissimilar histogram vector to obtain the corrected sub-dissimilar histogram vector, as detailed in 4b to 4e.
[0144] 4b: Determine the dissimilarity mean PL for each sub-dissimilarity histogram vector.
[0145] In one example, the values of the elements in the sub-dissimilarity histogram vector are summed and then divided by the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity mean PL of the sub-dissimilarity histogram vector.
[0146] Let Hfactor be the first sub-dissimilar histogram vector. L The dissimilarity mean PL is the first dissimilarity mean PL L The second sub-dissimilar histogram vector Hfactor R The dissimilarity mean PL is the second dissimilarity mean PL R .
[0147] The number of non-zero elements in the first sub-dissimilar histogram vector is the number of the first element, and the number of non-zero elements in the second sub-dissimilar histogram vector is the number of the second element.
[0148] In another example, the sum of the values of the elements in the dissimilar histogram vector Hfactor is divided by the number of elements in the dissimilar histogram vector Hfactor, and the quotient is used as the dissimilarity mean of each sub-dissimilar histogram vector.
[0149] 4c: For each sub-dissimilarity histogram vector, set the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean to the dissimilarity mean, and keep the values of the elements in the sub-dissimilarity histogram vector that are not greater than the dissimilarity mean unchanged, to obtain the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector.
[0150] That is, based on the dissimilarity mean of the sub-dissimilarity histogram vectors, the portion of the sub-dissimilarity histogram vectors that is greater than the dissimilarity mean is clipped.
[0151] In a specific example, using the following formula: Determine the first sub-dissimilar histogram vector Hfcator L The corresponding first restricted sub-dissimilarity histogram vector H′ L The value H′ of the i-th element L (i).
[0152] Among them, PL L Hfactor represents the first sub-dissimilar histogram vector. L Dissimilarity means, Hfcator L Hfcator represents the first sub-dissimilar histogram vector. L (i) represents the i-th element in the first sub-dissimilar histogram vector.
[0153] In a specific example, using the following formula: Determine the second sub-dissimilar histogram vector Hfcator R The corresponding second restricted sub-dissimilarity histogram H′ R The value H′ of the i-th element R (i).
[0154] Among them, PL R Hfactor represents the second sub-dissimilar histogram vector. R Dissimilarity means, Hfcator R Hfcator represents the second sub-dissimilar histogram vector. R (i) represents the i-th element in the second sub-dissimilar histogram vector.
[0155] 4d: Using the number of non-zero elements in the sub-dissimilarity histogram vector, the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector are averaged to obtain the dissimilarity compensation value that restricts the sub-dissimilarity histogram vector.
[0156] In one example, for each sub-dissimilarity histogram vector, elements with values greater than the dissimilarity mean of the sub-dissimilarity histogram vector (e.g., element 1) are selected; the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector is determined; the sum of multiple differences is averaged using the number of non-zero elements in the sub-dissimilarity histogram vector (that is, the sum of the differences between multiple elements 1 and the dissimilarity mean is divided by the number of non-zero elements in the sub-dissimilarity histogram vector) to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector.
[0157] For example, for the first sub-dissimilar histogram vector Hfcator L Elements whose values are greater than the first dissimilarity mean of the first sub-dissimilarity histogram vector are selected. The sum of the selected elements is then averaged using the number of non-zero elements in the first sub-dissimilarity histogram to obtain the first sub-dissimilarity histogram vector Hfcator. L The corresponding first restricted sub-dissimilarity histogram vector H′ L The first dissimilarity compensation value R PL .
[0158] For example, for the second sub-dissimilar histogram vector Hfcator R Elements whose values are greater than the second dissimilarity mean of the second sub-dissimilarity histogram vector are selected. The sum of the selected elements is then averaged using the number of non-zero elements in the second sub-dissimilarity histogram to obtain the second sub-dissimilarity histogram vector Hfcator. R The corresponding second restricted sub-dissimilarity histogram vector H′ R The second dissimilarity compensation value R PR .
[0159] For example, based on the following formula: Determine the first dissimilarity compensation value R PL , where Num L minVal represents the number of non-zero elements in the first sub-dissimilar histogram vector. If bad pixels are not filtered out, minVal is replaced with 0.
[0160] For example, based on the following formula: Determine the second dissimilarity compensation value R PR , where Num R MaxVal is the number of non-zero elements in the second sub-dissimilarity histogram vector. If bad pixels are not filtered out, MaxVal is replaced with 2. L -1.
[0161] In another example, for each sub-dissimilarity histogram vector, element 1 with a value greater than the dissimilarity mean of the sub-dissimilarity histogram vector is selected; the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector is determined. The sum S1 of the differences between multiple elements 1 and their corresponding sub-dissimilarity histogram mean in multiple sub-dissimilarity histogram vectors is determined, and the sum S1 is averaged (i.e., S1 / S2) using the sum S2 of the number of non-zero elements in multiple sub-dissimilarity histogram vectors to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to each sub-dissimilarity histogram vector.
[0162] If bad pixels are not filtered out, then minVal is replaced with 0 and maxVal is replaced with 2. L -1.
[0163] For example, through the following formula,
[0164] Determine the dissimilarity compensation value R for the restricted sub-dissimilarity histogram vector corresponding to each sub-dissimilarity histogram vector.
[0165] Where, H′(min Val:Tm)=H L ′, H′(Tm+1, max Val)=H R ′, Num is the number of non-zero elements in dissimilar histograms.
[0166] 4e: Keep the value of element A in the restricted sub-dissimilarity histogram vector unchanged, and set the value of element B in the restricted sub-dissimilarity histogram vector to the sum of the value of element B and the dissimilarity compensation value corresponding to the restricted sub-dissimilarity histogram vector, to obtain the modified sub-dissimilarity histogram vector. Here, element A is an element greater than or equal to the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector, and element B is an element less than the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector.
[0167] For example, the first restricted sub-dissimilarity histogram vector H′ L The mean of the first dissimilarity PL is greater than or equal to the mean of the second dissimilarity. L The values of the elements remain unchanged, and the first restricted sub-dissimilarity histogram vector H′ is kept constant. L The mean PL of the first dissimilarity is less than that of the middle. L The value of the element is set to the value of the element and the first dissimilarity compensation value (R). PL The sum of (or R) yields the first modifier dissimilarity histogram vector H. RL .
[0168] For example, the second restricted sub-dissimilarity histogram vector H′ R The mean of the second dissimilarity is greater than or equal to the mean PL. RThe values of the elements remain unchanged, and the second restricted sub-dissimilarity histogram vector H′ is kept constant. R The mean PL of the first dissimilarity is less than that of the middle. R The value of the element is set to the second dissimilarity compensation value (R) between the value of the element and the value of the element. PR The sum of (or R) yields the second modifier dissimilarity histogram vector H. RR .
[0169] For example, through the following formula, Determine the first sub-corrected dissimilar histogram vector H RL The value H of the i-th element RL (i).
[0170] For example, through the following formula, Determine the second sub-corrected dissimilarity histogram vector H RR The value H of the i-th element RR (i).
[0171] For example, using the following formula, Determine the first sub-corrected dissimilarity histogram vector H RL The value H of the i-th element RL (i).
[0172] For example, using the following formula, Determine the second sub-corrected dissimilarity histogram vector H RR The value H of the i-th element RR (i).
[0173] Step 105: Determine the mapping function vector based on the first sub-dissimilarity histogram vector, the second sub-dissimilarity histogram vector, and the adjustment threshold.
[0174] The following describes the process of step 105:
[0175] 5a: Determine the probability density function vector PDF corresponding to each modified sub-histogram vector.
[0176] Specifically, for each modified sub-histogram vector, the following operations are performed: the value of the i-th element in the modified sub-histogram vector is divided by the sum of the values of all elements in the modified sub-histogram vector (which is actually the sum of the values of non-zero elements) to obtain the probability density of the i-th element; the probability density of the i-th element is used as the value of the i-th element in the probability density function vector corresponding to the modified sub-histogram vector.
[0177] In a specific example, for the first modified sub-histogram vector H RL The i-th element in the array, with the value H of the i-th element. RL(i) Divide by the sum of the values of all elements in the first modified sub-histogram vector (which is actually the sum of the values of the non-zero elements) to obtain the probability density PDF of the i-th element. L (i); The probability density of the i-th element is used as the first probability density function vector PDF corresponding to the first modified sub-histogram vector. L The value of the i-th element in the array.
[0178] For example, through the following formula:
[0179] Determine the first probability density function vector PDF L The value of the i-th element in the array.
[0180] In a specific example, for the second modified sub-histogram vector H RR The i-th element in the array, with the value H of the i-th element. RR (i) Divide by the sum of the values of all elements in the second modified sub-histogram vector (which is actually the sum of the values of the non-zero elements) to obtain the probability density PDF of the i-th element. R (i); The probability density of the i-th element is used as the second probability density function vector PDF corresponding to the second modified sub-histogram vector. R The value of the i-th element in the array.
[0181] For example, through the following formula:
[0182] Determine the second probability density function vector PDF R The value of the i-th element in the array.
[0183] 5b: Determine the cumulative distribution function vector (CDF) corresponding to each modified sub-histogram vector based on the probability density function vector (PDF) corresponding to each modified sub-histogram vector.
[0184] For any modified sub-histogram vector corresponding to the probability density function vector, perform the following process: sum the probability density function to the i-th element in the PDF quantity and all elements before the i-th element, and determine the sum as the value of the i-th element in the cumulative distribution function vector corresponding to the modified sub-histogram vector.
[0185] For example, for the first probability density function vector corresponding to the first modified sub-histogram vector, the following process is performed: PDF the first probability density function vector. L Summing the i-th element and all elements preceding the i-th element, the sum is determined as the first cumulative distribution function vector (CDF) corresponding to the first modified sub-histogram vector. LThe value of the i-th element in CDF L (i).
[0186] For example, for the second probability density function vector corresponding to the second modified sub-histogram vector, the following process is performed: PDF the second probability density function vector. R Summing the i-th element and all elements preceding the i-th element, the sum is determined as the second cumulative distribution function vector (CDF) corresponding to the second modified sub-histogram vector. R The value of the i-th element in CDF R (i).
[0187] For example, through the following formula: Determine the first cumulative distribution function vector CDF L The value of the i-th element in CDF L (i)
[0188] For example, through the following formula: Determine the second cumulative distribution function vector CDF R The value of the i-th element in CDF R (i)
[0189] The maximum value in the cumulative distribution function vector is 1, i.e., CDF. L The maximum value of (i) is 1. CDF R The maximum value of (i) is 1.
[0190] 5c: Based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the adjustment threshold, determine the mapping function vector from the grayscale range of the original image to the preset grayscale range.
[0191] F(i) = tmpmin + Tm * CDF L (i), where 1≤i≤Tm. As i increases, CDF L (i) also increases, with a maximum value of 1. This formula maps the grayscale value range from 1 to Tm to tmpmin to tmpmin+TM.
[0192] F(i)=Tm+1+[(tmpmax-tmpmin)-(Tm+1)]*CDF R (i), where Tm+1≤i≤2 L -1. As i increases, CDF R (i) also increases, with a maximum value of 1. This formula ranges the grayscale value from Tm+1 to 2. L -1 is mapped to Tm+1 to tmpmax.
[0193] Where F(i) represents the value of the i-th element in the mapping function vector F, tmpmin is the minimum mapping value, tmpmax is the maximum mapping value, tmpmin ≤ tmpmax, and 0 < tmpmin < 2. L-1 0 < tmpmax < 2 L-1 .
[0194] By mapping grayscale values as described above, the contrast of an image can be improved.
[0195] Step 106: Determine the contrast-enhanced image based on the mapping function vector from the grayscale range of the original image to the preset grayscale range.
[0196] Based on the mapping function vector, traverse each pixel in the original image Img and calculate the gray value of the corresponding pixel in the contrast-enhanced image Imgout.
[0197] For example, using the following formula: Imgout(x,y)=F(Img(x,y)+1) / 2 L-8 Determine the gray value of the pixel with coordinates (x, y) in the contrast-enhanced image Imgout.
[0198] Where Img(x, y) is the gray value of the original image Img at coordinates (x, y).
[0199] In this application, a grayscale histogram and a dissimilar histogram are calculated separately. An adjustment threshold is calculated based on the weighted average of the grayscale and dissimilar histograms. The dissimilar histogram is divided into a first sub-dissimilar histogram and a second sub-dissimilar histogram by using the range after the abscissa of the grayscale histogram and the adjustment threshold. Then, the first and second sub-dissimilar histograms are adaptively redistributed to obtain a corrected histogram. Finally, the range of the corrected histogram is remapped according to the adjustment threshold to obtain a contrast-enhanced visualization image.
[0200] Based on the description above, Figure 2 The diagram provided illustrates another image processing flow according to an embodiment of this application, including the following steps:
[0201] Step 201: For each pixel in the original image, determine the dissimilarity factor of the pixel based on the pixel value and the pixel values of multiple pixels in the neighborhood of the pixel.
[0202] Step 202: Determine the dissimilarity histogram vector corresponding to the original image; wherein, the value of the k-th element in the dissimilarity histogram vector is the sum of the dissimilarity factors of the pixels corresponding to the k-th gray level in the gray value range of the original image, and the gray value range of the original image is 0 to 2. L-1, where k ranges from 0 to 2. L -1;
[0203] Step 203: Based on the gray value corresponding to each element in the dissimilar histogram vector and at least one adjustment threshold, divide the dissimilar histogram vector into at least two sub-dissimilar histogram vectors;
[0204] Step 204: For each sub-dissimilar histogram vector, based on the dissimilarity mean of the sub-dissimilar histogram vector, the sub-dissimilar histogram vector is corrected to obtain the corrected sub-dissimilar histogram vector;
[0205] Step 205: Based on the at least one adjustment threshold, remap at least two of the modified sub-dissimilar histogram vectors to obtain the target image.
[0206] The process of the above steps has been described in detail above, and will not be repeated here.
[0207] Based on the same technical concept, this application also provides an image processing apparatus. Figure 3 A schematic diagram of an image processing device is shown, including:
[0208] The dissimilarity histogram module 31 is used to determine the dissimilarity factor of each pixel in the original image based on the pixel value and the pixel values of multiple pixels in the pixel's neighborhood; and to determine the dissimilarity histogram vector corresponding to the original image; wherein the value of the k-th element in the dissimilarity histogram vector is the sum of the dissimilarity factors of the pixels corresponding to the k-th gray level in the gray value range of the original image, and the gray value range of the original image is 0 to 2. L -1, where k ranges from 0 to 2. L -1;
[0209] The correction module 32 is used to divide the dissimilar histogram vector into at least two sub-dissimilar histogram vectors based on the gray value corresponding to each element in the dissimilar histogram vector and at least one adjustment threshold; and for each sub-dissimilar histogram vector, to correct the sub-dissimilar histogram vector based on the dissimilarity mean of the sub-dissimilar histogram vector to obtain a corrected sub-dissimilar histogram vector.
[0210] The remapping module 33 is used to remap at least two of the modified sub-dissimilar histogram vectors based on the at least one adjustment threshold to obtain the target image.
[0211] In one possible implementation, the correction module 32, when used to correct the sub-dissimilarity histogram vector based on the dissimilarity mean of the sub-dissimilarity histogram vector to obtain a corrected sub-dissimilarity histogram vector, is specifically used for:
[0212] Determine the dissimilarity mean of each of the sub-dissimilarity histogram vectors;
[0213] For each sub-dissimilarity histogram vector, the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean are set to the dissimilarity mean, while the values of the elements in the sub-dissimilarity histogram vector that are not greater than the dissimilarity mean remain unchanged, thus obtaining the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector;
[0214] The dissimilarity compensation value of the restricted sub-dissimilarity histogram vector is obtained by averaging the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector using the number of non-zero elements in the sub-dissimilarity histogram vector.
[0215] The value of element A in the restricted sub-dissimilarity histogram vector is kept unchanged, and the value of element B in the restricted sub-dissimilarity histogram vector is set to the sum of the value of element B and the dissimilarity compensation value corresponding to the restricted sub-dissimilarity histogram vector, to obtain the modified sub-dissimilarity histogram vector; wherein, element A is an element that is greater than or equal to the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector, and element B is an element that is less than the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector.
[0216] In one possible implementation, the correction module 32, when determining the dissimilarity mean of each of the sub-dissimilarity histogram vectors, is specifically used for:
[0217] For each of the sub-dissimilarity histogram vectors, the values of the elements in the sub-dissimilarity histogram vector are added together, and then divided by the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity mean of the sub-dissimilarity histogram vector.
[0218] In one possible implementation, the correction module 32, when used to divide the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, is specifically used for:
[0219] Keep the value of the first element in the dissimilar histogram vector unchanged, and set the value of the second element in the dissimilar histogram vector to 0 to obtain a sub-dissimilar histogram vector;
[0220] Set the value of the first element in the dissimilar histogram vector to 0, and keep the value of the second element in the dissimilar histogram vector unchanged to obtain another sub-dissimilar histogram vector;
[0221] Wherein, the first element is the element in the dissimilar histogram vector that corresponds to a gray value less than or equal to the adjustment threshold, and the second element is the element in the dissimilar histogram vector that corresponds to a gray value greater than or equal to the adjustment threshold.
[0222] In one possible implementation, the correction module 32, when averaging the values of elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector using the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity compensation value for limiting the sub-dissimilarity histogram vector, is specifically used for:
[0223] For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; average the sum of multiple differences using the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector; or;
[0224] For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; determine the sum S1 of the differences between multiple elements 1 and the corresponding sub-dissimilarity histogram mean in multiple sub-dissimilarity histogram vectors; average the sum S1 using the sum S2 of the number of non-zero elements in multiple sub-dissimilarity histogram vectors to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to each sub-dissimilarity histogram vector.
[0225] In one possible implementation, the correction module 32, before dividing the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, is further configured to:
[0226] The average gray value Tm1 of the pixel is determined based on the sum of the gray values of the pixels in the original image and the number of pixels in the original image.
[0227] Based on the dissimilarity histogram vectors corresponding to the original image, the average gray value Tm2 of the dissimilarity factor is determined.
[0228] The adjustment threshold Tm is determined based on the average gray value Tm1 of the pixel and the average gray value Tm2 of the similarity factor.
[0229] In one possible implementation, the correction module 32, when determining the average gray value Tm2 of the dissimilarity factor based on the dissimilarity histogram vector corresponding to the original image, is specifically used for:
[0230] Determine the product of the gray value of each pixel in the original image and the dissimilarity factor of that pixel;
[0231] Add the products corresponding to all pixels;
[0232] The average gray value Tm2 of the dissimilarity factors is obtained by averaging the sum of the dissimilarity factors of the original images and the products of the products.
[0233] In one possible implementation, the remapping module 33, when used to remap at least two of the modified sub-dissimilarity histogram vectors based on the at least one adjustment threshold to obtain the target image, is specifically used for:
[0234] Determine the probability density function vector corresponding to each modified sub-histogram vector;
[0235] Based on the probability density function vector corresponding to each modified sub-histogram vector, determine the cumulative distribution function vector corresponding to the modified sub-histogram vector;
[0236] Based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, determine the mapping function vector from the grayscale range of the original image to the preset grayscale range;
[0237] The target image is determined based on the mapping function vector.
[0238] In one possible implementation, the remapping module 33, when determining the mapping function vector from the grayscale range of the original image to a preset grayscale range based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, is specifically used for:
[0239] Using the following formula:
[0240] F(i) = tmpmin + Tm * CDF L (i), where 1≤i≤Tm;
[0241] F(i)=Tm+1+[(tmpmax-tmpmin)-(Tm+1)]*CDF R (i), where Tm+1
[0242] ≤i≤2 L-1;
[0243] Determine the value F(i) of the i-th element in the mapping function vector F, where tmpmin ≤ tmpmax, 0 < tmpmin < 2. L-1 0 < tmpmax < 2 L-1 Tm represents the adjustment threshold, CDF L (i) represents the value of the i-th element in a cumulative distribution function vector, CDF R (i) represents the value of the i-th element in another cumulative distribution function vector.
[0244] Based on the same technical concept, this application also provides an electronic device. Figure 4 A schematic diagram of an electronic device structure is shown, such as Figure 4 As shown, it includes: processor 41, and optionally, it also includes: communication interface 42, memory 43 and communication bus 44, wherein the processor 41, communication interface 42 and memory 43 communicate with each other through communication bus 44;
[0245] The memory 43 stores a computer program, which, when executed by the processor 41, causes the processor 41 to complete the steps of the above-described image processing method.
[0246] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0247] Communication interface 42 is used for communication between the above-mentioned electronic device and other devices.
[0248] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0249] The processors mentioned above can be general-purpose processors, including central processing units, network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits, field-programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0250] Based on the same technical concept and the above embodiments, this application provides a computer-readable storage medium storing a computer program executable by an electronic device, wherein computer-executable instructions are used to cause a computer to perform the steps of the above image processing method.
[0251] The aforementioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in an electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), optical storage such as CDs, DVDs, BDs, HVDs, etc., and semiconductor storage such as ROMs, EPROMs, EEPROMs, non-volatile memory (NAND flash), solid-state drives (SSDs), etc.
[0252] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0253] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0254] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0255] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0256] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. An image processing method, characterized in that, include: For each pixel in the original image, a dissimilarity factor is determined based on the pixel value and the pixel values of multiple pixels in the pixel's neighborhood. Determine the dissimilarity histogram vector corresponding to the original image; wherein the k-th element of the dissimilarity histogram vector is the sum of the dissimilarity factors of the pixels corresponding to the k-th gray level in the gray value range of the original image, and the gray value range of the original image is 0 to... The value of k ranges from 0 to L is an integer greater than or equal to 8; Based on the gray value corresponding to each element in the dissimilar histogram vector and at least one adjustment threshold, the dissimilar histogram vector is divided into at least two sub-dissimilar histogram vectors. For each sub-dissimilar histogram vector, the sub-dissimilar histogram vector is corrected based on the dissimilar mean of the sub-dissimilar histogram vector to obtain the corrected sub-dissimilar histogram vector; Based on the at least one adjustment threshold, at least two of the modified sub-dissimilarity histogram vectors are remapped to obtain the target image; Based on the dissimilarity mean of the sub-dissimilarity histogram vectors, the sub-dissimilarity histogram vectors are corrected to obtain corrected sub-dissimilarity histogram vectors, including: Determine the dissimilarity mean of each of the sub-dissimilarity histogram vectors; For each sub-dissimilarity histogram vector, the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean are set to the dissimilarity mean, while the values of the elements in the sub-dissimilarity histogram vector that are not greater than the dissimilarity mean remain unchanged, thus obtaining the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector; The dissimilarity compensation value of the restricted sub-dissimilarity histogram vector is obtained by averaging the values of the elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector using the number of non-zero elements in the sub-dissimilarity histogram vector. The value of element A in the restricted sub-dissimilarity histogram vector is kept unchanged, and the value of element B in the restricted sub-dissimilarity histogram vector is set to the sum of the value of element B and the dissimilarity compensation value corresponding to the restricted sub-dissimilarity histogram vector, to obtain the modified sub-dissimilarity histogram vector; wherein, element A is an element that is greater than or equal to the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector, and element B is an element that is less than the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector.
2. The method as described in claim 1, characterized in that, Determining the dissimilarity mean for each of the sub-dissimilarity histogram vectors includes: For each of the sub-dissimilarity histogram vectors, the values of the elements in the sub-dissimilarity histogram vector are added together, and then divided by the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity mean of the sub-dissimilarity histogram vector.
3. The method as described in claim 1, characterized in that, Based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, the dissimilar histogram vector is divided into two sub-dissimilar histogram vectors, including: Keep the value of the first element in the dissimilar histogram vector unchanged, and set the value of the second element in the dissimilar histogram vector to 0 to obtain a sub-dissimilar histogram vector; Set the value of the first element in the dissimilar histogram vector to 0, and keep the value of the second element in the dissimilar histogram vector unchanged to obtain another sub-dissimilar histogram vector; Wherein, the first element is the element in the dissimilar histogram vector that corresponds to a gray value less than or equal to the adjustment threshold, and the second element is the element in the dissimilar histogram vector that corresponds to a gray value greater than or equal to the adjustment threshold.
4. The method as described in claim 1, characterized in that, The dissimilarity compensation value for limiting the sub-dissimilarity histogram vector is obtained by averaging the values of elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean of the sub-dissimilarity histogram vector, using the number of non-zero elements in the sub-dissimilarity histogram vector. This includes: For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; average the sum of multiple differences using the number of non-zero elements in the sub-dissimilarity histogram vector to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector; or; For each sub-dissimilarity histogram vector, select element 1 whose value is greater than the dissimilarity mean of the sub-dissimilarity histogram vector; determine the difference between each element 1 and the dissimilarity mean of the dissimilarity histogram vector; determine the sum S1 of the differences between multiple elements 1 and the corresponding sub-dissimilarity histogram mean in multiple sub-dissimilarity histogram vectors; average the sum S1 using the sum S2 of the number of non-zero elements in multiple sub-dissimilarity histogram vectors to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector corresponding to each sub-dissimilarity histogram vector.
5. The method as described in claim 1, characterized in that, Before dividing the dissimilar histogram vector into two sub-dissimilar histogram vectors based on the grayscale value corresponding to each element in the dissimilar histogram vector and an adjustment threshold, the process further includes: The average gray value Tm1 of the pixel is determined based on the sum of the gray values of the pixels in the original image and the number of pixels in the original image. Based on the dissimilarity histogram vectors corresponding to the original image, the average gray value Tm2 of the dissimilarity factor is determined. The adjustment threshold Tm is determined based on the average gray value Tm1 of the pixel and the average gray value Tm2 of the similarity factor.
6. The method as described in claim 5, characterized in that, Based on the dissimilarity histogram vectors corresponding to the original image, the average gray value Tm2 of the dissimilarity factor is determined, including: Determine the product of the gray value of each pixel in the original image and the dissimilarity factor of that pixel; Add the products corresponding to all pixels; The average gray value Tm2 of the dissimilarity factors is obtained by averaging the sum of the dissimilarity factors of the original images and the products of the products.
7. The method as described in claim 1, characterized in that, Based on the at least one adjustment threshold, at least two of the modified sub-dissimilarity histogram vectors are remapped to obtain the target image, including: Determine the probability density function vector corresponding to each modified sub-histogram vector; Based on the probability density function vector corresponding to each modified sub-histogram vector, determine the cumulative distribution function vector corresponding to the modified sub-histogram vector; Based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, determine the mapping function vector from the grayscale range of the original image to the preset grayscale range; The target image is determined based on the mapping function vector.
8. The method as described in claim 7, characterized in that, Based on the cumulative distribution function vectors corresponding to multiple modified sub-histogram vectors and the at least one adjustment threshold, a mapping function vector from the grayscale range of the original image to a preset grayscale range is determined, including: Using the following formula: F(i) = tmpmin + Tm Where 1≤i≤Tm; F(i)=Tm+1+[(tmpmax-tmpmin)-(Tm+1)] Where, Tm+1≤i≤ ; Determine the value F(i) of the i-th element in the mapping function vector F, where tmpmin ≤ tmpmax, 0 < tmpmin < 0 < tmpmax < Tm represents the adjustment threshold. Let represent the value of the i-th element in a cumulative distribution function vector. This represents the value of the i-th element in another cumulative distribution function vector.
9. An image processing apparatus, characterized in that, include: The dissimilarity histogram module is used to determine the dissimilarity factor of each pixel in the original image based on the pixel value and the pixel values of multiple neighboring pixels; and to determine the dissimilarity histogram vector corresponding to the original image; wherein the k-th element of the dissimilarity histogram vector is the sum of the dissimilarity factors of the pixels corresponding to the k-th gray level in the gray value range of the original image, where the gray value range of the original image is 0 to... The value of k ranges from 0 to L is an integer greater than or equal to 8; The correction module is used to divide the dissimilar histogram vector into at least two sub-dissimilar histogram vectors based on the gray value corresponding to each element in the dissimilar histogram vector and at least one adjustment threshold; for each sub-dissimilar histogram vector, the sub-dissimilar histogram vector is corrected based on the dissimilarity mean of the sub-dissimilar histogram vector to obtain a corrected sub-dissimilar histogram vector. A remapping module is used to remap at least two of the modified sub-dissimilarity histogram vectors based on the at least one adjustment threshold to obtain a target image; The correction module is specifically used to determine the dissimilarity mean of each of the sub-dissimilarity histogram vectors; for each sub-dissimilarity histogram vector, the values of elements in the sub-dissimilarity histogram vector that are greater than the dissimilarity mean are set to the dissimilarity mean, while the values of elements in the sub-dissimilarity histogram vector that are not greater than the dissimilarity mean remain unchanged, thus obtaining the restricted sub-dissimilarity histogram vector corresponding to the sub-dissimilarity histogram vector; using the number of non-zero elements in the sub-dissimilarity histogram vector, the dissimilarity mean of the sub-dissimilarity histogram vector is calculated. The values of the elements are averaged to obtain the dissimilarity compensation value of the restricted sub-dissimilarity histogram vector; the value of element A in the restricted sub-dissimilarity histogram vector is kept unchanged, and the value of element B in the restricted sub-dissimilarity histogram vector is set to the sum of the value of element B and the dissimilarity compensation value corresponding to the restricted sub-dissimilarity histogram vector to obtain the corrected sub-dissimilarity histogram vector; wherein, element A is an element that is greater than or equal to the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector, and element B is an element that is less than the dissimilarity mean corresponding to the restricted sub-dissimilarity histogram vector.
10. An electronic device, characterized in that, include: Processor and memory; The memory is used to store computer programs or instructions; The processor is configured to execute some or all of the computer programs or instructions in the memory, and when the some or all of the computer programs or instructions are executed, to implement the method as described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, Used to store a computer program, the computer program including instructions for implementing the method of any one of claims 1-8.