Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In the description of the present invention, it is to be understood that the terms "first", "second" and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the present invention, "a plurality" means two or more unless specifically defined otherwise.
As shown in fig. 1, an embodiment of the present invention provides a color recognition method, which includes:
step S1011: and acquiring the RGB value of a target pixel point on the target substance and the RGB value of the reference background.
In this embodiment, the target substance specifically refers to a monochromatic or chromatic substance that needs to identify a color and is selected by a user, and the target pixel point specifically refers to any pixel point on the target substance. For a monochromatic substance, the color of the target pixel point is equal to that of the target substance; for a color substance, the color of the target substance needs to be comprehensively analyzed after the colors of all pixel points with different colors on the target substance are identified, so as to obtain the color of the target substance.
In the present embodiment, the RGB values specifically refer to various colors obtained by changing three color channels of red (R), green (G), and blue (B) and superimposing them on each other, and include an R component corresponding to red light, a G component corresponding to green light, and a B component corresponding to blue light.
In the present embodiment, the reference background specifically refers to a standard color whose spectral function (including a spectral function of transmitted light and a spectral function of reflected light) does not change with an external factor while ignoring the influence of the lighting environment, the optical lens transmission spectrum, the image sensor spectral response difference, the algorithm difference of the image sensor, and the like.
In an embodiment of the present invention, step S1011 specifically includes:
selecting or setting a reference background in an image field of view, and acquiring an image containing a target substance and the reference background by using an image sensor;
obtaining R of target pixel point on target substancei、GiAnd BiNumerical value, while obtaining the reference background R0、G0And B0Numerical values, where i represents different pixel points.
Step S1021: and calculating the normalized color data of the target pixel point relative to the reference background according to the RGB value of the target pixel point and the RGB value of the reference background.
In an embodiment of the present invention, step S1021 specifically includes:
according to the formula:calculating normalized color data of the target pixel points;
wherein R isi、GiAnd BiR component, G component and B component of RGB value of target pixel point i respectively, R0、G0And B0Are respectively reference backgroundsR, G and B components of an RGB value of 0, Y1i、Y2iAnd Y3iNormalized color data of the R component, the G component, and the B component of the RGB value of the target pixel point i with respect to the R component, the G component, and the B component of the RGB value of the reference background 0, respectively.
In this embodiment, R of the target pixel pointi、GiAnd BiThe numerical values are specifically:
reference background R0、G0And B0The numerical values are specifically:
wherein S isiR(λ)、SiG(lambda) and SiB(lambda) is the red, green and blue spectral functions of the light transmitted or reflected by the target pixel point i, S0R(λ)、S0G(lambda) and S0B(λ) are the red, green and blue spectral functions, respectively, of the light transmitted or reflected via the reference background 0, QR(λ)、QG(lambda) and QB(λ) is a spectral response function of R, G and B components of RGB values output by the image sensor, respectively, F (λ) is a spectral function of the light source, and Δ λ is a spectral response range of the image sensor.
According to the formula:
then there are:
therefore, the formula for calculating the normalized color data of the target pixel point in step S1021 may also beCorrespondingly, in the present embodiment, step S1011 and step S1021 may be equivalently replaced by step S1012 and step S1022 at the same time.
Wherein, step S1012 is: and acquiring a spectral function and a reference background spectral function of a target pixel point on the target substance.
In this embodiment, the spectral function specifically means that under photopic vision conditions, human eyes have different perceptibility to radiation with different wavelengths in a visible spectrum range of 380-780 nm, that is, various color lights.
Step S1022 is: and calculating the normalized color data of the target pixel point relative to the reference background according to the spectral function of the target pixel point and the spectral function of the reference background.
In a specific application, the spectral function comprises a red light spectral function, a green light spectral function and a blue light spectral function; in an embodiment of the present invention, step S1022 includes:
according to the formula:calculating normalized color data of the target pixel points;
wherein S isiR(λ)、SiG(lambda) and SiB(lambda) is the red light spectral function, the green light spectral function and the blue light spectral function of the light transmitted or reflected by the target pixel point respectively, S0R(λ)、S0G(lambda) and S0B(λ) are the red, green and blue spectral functions, respectively, of the light transmitted or reflected via the reference background 0, Y1i、Y2iAnd Y3iAre respectively eyesAnd marking normalized color data of the R component, the G component and the B component of the RGB value of the pixel point i relative to the R component, the G component and the B component of the RGB value of the reference background 0.
Step S103: and calculating the correlation between the color value of the target pixel point and the color value of each standard sample in the plurality of prestored standard samples according to the normalized color data of the target pixel point and the normalized color data of the plurality of prestored standard samples.
In this embodiment, the correlation refers to a proximity between the normalized color data of the target pixel point and the normalized color data of each of the plurality of pre-stored standard samples, and specifically reflects a similarity between the target pixel point and the color of each of the plurality of standard samples.
In an embodiment of the present invention, step S103 specifically includes:
according to the formula:calculating the correlation between the color value of the target pixel point and the color value of each standard sample in the plurality of prestored standard samples;
wherein, k ═ 1,2,3, k ═ 1 corresponds to the R component, k ═ 2 corresponds to the G component, and k ═ 3 corresponds to the B component; xκjNormalized color data for the kappa component of the RGB values of the standard sample j; y isκiNormalizing color data of a kappa component of an RGB value of a target pixel point i relative to a kappa component of an RGB value of a reference background 0; rijAnd the correlation coefficient between the color value of the target pixel point i and the color value of the standard sample j is obtained.
Step S104: and selecting the color value of the standard sample with the maximum color value correlation with the target pixel point, and identifying the color value as the real color value of the target pixel point.
In this embodiment, the real color value of the target pixel specifically means an actual color value of the target pixel under the condition of ignoring influences of an illumination environment, an optical lens transmission spectrum, an image sensor spectral response difference, an image sensor algorithm difference and the like, and the color value can be specifically measured by using an RGB value.
According to the method, the normalized color data of the target pixel point relative to the reference background is calculated, the correlation between the color value of the target pixel point and the color value of each standard sample in the plurality of prestored standard samples is calculated according to the normalized color data of the target pixel point and the normalized color data of the plurality of prestored standard samples, the color value of the standard sample with the maximum correlation with the color value of the target pixel point is selected and identified as the real color value of the target pixel point, and therefore the color value of the target substance is identified under the conditions of good data stability, high accuracy and low cost.
As shown in fig. 2, in an embodiment of the present invention, before step S103, the method includes:
step S201: the RGB value of any pixel point is obtained through an image sensor, and the spectral function of any pixel point and the spectral function of a light source used for irradiating any pixel point are obtained.
In this embodiment, any pixel point refers to any pixel point on any colored substance (including gray colors such as white and black).
In specific application, the light source can be any monochromatic light source.
Step S202: and calculating the spectral response function of the image sensor according to the RGB value of any pixel point, the spectral function of any pixel point and the spectral function of the light source.
In an embodiment of the present invention, step S202 specifically includes:
according to the formula:calculating a spectral response function of the image sensor;
wherein, I1、I2And I3Decimal expression forms of R component, G component and B component, Q, of any pixel point respectivelyR(λ)、QG(lambda) and QB(lambda) is the spectral response function of the R component, G component and B component of the image sensor, S (lambda) is the spectral function of any pixel point, F (lambda) is the spectral function of the light source, and the spectral response range of the delta lambda image sensor.
In this embodiment, the image sensor is specifically a device that converts an optical image into an electronic signal, and photosensitive elements are used as basic means for image capture, each photosensitive element corresponds to an image point in the image sensor, and RGB red, green and blue filters are covered above the photosensitive elements. When the image sensor works, the image sensor converts the information of each pixel into a digital signal after being processed by the analog-to-digital converter, the digital signal is compressed in a certain format and then stored in a buffer, and then the image data is output in the form of the digital signal and the video signal according to different requirements. I is1、I2And I3Which is substantially equal to the number of photoelectrons collected by each of the three primary color channels of the image sensor.
Step S203: spectral functions of a plurality of standard samples are acquired.
Step S204: and calculating and obtaining normalized color data of the plurality of standard samples according to the spectral response function of the image sensor and the spectral functions of the plurality of standard samples, and storing the normalized color data.
In an embodiment of the present invention, step S204 specifically includes:
according to the formula:calculating to obtain normalized color data of the plurality of standard samples;
wherein, X1j、X2jAnd X3jRespectively being the standards in the plurality of standard samplesNormalized color data for the R, G, and B components of the RGB values for sample j.
In one embodiment of the present invention, step S204 is preceded by:
step S2041: establishing a database;
step S2042: storing the normalized color data for the standard sample in the database.
In specific application, a corresponding relationship between the standard sample and the color value thereof may also be established and stored in the database, and the corresponding relationship may be specifically realized by establishing a hash table or establishing a form of a mapping relationship.
In an embodiment of the present invention, on the basis of steps S2041 and S2042, step S104 may be followed by step S2043:
and storing the real color values of the identified target pixel points in a database, and updating the database.
As shown in fig. 3, an embodiment of the present invention provides a color recognition system 100 for performing the method steps in the embodiment corresponding to fig. 1, which includes:
a first obtaining unit 1011, configured to obtain RGB values of a target pixel on a target substance and RGB values of a reference background;
a first calculating unit 1021, configured to calculate normalized color data of the target pixel with respect to the reference background according to the RGB values of the target pixel and the RGB values of the reference background;
a second obtaining unit 1012, configured to obtain a spectral function of a target pixel on a target substance and a reference background spectral function;
the second calculating unit 1022, configured to calculate normalized color data of the target pixel with respect to the reference background according to the spectral function of the target pixel and the spectral function of the reference background;
the correlation calculation unit 103 is configured to calculate, according to the normalized color data of the target pixel and the normalized color data of the pre-stored multiple standard samples, a correlation between the color value of the target pixel and the color value of each of the pre-stored multiple standard samples;
and the color identification unit 104 is configured to select a color value of the standard sample having the largest color value correlation with the target pixel point, and identify the color value as a true color value of the target pixel point.
In a specific application, the first obtaining unit 1011 may specifically adopt an image sensor; the second acquiring unit 1012 may specifically be a spectrometer.
In a specific application, when calculating the normalized color data of the target pixel point by using the RGB values, the color identification system 100 may only include the first obtaining unit 1011, the first calculating unit 1021, the correlation calculating unit 103, and the color identifying unit 104; when the spectral function is employed to calculate the normalized color data of the target pixel point, the color recognition system 100 may include only the second acquisition unit 1012, the second calculation unit 1022, the correlation calculation unit 103, and the color identification unit 104.
In an embodiment of the present invention, the first obtaining unit 1011 is specifically configured to:
selecting or setting a reference background in an image field of view, and acquiring an image containing a target substance and the reference background by using an image sensor;
obtaining R of target pixel point on target substancei、GiAnd BiNumerical value, while obtaining the reference background R0、G0And B0Numerical values, where i represents different pixel points.
In an embodiment of the present invention, the first calculating unit 1021 is specifically configured to:
according to the formula:calculating normalized color data of the target pixel points;
wherein R isi、GiAnd BiR component, G component and B component of RGB value of target pixel point i respectively, R0、G0And B0R, G and B components, Y, respectively, of RGB values of a reference background 01i、Y2iAnd Y3iNormalized color data of the R component, the G component, and the B component of the RGB value of the target pixel point i with respect to the R component, the G component, and the B component of the RGB value of the reference background 0, respectively.
In an embodiment of the present invention, the second calculating unit S1022 is specifically configured to:
according to the formula:calculating normalized color data of the target pixel points;
wherein S isiR(λ)、SiG(lambda) and SiB(lambda) is the spectral function of the R, G and B components of the target pixel point i, S0R(λ)、S0G(lambda) and S0B(λ) is a spectral function of the R, G and B components, respectively, of the reference background 0, Y1i、Y2iAnd Y3iNormalized color data of the R component, the G component, and the B component of the RGB value of the target pixel point i with respect to the R component, the G component, and the B component of the RGB value of the reference background 0, respectively.
In an embodiment of the present invention, the correlation calculation unit 103 is specifically configured to:
according to the formula:calculating the correlation between the color value of the target pixel point and the color value of each standard sample in the plurality of prestored standard samples;
wherein, k ═ 1,2,3, k ═ 1 corresponds to the R component, k ═ 2 corresponds to the G component, and k ═ 3 corresponds to the B component; xκjNormalized color data for the kappa component of the RGB values of the standard sample j; y isκiNormalizing color data of a kappa component of an RGB value of a target pixel point i relative to a kappa component of an RGB value of a reference background 0; rijAnd the correlation coefficient between the color value of the target pixel point i and the color value of the standard sample j is obtained.
According to the method, the normalized color data of the target pixel point relative to the reference background is calculated, the correlation between the color value of the target pixel point and the color value of each standard sample in the plurality of prestored standard samples is calculated according to the normalized color data of the target pixel point and the normalized color data of the plurality of prestored standard samples, the color value of the standard sample with the maximum correlation with the color value of the target pixel point is selected and identified as the real color value of the target pixel point, and therefore the color value of the target substance is identified under the conditions of good data stability, high accuracy and low cost.
As shown in fig. 4, in an embodiment of the present invention, corresponding to the method steps in the embodiment corresponding to fig. 2, the color recognition system 100 further includes:
a third obtaining unit 201, configured to obtain an RGB value of any pixel point through an image sensor, and obtain a spectral function of the any pixel point and a spectral function of a light source used for illuminating the any pixel point;
a third calculating unit 202, configured to calculate a spectral response function of the image sensor according to the RGB value of any pixel point, the spectral function of any pixel point, and the spectral function of the light source;
a fourth acquiring unit 203, configured to acquire spectral functions of a plurality of standard samples;
a fourth calculating unit 204, configured to calculate and obtain normalized color data of the multiple standard samples according to the spectral response function of the image sensor and the spectral functions of the multiple standard samples, and store the normalized color data.
In an embodiment of the present invention, the third calculating unit 202 is specifically configured to:
according to the formula:calculating a spectral response function of the image sensor;
wherein, I1、I2And I3Decimal expression forms of R component, G component and B component, Q, of any pixel point respectivelyR(λ)、QG(lambda) and QB(λ) is a spectral response function of R, G and B components of the RGB values output by the image sensor, S (λ) is a spectral function of any pixel, F (λ) is a spectral function of the light source, and Δ λ is a spectral response range of the image sensor.
In an embodiment of the present invention, the fourth calculating unit 204 is specifically configured to:
according to the formula:and calculating to obtain normalized color data of the plurality of standard samples.
Wherein, X1j、X2jAnd X3jNormalized color data of R, G, and B components of the RGB values of standard sample j in the plurality of standard samples, respectively.
In one embodiment of the present invention, the color recognition system 100 further comprises:
the establishing unit is used for establishing a database;
and the storage unit is used for storing the normalized color data of the standard sample in the database.
In an embodiment of the present invention, the color recognition system 100 may further include:
and the updating unit is used for storing the real color values of the identified target pixel points in a database and updating the database.
In a specific application, all operations related to acquiring RGB values in the above embodiment may be completed by using the same image sensor, and all operations related to acquiring a spectral function may be completed by using the same spectrometer, and by this means, errors caused by different devices may be eliminated, so that influences of an illumination environment, an optical lens transmission spectrum, an image sensor spectral response, an image sensor algorithm, and the like may be ignored.
In this embodiment, a reference basis can be provided for subsequently calculating the color value of the target pixel point by calculating the spectral response function of the image sensor, and calculating and storing the normalized color data of the plurality of standard samples according to the spectral response function of the image sensor and the spectral functions of the plurality of standard samples. In specific application, spectral functions of more standard samples should be acquired as much as possible to calculate normalized color data of more standard samples, so as to provide data support for calculating color values of target pixels.
In a specific application, the color identification method and system provided by the embodiment of the invention can be applied to the following fields, which include:
(1) medical test paper reaction color identification
And (3) reacting the standard solution with known concentration with the test paper, and establishing a reaction color database with known concentration by using the white background of the test paper as a reference background. The RGB value of a target pixel point on a target substance and the RGB value of a white reference background of the test paper are obtained simultaneously in an imaging mode, normalized color data of the target pixel point relative to the reference background are obtained through calculation, correlation detection is carried out on the normalized color data of the target pixel point and reaction color data with known concentration, and the most relevant color is searched to serve as a detection result.
By using the color identification method, the influence of factors such as illumination environment influence, difference of quantum efficiency of different sensors, difference of sensor algorithms and the like in the imaging process can be eliminated, the universality is strong, and the reaction color of the test paper can be timely and accurately searched and identified in a complex illumination environment by using a mobile terminal such as a color camera of a smart phone.
(2) Impurity metal identification in electric vehicle battery production line
The method comprises the steps of carrying out spectral analysis on several main impurity metals such as copper, aluminum, steel and the like in a laboratory to obtain spectral functions of a plurality of standard samples of the copper, the aluminum, the steel and the like, simultaneously measuring a spectral response function of an image sensor, calculating normalized color data of the plurality of standard samples of the copper, the aluminum, the steel and the like according to the spectral response function of the image sensor and the spectral functions of the plurality of standard samples of the copper, the aluminum, the steel and the like, and taking the normalized color data as color values of the standard samples of the impurity metals (the copper, the aluminum, the steel and the like) irrelevant to the illumination environment.
The same diffuse reflection white board is arranged on a production line, the RGB value of a target pixel point on a target substance and the RGB value of the diffuse reflection white board are obtained simultaneously through a color industrial camera, normalized color data of the target pixel point relative to the diffuse reflection white board are obtained through calculation, correlation detection is carried out on the normalized color data and the color value of an impurity metal standard sample, and impurity metals in products are searched and identified.
By utilizing the color identification method, the influence of factors such as illumination environment influence, difference of quantum efficiency of different sensors, difference of sensor algorithms and the like in the imaging process can be eliminated, and the fine color difference of different impurity metals can be searched and identified with high precision.
(3) Color identification of automotive bodies
In different lighting environments, the color information of the automobile body will generate large differences. And calculating to obtain the normalized color data of the aluminum alloy hub by measuring the spectral response function of the image sensor and the spectral function of the aluminum alloy hub. When the color of the automobile body is searched and identified, the RGB value of the automobile body and the RGB value of the aluminum alloy hub are obtained by using the image sensor, the normalized color data of the automobile body relative to the aluminum alloy hub is calculated, correlation detection is carried out on the normalized color data of the automobile body relative to the aluminum alloy hub obtained by actual photographing and the normalized color data of the aluminum alloy hub, and the real color value of the automobile body, which is irrelevant to the illumination environment and photographic equipment, is determined by using the maximum correlation coefficient.
The present invention is not limited to the above preferred embodiments, and any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention should be included in the protection scope of the present invention.