Color recognition method, device, equipment and storage medium
Classifying color data through HLS color model and clustering algorithm, solving the commonality problem of color recognition methods in different business scenarios, achieving wider color coverage and more efficient recognition effects.
Patent Information
- Application Number
- CN202310480286.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-28
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2043-04-28
AI Technical Summary
In the prior art, color recognition methods are not very versatile between different business scenarios and are difficult to adapt to complex business scenarios. Deep learning-based methods require training of different models for different scenarios, and methods based on manual rules cannot effectively define color changes.
The HLS color model is used to classify the color data, and the color channels are divided into multiple color types through manual division and clustering algorithms, and a filter set is established to quickly locate and classify the color types of pixel points based on the color channel values of pixel points, and determine the color types of pixel points.
It achieves stronger versatility in color recognition, more comprehensive color coverage, and can recognize more types of colors, improving the efficiency and accuracy of color recognition.
Smart Images

Figure CN116486171B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine vision, and specifically to a color recognition method, device, equipment and storage medium. Background Art
[0002] With the increasing popularity of artificial intelligence (AI) and surveillance cameras, the number of scenarios requiring color recognition is increasing. For example, in license plate recognition, after detecting a license plate, it's also necessary to determine its color—whether it's yellow, blue, green, or black. On factory production lines, color recognition can also be used to classify products for appropriate processing. In security surveillance, in the case of human attribute recognition, after detecting a person, it's also necessary to identify their skin color, hair color, and clothing color.
[0003] Previous approaches primarily focused on deep learning and manual rule-based approaches. Deep learning approaches typically involve collecting sample data, manually labeling it, and then conducting supervised training. Finally, the deep learning neural network model is deployed to identify the color of the target image. This approach can only be used in specialized business scenarios, as different deep learning neural network models require training. For example, a model for license plate color recognition cannot be used for clothing color recognition. This approach is not universal and carries extremely high R&D costs. Manual rule-based approaches, on the other hand, have difficulty defining the boundaries between different colors, and color changes are discontinuous and nonlinear. Simple rules cannot cover the entire color range and are unsuitable for complex business scenarios. Summary of the Invention
[0004] One of the purposes of this application is to provide a color recognition method, device, equipment and storage medium to solve the technical problems in the existing technology that color recognition is not universal and cannot adapt to complex business scenarios.
[0005] According to one aspect of the present application, a color recognition method is provided, comprising:
[0006] Classify the color data to obtain the values of color channels of various color types;
[0007] Get the values of all color channels of the pixels of the image to be identified;
[0008] The color type of the pixel is determined based on the values of the color channels of multiple color types and the values of all the color channels of the pixel.
[0009] In one embodiment of the present application, color data is classified to obtain values of color channels of various color types, including:
[0010] Divide the hue channel of the HLS color model to obtain multiple hue types and the hue value range corresponding to each hue type;
[0011] Constructing one or more color maps corresponding to each hue type, wherein each color map corresponds to one or more hue values, each color map includes multiple color pixels, the values of the hue channels of the multiple color pixels are limited to the corresponding hue value range, and the values of other color channels of the multiple color pixels cover all values of the other color channels;
[0012] All color pixels in the color image corresponding to each hue type are clustered respectively to obtain multiple color types corresponding to each hue type and color channel values corresponding to each color type.
[0013] In one embodiment of the present application, the color channels of the color data include a hue channel, a brightness channel, and a saturation channel, wherein determining the color type of the pixel based on the values of the color channels of multiple color types and the values of all the color channels of the pixel includes:
[0014] Establishing a first set corresponding to the hue channel and a second set corresponding to the brightness channel and the saturation channel, wherein the first set includes a plurality of first filters, the second set includes a plurality of second filters, each first filter corresponds to a hue value of a color type, and each second filter corresponds to a saturation value and a brightness value of a color type;
[0015] Determining the color type corresponding to the hue value of the pixel point based on the plurality of first filters, and determining the color type corresponding to the saturation value and the brightness value of the pixel point based on the plurality of second filters;
[0016] The color type of the pixel point is determined based on the color type corresponding to the hue value of the pixel point and the color types corresponding to the saturation value and the brightness value of the pixel point.
[0017] In one embodiment of the present application, the first filter corresponds to the hue value of the corresponding color type based on the position in the first set, and the second filter corresponds to the saturation value and brightness value of the corresponding color type based on the position in the second set.
[0018] In one embodiment of the present application, determining the color type corresponding to the hue value of the pixel point based on the multiple first filters, and determining the color type corresponding to the saturation value and the brightness value of the pixel point based on the multiple second filters includes:
[0019] Positioning a first target filter among the plurality of first filters based on the hue value of the pixel; and positioning a second target filter among the second filters based on the saturation value and brightness value of the pixel, wherein the hue value corresponding to the position of the first target filter in the first set is consistent with the hue value of the pixel, and the brightness value and saturation value corresponding to the position of the second target filter in the second set are consistent with the brightness value and saturation value of the pixel, respectively;
[0020] The color type corresponding to the first target filter is used as the color type corresponding to the hue value of the pixel point, and the color type corresponding to the second target filter is used as the color type corresponding to the saturation value and brightness value of the pixel point.
[0021] In one embodiment of the present application, determining the color type of the pixel based on the color type corresponding to the hue value of the pixel and the color types corresponding to the saturation value and the brightness value of the pixel includes:
[0022] Determining a first set of multiple color types corresponding to the hue value of the pixel point, and determining a second set of multiple color types corresponding to the saturation value and brightness value of the pixel point;
[0023] Determine the intersection of the first set and the second set to obtain the color type of the pixel.
[0024] In one embodiment of the present application, it further includes:
[0025] Determining the color type of each pixel in the image to be identified;
[0026] The color type of each pixel in the image to be identified is counted to obtain all color types of the image to be identified and the proportion of each color type, where the proportion is the ratio of the number of pixels of each color type to the total number of pixels.
[0027] Another aspect of the present application further provides a color recognition device, comprising:
[0028] The classification module is used to classify color data and obtain the values of color channels of various color types;
[0029] An acquisition module is used to obtain the values of all color channels of the pixels of the image to be identified;
[0030] The pixel identification module is used to determine the color type of the pixel based on the values of the color channels of multiple color types and the values of all the color channels of the pixel.
[0031] In another aspect of the present application, an electronic device is provided, comprising: a processor; and a memory for storing a program, wherein the program comprises instructions that, when executed by the processor, cause the processor to execute the method of an embodiment of the present application.
[0032] In another aspect of the present application, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the method of the embodiment of the present application.
[0033] The beneficial effects of this application are:
[0034] This application divides color data into multiple color types in advance and determines the value of the color channel of each color type. When recognizing an image, the value of each color channel of each pixel in the image is extracted, and the color type of the pixel is determined based on the value of each color channel of the pixel and the value of the color channels of multiple color types. This application solves the problem of difficult to define the boundaries between different colors by combining manual division and clustering algorithms. At the same time, classification based on pixels makes this application more versatile, covers a more comprehensive range of colors, and can recognize more types of colors. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A flowchart of a color recognition method shown as an exemplary embodiment of the present application;
[0036] Figure 2 A flowchart of constructing color data is shown as another exemplary embodiment of the present application;
[0037] Figure 3 A schematic diagram of color data is shown for another exemplary embodiment of the present application;
[0038] Figure 4 A flowchart of color recognition is shown as another exemplary embodiment of the present application;
[0039] Figure 5 This is a schematic diagram of a target image recognition result shown in an exemplary embodiment of the present application;
[0040] Figure 6 A structural diagram of a color recognition device shown as an exemplary embodiment of the present application;
[0041] Figure 7 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0042] The following will describe the embodiments of the present application with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand the other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be understood that the preferred embodiments are only for the purpose of illustrating the present application and are not intended to limit the scope of protection of the present application.
[0043] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application. Therefore, the illustrations only show components related to the present application and are not drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component can be changed at will, and the component layout type may also be more complicated.
[0044] Figure 1 This is a flowchart of a color recognition method shown in an exemplary embodiment of the present application. Figure 1 As shown, the color recognition method in this embodiment includes steps S110 to S140.
[0045] S110, classifying the color data to obtain values of color channels of multiple color types;
[0046] Color data refers to the data contained in the color model. By dividing the color model, we can obtain the value relationship between various color types and pixel color channels. Taking the HLS color model as an example, the HLS color model includes a hue channel, a lightness channel, and a saturation channel.
[0047] Taking the HLS color model as an example, the process of classifying color data and obtaining the values of color channels of various color types includes:
[0048] Divide the hue channel of the HLS color model to obtain multiple hue types and the hue value range corresponding to each hue type;
[0049] By manually dividing the HLS color model, multiple hue types are obtained. In the HLS color model, the hue channel has a value range of 0-360°, and each hue type corresponds to a hue value range.
[0050] For example, according to the arrangement rules of hues, the six main hues of red, yellow, green, cyan, blue, and purple and the mixed colors between the main hues are divided from 0-360° to obtain N hue types and value ranges of the N hue types.
[0051] Constructing one or more color maps corresponding to each hue type, wherein each color map corresponds to one or more hue values, each color map includes multiple color pixels, the values of the hue channels of the multiple color pixels are limited to the corresponding hue value range, and the values of other color channels of the multiple color pixels cover all values of the other color channels;
[0052] All color pixels in the color image corresponding to each hue type are clustered respectively to obtain multiple color types corresponding to each hue type and color channel values corresponding to each color type.
[0053] A color map constructed based on a hue type represents all colors that exist within that hue value range.
[0054] For example, the horizontal direction of the color image is brightness, with a value range from 0-100, increasing from left to right, and the vertical direction of the color image is saturation, with a value range from 0-100, increasing from top to bottom.
[0055] All color pixels in the color image corresponding to each hue type are clustered respectively to obtain multiple color types corresponding to each hue type and color channel values corresponding to each color type.
[0056] In this embodiment, a clustering algorithm is used to cluster the color pixels in the color image, and the multiple colors in the color image are clustered into color types, thereby obtaining multiple color types corresponding to each hue type.
[0057] The clustering algorithm may be a k-means clustering algorithm, which clusters the color information contained in the color map corresponding to each hue type into M color types, thereby dividing the HLS color model into N*M color types.
[0058] The color data established based on the color model has the advantages of strong versatility, clear boundaries, comprehensive color coverage, and a wide range of identifiable colors.
[0059] S120, obtaining values of all color channels of pixels of the image to be identified;
[0060] The color of a pixel of the image to be identified is determined by multiple color channels. Therefore, this embodiment identifies the color of the pixel by acquiring the values of all color channels of the pixel of the image to be identified.
[0061] The color model of the image to be identified should be consistent with the color model of the color data to ensure that the color channels of the pixels are consistent with the color channels of the collection. For example, if the color data uses the HLS color model, the color model of the image to be identified should also be the HLS model. If the color model of the image to be identified is the RGB model, the image to be identified must first be converted from the RGB color model to the HLS color model. This will determine the values of the hue, brightness, and saturation channels of the pixels.
[0062] S130: Determine the color type of the pixel based on the values of color channels of multiple color types and the values of all color channels of the pixel.
[0063] The value of the color channel of a certain color type should include the value of the color channel corresponding to the pixel point. For example, the value of the hue channel of a certain color type should include the value of the hue channel of the pixel point, the value of the brightness channel of a certain color type should include the value of the brightness channel of the pixel point, and the value of the saturation channel of a certain color type should include the value of the saturation channel of the pixel point.
[0064] The specific determination process includes the following steps:
[0065] Establishing a first set corresponding to the hue channel and a second set corresponding to the brightness channel and the saturation channel, wherein the first set includes a plurality of first filters, the second set includes a plurality of second filters, each first filter corresponds to a hue value of a color type, and each second filter corresponds to a saturation value and a brightness value of a color type;
[0066] The first set is established based on the values of the hue channel corresponding to multiple color types, and the second set is established based on the values of the brightness channel and saturation channel corresponding to multiple color types. That is, the first set corresponds to the hue channel, and the second set corresponds to the brightness and saturation channels.
[0067] Each first filter in the first set corresponds to a hue value range of a color type. Each second filter in the second set corresponds to a brightness and saturation value range of a color type.
[0068] For example, the value corresponding to a first filter in the first set is {1,1,1,1,1,0,0,0,0,0...}. The first five 1s indicate that the hue value range of the color type corresponding to the first filter is from 1 to 5, and the corresponding color type is red.
[0069] Determining the color type corresponding to the hue value of the pixel point based on the plurality of first filters, and determining the color type corresponding to the saturation value and the brightness value of the pixel point based on the plurality of second filters;
[0070] In this embodiment, the value of the pixel point is used to perform position indexing on the filters in the corresponding set to obtain the filter corresponding to the value of each color channel of the pixel point.
[0071] In this embodiment, the first filter contains an array, and the position of each digit in the array represents the corresponding hue value. Each digit is 0 or 1. 1 indicates that the hue value falls into the hue range corresponding to the first filter, and the first filter is the first target filter for the pixel point. 0 indicates that the hue value does not belong to the hue range corresponding to the first filter. If the hue value of a pixel point is 2, and the value of the second digit of the first filter is 1, it means that the hue type of the pixel point is consistent with the hue type corresponding to the first filter, and the first filter is the first target filter for the pixel point. The second filter contains a two-dimensional array, one dimension of which corresponds to saturation and the other dimension represents brightness. During the positioning process, the second filter is the same as the first filter.
[0072] This application uses coordinate positioning to quickly filter pixels. The specific process is as follows:
[0073] A first target filter among a plurality of first filters is located based on the hue value of the pixel point; and a second target filter among the second filters is located based on the saturation value and brightness value of the pixel point.
[0074] The first target filter is obtained by performing position indexing based on the hue value of the pixel point, and the second target filter is obtained by performing position indexing based on the brightness value and saturation value of the pixel point.
[0075] The color type corresponding to the first target filter is used as the color type corresponding to the hue value of the pixel point, and the color type corresponding to the second target filter is used as the color type corresponding to the saturation value and brightness value of the pixel point.
[0076] In this embodiment, the array within the filter is used as a coordinate system, and the color channel values of the pixel are used as coordinates for position indexing. This positioning method determines the color type of each color channel of the pixel, eliminating the time required to traverse and compare within the color database, shortening color recognition time and improving color recognition efficiency. The color database stores the values of color channels for various color types.
[0077] For example, a pixel's hue channel value is 2, its brightness channel value is 20, and its saturation channel value is 20. The hue range for one of the first filters in the first set corresponding to the hue channel is {1, 2, 3, 4, 5}. Since the hue range is represented by 0 and 1 in the first filter, the corresponding range within the first filter is actually {1, 1, 1, 1, 1, 0, 0, 0, 0, 0...}. The first five 1s indicate that the hue values for the first filter range from 1 to 5. A pixel's hue value is input to the first filter, and its hue value is 2. Using the position index of 2, the second position of the first filter is 1, indicating that the pixel's hue value falls within the hue range corresponding to the first filter. At this point, the first filter outputs 1, indicating that the pixel's hue type matches the hue type for the current first filter. For example, if the hue type for the first filter is red, and the hue channel value is 2, the corresponding value at the second position of the first filter is 1, indicating that the color type for the pixel's hue channel value is red.
[0078] At the same time, a second filter in the second set corresponding to the brightness channel and saturation channel has a value range of {(1, 1, 0, 1, 1, 0, 0, 1, …), (0, 0, 0, 1, 1, 0, 1, …)}. The brightness and saturation values of the pixel are used for position indexing. The saturation and brightness values of the pixel are both 20. If the value of the 20th bit in the value range is 1, it means that the brightness and saturation of the pixel are consistent with the brightness and saturation type corresponding to the second filter. For example, if the color type corresponding to the second filter is the target brightness and saturation, then the pixel also has the target brightness and saturation.
[0079] The color type of the pixel point is determined based on the color type corresponding to the hue value of the pixel point and the color types corresponding to the saturation value and the brightness value of the pixel point.
[0080] Since there may be multiple color types corresponding to hue values, and there may also be multiple color channels corresponding to brightness and saturation values, when determining the color type of a pixel, it is necessary to find the intersection of multiple possible color types, namely:
[0081] Determining a first set of multiple color types corresponding to the hue value of the pixel point, and determining a second set of multiple color types corresponding to the saturation value and brightness value of the pixel point;
[0082] Determine the intersection of the first set and the second set to obtain the color type of the pixel.
[0083] In this embodiment, determining the color type of the pixel point is the process of finding the intersection.
[0084] For example, the color type corresponding to the hue value of a pixel is red, and the possible color types of the pixel are dark red, light red, pink, etc.; the color type corresponding to the brightness value and saturation value of a pixel is dark, and the possible color types of the pixel are dark red, dark blue, dark green, etc.; by finding the intersection of the two sets, we can get the color type of the pixel as dark red.
[0085] The above recognition process takes up a part of the physical space by loading the color database into the memory in the form of parameters in advance. However, the positioning method is used to save the time of reading the color database and traversing and comparing it. By trading space for time, the color recognition speed can be effectively improved.
[0086] S140, determining the color type of each pixel in the image to be identified, and counting the color type of each pixel in the image to be identified to obtain all color types of the image to be identified and the proportion of each color type, where the proportion is the ratio of the number of pixels of each color type to the total number of pixels.
[0087] In this embodiment, after identifying the color type of each pixel in the image to be identified, the image to be identified can be further identified based on the color type of each pixel. The identification parameters include: all color types of the image to be identified and the proportion of each color type. This allows for a more intuitive display of image recognition.
[0088] Figure 2 A flowchart of constructing color data is shown as another exemplary embodiment of the present application. Figure 2 As shown, this embodiment is based on the HLS color model and classifies colors by combining manual division and clustering algorithm.
[0089] First, set the number of color categories based on the business scenario. For example, if license plate recognition requires fewer color categories, you can set a few color categories. Based on the set number of color categories, combine the color distribution patterns in the hue wheel diagram to divide the six primary colors (red, yellow, green, cyan, blue, and purple) and their mixed colors from 0-360°. The number of categories is N.
[0090] Then, a two-dimensional color map of brightness and saturation corresponding to each hue is drawn. This can be a single hue value corresponding to a 2D color map, or multiple hue values corresponding to a 2D color map. The horizontal direction of the 2D color map is brightness, ranging from 0-100, increasing from left to right; the vertical direction is saturation, ranging from 0-100, increasing from top to bottom.
[0091] Next, the k-means clustering algorithm is applied to the pixels within the two-dimensional color map, dividing the two-dimensional color map corresponding to each hue into M categories. Finally, the resulting (N*M) color maps are organized and merged, completing the classification of colors of different hues, brightness, and saturations. The classified color data is stored in a color database until it is called upon in the subsequent recognition process.
[0092] Figure 3 Another exemplary embodiment of the present application shows a schematic diagram of color data, where the color data stored in the color database is as follows: Figure 3 shown.
[0093] This color classification method allows for greater versatility, more comprehensive color coverage, and a wider range of identifiable colors when subsequently calling color types for color recognition, allowing it to be used in any scenario. Furthermore, when performing subsequent color recognition on pixels, each pixel is assigned a specific category, resulting in pixel-level color recognition accuracy.
[0094] After obtaining the color database, each pixel of the target image can be identified. By summarizing the color of each pixel, we can finally get the color categories and their proportions contained in the target image. For general color recognition methods, we can first read the image data and convert its color space from RGB to HLS. Then, we can obtain all the pixels of the image, traverse the color database, and compare the value of each pixel of the target image with the color data in the color database one by one, so as to realize the recognition of the color type of all pixels of the target image. However, this method requires too many comparisons, which makes it too time-consuming.
[0095] Figure 4 A flowchart of color recognition is shown for another exemplary embodiment of the present application, as shown in FIG. Figure 4 As shown, the color recognition process in this embodiment includes:
[0096] A classifier is created based on color data. The classifier contains two types of filters: an H filter (the first set) corresponding to the hue channel, and an LS filter (the second set) corresponding to the lightness and saturation channels. The H filter corresponds to the set of hue channels, while the LS filter corresponds to the set of saturation and lightness channels. Both the H and LS filters have ClassNum sieves (ClassNum can be the number of color categories). Each sieve in the H filter consists of a fixed-length one-dimensional array, while each sieve in the LS filter consists of a fixed-length two-dimensional array, for example, a length of 180.
[0097] Then, the values of each color channel of each color type are loaded from the color database into the corresponding filter sieve, so that each sieve is responsible for filtering a color type. For example, the sieve in the H filter is responsible for filtering hue, and the sieve in the LS filter is responsible for filtering brightness and saturation.
[0098] To identify pixels in a target image, you first need to read the target image and determine its color space. If the target image's color space is RGB, you need to convert it from RGB to HLS. Then, the target image's pixels are fed into the classifier. The pixel's hue channel value is fed into the H filter, while the brightness and saturation channel values are fed into the LS filter.
[0099] Based on the pixel's hue value, the corresponding one-dimensional array for each sieve in the H filter is indexed to determine the target sieve in the H filter. Based on the pixel's brightness and saturation values, the corresponding two-dimensional array for each sieve in the LS filter is indexed to determine the target sieve in the LS filter. When indexing, if the target bit in the array corresponding to each sieve is 1, the sieve outputs 1; if the target bit is 0, the sieve outputs 0. The target bit is determined by the pixel's color channel value. For example, if the pixel's hue value is 2, the target bit is bit 2. The target sieve outputs a value of 1, thus determining the pixel's hue type, brightness, and saturation type.
[0100] The H filter includes ClassNum sieves. When the hue value corresponding to one sieve matches the hue value of a pixel, the output of that sieve is 1, and the outputs of the other sieves are 0, thus forming a one-dimensional array of length ClassNum. This one-dimensional data can be used to identify the hue of the pixel. For example, if the hue type of the pixel corresponds to the sixth sieve, the value of the sixth position in the output one-dimensional array will be 1, and the values of the remaining positions will be 0.
[0101] The sieves in the LS filter are two-dimensional, and each sieve corresponds to two types of information: brightness and saturation. Similar to the H filter, the LS filter also outputs a one-dimensional array of length ClassNum.
[0102] The filter outputs an array representing the color type of the corresponding color channel. Since the color type of a single color channel can correspond to the color types of multiple pixels, the two arrays must be operated on to obtain a precise result. In this embodiment, the two arrays are finally multiplied or ANDed together, and the resulting one-dimensional array is the output of the classifier. This output one-dimensional array allows for rapid identification of the pixel's color type.
[0103] Figure 5This is a schematic diagram of the recognition result of the target image shown in an exemplary embodiment of the present application. Figure 5 As shown, finally, the color type of each pixel in the target image can be determined, and the color type of each pixel in the image to be identified is counted to obtain all color types of the image to be identified and the proportion of each color type.
[0104] The color recognition method in this application divides color data into multiple color types in advance and determines the value of the color channel of each color type. When recognizing an image, the value of each color channel of each pixel in the image is extracted, and the color type of the pixel is determined based on the value of each color channel of the pixel and the value of the color channels of multiple color types. This application solves the problem of difficult to define the boundaries between different colors by combining manual division and clustering algorithms. At the same time, classification based on pixels makes this application more versatile, more comprehensive in color coverage, and more identifiable in color types.
[0105] Figure 6 This is a structural diagram of a color recognition device shown in an exemplary embodiment of the present application. Figure 6 As shown, the color recognition device includes:
[0106] A classification module 610 is used to classify the color data and obtain the values of color channels of multiple color types;
[0107] An acquisition module 620 is used to acquire the values of all color channels of the pixels of the image to be identified;
[0108] A pixel identification module 630 is configured to determine a color type of a pixel based on values of color channels of multiple color types and values of all color channels of the pixel;
[0109] The image recognition module 640 determines the color type of each pixel in the image to be recognized, and counts the color type of each pixel in the image to be recognized to obtain all color types of the image to be recognized and the proportion of each color type, where the proportion is the ratio of the number of pixels of each color type to the total number of pixels.
[0110] The color recognition device in this application divides color data into multiple color types in advance and determines the value of the color channel of each color type. When recognizing an image, the value of each color channel of each pixel in the image is extracted, and the color type of the pixel is determined based on the value of each color channel of the pixel and the value of the color channels of multiple color types. This application solves the problem of difficult to define the boundaries between different colors by combining manual division and clustering algorithms. At the same time, classification based on pixels makes this application more versatile, more comprehensive in color coverage, and more identifiable in color types.
[0111] Figure 7 The following is a schematic diagram showing the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application. Figure 7 The computer system 700 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0112] like Figure 7 As shown, computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in read-only memory (ROM) 702 or programs loaded from storage 708 into random access memory (RAM) 703. RAM 703 also stores various programs and data required for system operation. CPU 701, ROM 702, and RAM 703 are interconnected via a bus 704. An input / output (I / O) interface 705 is also connected to bus 704.
[0113] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, mouse, and the like; an output section 707 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 708 including devices such as a hard disk; and a communication section 709 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. Removable media 711, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 710 as needed, so that computer programs read from the media can be installed in the storage section 708 as needed.
[0114] In particular, according to embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for executing the methods illustrated in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via the communication section 709 and / or installed from removable media 711. When executed by the central processing unit (CPU) 701, the computer program performs the various functions defined in the system of the present application.
[0115] It should be noted that the computer-readable medium described in the embodiments of this application may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may, for example, be an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. This propagated data signal may take a variety of forms, including, but not limited to, an electromagnetic signal, an optical signal, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. A computer program embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.
[0116] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0117] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.
[0118] Another aspect of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a computer processor, the computer executes the aforementioned method. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device.
[0119] Another aspect of the present application provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the color recognition and prediction methods provided in the various embodiments described above.
[0120] The above embodiments are only preferred embodiments for fully illustrating the present application, and the protection scope of the present application is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art based on the present application are within the protection scope of the present application.
Claims
1. A color recognition method, characterized in that: include: Classify the color data to obtain the values of color channels of various color types; Get the values of all color channels of the pixels of the image to be identified; Determine the color type of the pixel based on the values of the color channels of multiple color types and the values of all the color channels of the pixel; The color channels of the color data include a hue channel, a brightness channel, and a saturation channel, wherein the color type of the pixel is determined based on the values of the color channels of multiple color types and the values of all the color channels of the pixel, including: Establishing a first set corresponding to the hue channel and a second set corresponding to the brightness channel and the saturation channel, wherein the first set includes a plurality of first filters, the second set includes a plurality of second filters, each first filter corresponds to a hue value of a color type, and each second filter corresponds to a saturation value and a brightness value of a color type; Determining the color type corresponding to the hue value of the pixel based on the plurality of first filters, and determining the color type corresponding to the saturation value and the brightness value of the pixel based on the plurality of second filters; The color type of the pixel point is determined based on the color type corresponding to the hue value of the pixel point and the color types corresponding to the saturation value and the brightness value of the pixel point.
2. The color recognition method according to claim 1, wherein: Classify the color data and obtain the values of color channels of various color types, including: Divide the hue channel of the HLS color model to obtain multiple hue types and the hue value range corresponding to each hue type; Constructing one or more color maps corresponding to each hue type, wherein each color map corresponds to one or more hue values, each color map includes multiple color pixels, the values of the hue channels of the multiple color pixels are limited to the corresponding hue value range, and the values of other color channels of the multiple color pixels cover all values of the other color channels; All color pixels in the color image corresponding to each hue type are clustered respectively to obtain multiple color types corresponding to each hue type and color channel values corresponding to each color type.
3. The color recognition method according to claim 1, wherein: The first filter corresponds to the hue value of the corresponding color type based on the position in the first set, and the second filter corresponds to the saturation value and brightness value of the corresponding color type based on the position in the second set.
4. The color recognition method according to claim 3, characterized in that: Determining the color type corresponding to the hue value of the pixel point based on a plurality of first filters, and determining the color type corresponding to the saturation value and the brightness value of the pixel point based on a plurality of second filters, including: Positioning a first target filter among the multiple first filters based on the hue value of the pixel; and positioning a second target filter among the second filters based on the saturation value and brightness value of the pixel, wherein the hue value corresponding to the position of the first target filter in the first set is consistent with the hue value of the pixel, and the brightness value and saturation value corresponding to the position of the second target filter in the second set are consistent with the brightness value and saturation value of the pixel, respectively; The color type corresponding to the first target filter is used as the color type corresponding to the hue value of the pixel point, and the color type corresponding to the second target filter is used as the color type corresponding to the saturation value and brightness value of the pixel point.
5. The color recognition method according to claim 1, wherein: Determining the color type of the pixel point based on the color type corresponding to the hue value of the pixel point and the color types corresponding to the saturation value and the brightness value of the pixel point includes: Determining a first set of multiple color types corresponding to the hue value of the pixel point, and determining a second set of multiple color types corresponding to the saturation value and brightness value of the pixel point; Determine the intersection of the first set and the second set to obtain the color type of the pixel.
6. The color recognition method according to claim 1, wherein: Also includes: Determining the color type of each pixel in the image to be identified; The color type of each pixel in the image to be identified is counted to obtain all color types of the image to be identified and the proportion of each color type, where the proportion is the ratio of the number of pixels of each color type to the total number of pixels.
7. A color recognition device, characterized in that: include: The classification module is used to classify color data and obtain the values of color channels of various color types; An acquisition module is used to obtain the values of all color channels of the pixels of the image to be identified; a pixel identification module, configured to determine the color type of a pixel based on the values of color channels of multiple color types and the values of all color channels of the pixel; The color channels of the color data include a hue channel, a brightness channel, and a saturation channel. The color type of the pixel is determined based on the values of the color channels of multiple color types and the values of all the color channels of the pixel, including: Establishing a first set corresponding to the hue channel and a second set corresponding to the brightness channel and the saturation channel, wherein the first set includes a plurality of first filters, the second set includes a plurality of second filters, each first filter corresponds to a hue value of a color type, and each second filter corresponds to a saturation value and a brightness value of a color type; Determining the color type corresponding to the hue value of the pixel based on the plurality of first filters, and determining the color type corresponding to the saturation value and the brightness value of the pixel based on the plurality of second filters; The color type of the pixel point is determined based on the color type corresponding to the hue value of the pixel point and the color types corresponding to the saturation value and the brightness value of the pixel point.
8. An electronic device comprising: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Picture color identification method and system
CN106651966A
Color classification and recognition method, device and automatic driving system
CN109460710A
Monochrome video determination method and device, electronic equipment and storage medium
CN110400355A