CN110719382B - Color replacement method and device - Google Patents

Color replacement method and device Download PDF

Info

Publication number
CN110719382B
CN110719382B CN201910955279.1A CN201910955279A CN110719382B CN 110719382 B CN110719382 B CN 110719382B CN 201910955279 A CN201910955279 A CN 201910955279A CN 110719382 B CN110719382 B CN 110719382B
Authority
CN
China
Prior art keywords
color
value
line
replaced
currently read
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910955279.1A
Other languages
Chinese (zh)
Other versions
CN110719382A (en
Inventor
宋鑫鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Mininglamp Software System Co ltd
Original Assignee
Beijing Mininglamp Software System Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Mininglamp Software System Co ltd filed Critical Beijing Mininglamp Software System Co ltd
Priority to CN201910955279.1A priority Critical patent/CN110719382B/en
Publication of CN110719382A publication Critical patent/CN110719382A/en
Application granted granted Critical
Publication of CN110719382B publication Critical patent/CN110719382B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N1/00Scanning, transmission or reproduction of documents or the like, e.g. facsimile transmission; Details thereof
    • H04N1/46Colour picture communication systems
    • H04N1/56Processing of colour picture signals
    • H04N1/60Colour correction or control
    • H04N1/62Retouching, i.e. modification of isolated colours only or in isolated picture areas only

Abstract

The embodiment of the invention discloses a color replacement method and a color replacement device, wherein the method comprises the following steps: respectively reading a first color value of a color in a given color range and a second color value of a color to be replaced; determining whether the color corresponding to the currently read second color value needs to be subjected to color replacement or not according to a preset matching algorithm; when it is determined that the color corresponding to the currently read second color value needs to be replaced, comparing the currently read second color value with the plurality of first color values one by one; and selecting the color corresponding to the first color value with the minimum color difference value with the currently read second color value, and replacing the color corresponding to the currently read second color value. Through the scheme of the embodiment, the automation of color replacement is realized, the color matching speed is increased, and the color replacement precision is improved.

Description

Color replacement method and device
Technical Field
The present invention relates to color processing technologies, and in particular, to a color replacement method and apparatus.
Background
In the existing color replacement scheme, colors required to be replaced are generally matched through naked eyes, then the colors are replaced, color values are replaced, and the purpose of replacing similar colors is achieved.
Disclosure of Invention
In order to solve the above technical problem, embodiments of the present invention provide a color replacement method and apparatus, which can implement automation of color replacement, improve color matching speed, and improve color replacement accuracy.
To achieve the object of the embodiments of the present invention, the embodiments of the present invention provide a color replacement method, which may include:
respectively reading a first color value of a color in a given color range and a second color value of a color to be replaced;
determining whether the color corresponding to the currently read second color value needs to be subjected to color replacement or not according to a preset matching algorithm;
when it is determined that the color corresponding to the currently read second color value needs to be replaced, comparing the currently read second color value with the plurality of first color values one by one;
and selecting the color corresponding to the first color value with the minimum color difference value with the currently read second color value, and replacing the color corresponding to the currently read second color value.
In an exemplary embodiment of the present invention, the reading of the first color value of the color within the given color range may include:
performing a first position marking for the given color range;
reading a first color value of a color in the color range line by line according to the first position mark.
In an exemplary embodiment of the present invention, reading the second color value of the color to be replaced may include:
carrying out second position marking on the color to be replaced;
and reading the second color value of the color to be replaced line by line according to the second position mark.
In an exemplary embodiment of the present invention, the determining, according to a preset matching algorithm, whether a color corresponding to the currently read second color value needs to be color-replaced may include:
matching the color value of the currently read second color value according to the matching algorithm;
and when the hexadecimal color value is matched, determining that the color corresponding to the currently read second color value needs to be subjected to color replacement.
In an exemplary embodiment of the present invention, the matching algorithm may include: a regular expression.
In an exemplary embodiment of the present invention, the method may further include: and converting all the read first color values into red, green and blue RGB values, and storing the red, green and blue RGB values into a preset array.
In an exemplary embodiment of the present invention, the comparing the currently read second color value with the plurality of first color values one by one may include:
converting all RGB values in the array into first Hue Saturation Value (HSV) values, and converting currently read second color values into second HSV values;
comparing the first HSV value to the second HSV value.
In an exemplary embodiment of the present invention, the method may further include: and determining a first color value corresponding to the first HSV value with the minimum difference with the current second HSV value as the first color value with the minimum color difference with the currently read second color value.
In an exemplary embodiment of the present invention, the method may further include: and reading the second color value of each line of color in the color file to be replaced line by line, determining whether the line of color needs to be replaced line by line, and performing color replacement when the line of color needs to be replaced is determined until the last line of color in the color file to be replaced finishes determining operation or replacing operation.
The embodiment of the present invention further provides a color replacement apparatus, which may include a processor and a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are executed by the processor, the color replacement method described in any one of the above is implemented.
The embodiment of the invention comprises the following steps: respectively reading a first color value of a color in a given color range and a second color value of a color to be replaced; determining whether the color corresponding to the currently read second color value needs to be subjected to color replacement or not according to a preset matching algorithm; when it is determined that the color corresponding to the currently read second color value needs to be replaced, comparing the currently read second color value with the plurality of first color values one by one; and selecting the color corresponding to the first color value with the minimum color difference value with the currently read second color value, and replacing the color corresponding to the currently read second color value. Through the scheme of the embodiment, the automation of color replacement is realized, the color matching speed is increased, and the color replacement precision is improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
The accompanying drawings are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the example serve to explain the principles of the invention and not to limit the invention.
FIG. 1 is a flow chart of a color replacement method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an HSV color model;
fig. 3 is a block diagram of a color replacement apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
The steps illustrated in the flow charts of the figures may be performed in a computer system such as a set of computer-executable instructions. Also, while a logical order is shown in the flow diagrams, in some cases, the steps shown or described may be performed in an order different than here.
An embodiment of the present invention provides a color replacement method, as shown in fig. 1, the method may include S101-S104:
s101, respectively reading a first color value of a color in a given color range and a second color value of a color to be replaced.
In an exemplary embodiment of the present invention, the reading of the first color value of the color within the given color range may include:
performing a first position marking for the given color range;
reading a first color value of a color in the color range line by line according to the first position mark.
In an exemplary embodiment of the present invention, reading the second color value of the color to be replaced may include:
carrying out second position marking on the color to be replaced;
and reading the second color value of the color to be replaced line by line according to the second position mark.
In an exemplary embodiment of the present invention, a file stream to be read and a file saving stream may be first obtained, a file to be read is opened, and a file saving position is set:
f1=open("src/css/common/_variables.scss",'r');
f2=open("src/css/common/_variables3.scss",'w')。
in an exemplary embodiment of the present invention, colors may be divided into a color range (for performing color replacement) and a color to be replaced, and position marks may be performed separately, where the color range and the color to be replaced may be separated using "/over".
In an exemplary embodiment of the present invention, the method may further include: and converting all the read first color values into red, green and blue RGB values, and storing the red, green and blue RGB values into a preset array.
In an exemplary embodiment of the present invention, the method may further include: and converting all the read second color values into RGB values, and storing the RGB values into a preset array (such as a second array).
In an exemplary embodiment of the present invention, after reading and separating the color range and the color to be replaced line by line, the color range value may be converted into RGB colors and saved:
Figure BDA0002227073650000041
Figure BDA0002227073650000051
s102, determining whether the color corresponding to the currently read second color value needs to be replaced according to a preset matching algorithm.
In an exemplary embodiment of the present invention, the determining, according to a preset matching algorithm, whether a color corresponding to the currently read second color value needs to be color-replaced may include:
matching the color value of the currently read second color value according to the matching algorithm;
and when the hexadecimal color value is matched, determining that the color corresponding to the currently read second color value needs to be subjected to color replacement.
In an exemplary embodiment of the present invention, the matching algorithm may include: a regular expression.
In the exemplary embodiment of the present invention, the color to be replaced may be read line by line, and regular matching may be performed through a regular expression, and if a hexadecimal color value is matched, color value extraction and replacement may be performed.
In an exemplary embodiment of the present invention, the color to be replaced is read line by line, and if there is a hexadecimal color, identification is performed, replacement:
Figure BDA0002227073650000052
Figure BDA0002227073650000061
s103, when it is determined that the color corresponding to the currently read second color value needs to be replaced, comparing the currently read second color value with the plurality of first color values one by one.
In an exemplary embodiment of the present invention, the comparing the currently read second color value with the plurality of first color values one by one may include:
converting all RGB values in the array into first Hue Saturation Value (HSV) values, and converting currently read second color values into second HSV values;
comparing the first HSV value to the second HSV value.
In an exemplary embodiment of the invention, the colors within the color gamut are converted to HSV color values before being compared one-by-one to calculate the color difference.
HSV (Hue, Saturation) is a color space created by a.r. smith in 1978, also known as the hexagonal cone Model (Hexcone Model), based on the intuitive nature of color. The parameters of the colors in this model are: hue (H), saturation (S), and brightness (V), as shown in fig. 2.
HEX color is also known as hexadecimal color. The hexadecimal color code is a code for setting color values in software. In many software, the problem of setting color values is encountered, and there are two types of colors seen by the eyes of developing sources: one is the color emitted by the light, such as the color displayed on a computer display screen; the other is that the object itself does not emit light, but the reflected light produces a hexadecimal color.
The RGB color space is based on three basic colors of R (Red), G (Green) and B (Blue) and is superposed to different degrees to generate rich and wide colors, so the RGB color space is commonly called a three-primary-color mode.
The RGB space is the most common model in life, and most of tv sets, CRT displays of computers, and the like use this model. Any color in nature can be formed by mixing red, green and blue lights, and most of colors seen by people in real life are mixed colors.
Both the RGB and CMY color models are hardware-oriented, while the hsv (hue validation value) color model is user-oriented. The three-dimensional representation of the HSV model evolved from the RGB cube. Consider that the hexagonal shape of a cube is seen looking from the white vertices to the black vertices of RGB along the diagonal of the cube. The hexagonal boundaries represent color, the horizontal axis represents purity, and brightness is measured along the vertical axis.
In an exemplary embodiment of the invention, RGB color values are converted to HSV color values:
Figure BDA0002227073650000071
s104, selecting the color corresponding to the first color value with the minimum color difference value with the currently read second color value, and replacing the color corresponding to the currently read second color value.
In an exemplary embodiment of the present invention, the method may further include: and determining a first color value corresponding to the first HSV value with the minimum difference with the current second HSV value as the first color value with the minimum color difference with the currently read second color value.
In an exemplary embodiment of the present invention, a color value with the smallest difference from the color range value is selected to replace the color of the current line in the color file to be replaced.
In an exemplary embodiment of the present invention, the difference between the color value and the color value is calculated:
Figure BDA0002227073650000072
Figure BDA0002227073650000081
in an exemplary embodiment of the invention, the RGB colors are converted to HEX colors:
Figure BDA0002227073650000082
in an exemplary embodiment of the invention, the HEX color is converted to RGB color:
Figure BDA0002227073650000083
in an exemplary embodiment of the present invention, the method may further include: and reading the second color value of each line of color in the color file to be replaced line by line, determining whether the line of color needs to be replaced line by line, and performing color replacement when the line of color needs to be replaced is determined until the last line of color in the color file to be replaced finishes determining operation or replacing operation.
In an exemplary embodiment of the present invention, the line-by-line matching is performed until the end of the file, and a new color value file is generated.
In an exemplary embodiment of the invention, the file IO stream is closed when the end of the file is reached:
f1.close();
f2.close()。
an embodiment of the present invention further provides a color replacement apparatus 1, as shown in fig. 3, which may include a processor 11 and a computer-readable storage medium 12, where the computer-readable storage medium 12 stores instructions, and when the instructions are executed by the processor 11, the color replacement method described in any one of the above is implemented.
It will be understood by those of ordinary skill in the art that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those of ordinary skill in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art.

Claims (9)

1. A color replacement method, characterized in that the method comprises:
respectively reading a first color value of a color in a given color range and a second color value of a color to be replaced;
matching the color value of the currently read second color value according to the matching algorithm;
when the hexadecimal color value is matched, determining that the color corresponding to the currently read second color value needs to be subjected to color replacement;
when it is determined that the color corresponding to the currently read second color value needs to be replaced, comparing the currently read second color value with the plurality of first color values one by one;
and selecting the color corresponding to the first color value with the minimum color difference value with the currently read second color value, and replacing the color corresponding to the currently read second color value.
2. The color replacement method of claim 1 wherein reading the first color value of a color in the given color range comprises:
performing a first position marking for the given color range;
and reading a first color value of the color in the color range line by line according to the first position mark.
3. The color replacement method according to claim 1, wherein reading the second color value of the color to be replaced comprises:
carrying out second position marking on the color to be replaced;
and reading the second color value of the color to be replaced line by line according to the second position mark.
4. A color replacement method according to claim 1, wherein the matching algorithm comprises: a regular expression.
5. A color replacement method according to claim 1, characterized in that the method further comprises: and converting all the read first color values into red, green and blue RGB values, and storing the red, green and blue RGB values into a preset array.
6. The color replacement method according to claim 5, wherein comparing the currently read second color value with the plurality of first color values one by one comprises:
converting all RGB values in the array into first Hue Saturation Value (HSV) values, and converting currently read second color values into second HSV values;
comparing the first HSV value to the second HSV value.
7. A color replacement method according to claim 5, characterized in that the method further comprises: and determining a first color value corresponding to the first HSV value with the minimum difference with the current second HSV value as the first color value with the minimum color difference with the currently read second color value.
8. A color replacement method according to claim 1, characterized in that the method further comprises: and reading the second color value of each line of color in the color file to be replaced line by line, determining whether the line of color needs to be replaced line by line, and performing color replacement when the line of color needs to be replaced is determined until the last line of color in the color file to be replaced finishes determining operation or replacing operation.
9. A color replacement apparatus comprising a processor and a computer-readable storage medium having instructions stored thereon, wherein the instructions, when executed by the processor, implement the color replacement method of any one of claims 1-8.
CN201910955279.1A 2019-10-09 2019-10-09 Color replacement method and device Active CN110719382B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910955279.1A CN110719382B (en) 2019-10-09 2019-10-09 Color replacement method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910955279.1A CN110719382B (en) 2019-10-09 2019-10-09 Color replacement method and device

Publications (2)

Publication Number Publication Date
CN110719382A CN110719382A (en) 2020-01-21
CN110719382B true CN110719382B (en) 2021-11-16

Family

ID=69212374

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910955279.1A Active CN110719382B (en) 2019-10-09 2019-10-09 Color replacement method and device

Country Status (1)

Country Link
CN (1) CN110719382B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112269574A (en) * 2020-11-03 2021-01-26 北京字跳网络技术有限公司 Replacement method, storage method, device, electronic equipment and storage medium
CN114968466A (en) * 2022-07-14 2022-08-30 深圳市明源云空间电子商务有限公司 Page color matching adjustment method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104349159A (en) * 2013-08-05 2015-02-11 鸿富锦精密工业(深圳)有限公司 Screen test system and method
CN104572911A (en) * 2014-12-26 2015-04-29 浙江理工大学 Pre-spinning-colored fiber color testing and matching method
CN106157290A (en) * 2015-04-20 2016-11-23 金泰线业(上海)有限公司 A kind of method for color matching and system
CN106780648A (en) * 2016-12-15 2017-05-31 北京金山软件有限公司 A kind of dynamic mapping method and device of color of image

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0560616A (en) * 1991-09-05 1993-03-12 Matsushita Electric Ind Co Ltd Method and apparatus for discriminating color
JP2005260378A (en) * 2004-03-09 2005-09-22 Matsushita Electric Ind Co Ltd Color image processor and color image forming apparatus provided with the same, and color image processing method
JP4686496B2 (en) * 2007-03-30 2011-05-25 株式会社東芝 Imaging device
CN107627969B (en) * 2017-09-25 2020-10-02 奇瑞汽车股份有限公司 Method and device for changing color of vehicle body and computer storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104349159A (en) * 2013-08-05 2015-02-11 鸿富锦精密工业(深圳)有限公司 Screen test system and method
CN104572911A (en) * 2014-12-26 2015-04-29 浙江理工大学 Pre-spinning-colored fiber color testing and matching method
CN106157290A (en) * 2015-04-20 2016-11-23 金泰线业(上海)有限公司 A kind of method for color matching and system
CN106780648A (en) * 2016-12-15 2017-05-31 北京金山软件有限公司 A kind of dynamic mapping method and device of color of image

Also Published As

Publication number Publication date
CN110719382A (en) 2020-01-21

Similar Documents

Publication Publication Date Title
CN101658024B (en) Methods and systems for displays with chromatic correction with differing chromatic ranges
CN103559864B (en) The bright chroma bearing calibration of LED display module
US20040240749A1 (en) Image processing device, image processing method, and program
US20220245775A1 (en) Tone mapping method and electronic device
KR20170107487A (en) Metadata-based image processing method and apparatus
CN110719382B (en) Color replacement method and device
WO2018149253A1 (en) Image processing method and device
KR20070090224A (en) Method of electronic color image saturation processing
CN1984281A (en) Method and apparatus for generating illumination characteristic data
CN107257990A (en) By method and apparatus of the HDR version conversion of picture for the standard dynamic range version of the picture
CN113053324A (en) Backlight control method, device, equipment, system and storage medium
WO2020119454A1 (en) Method and apparatus for color reproduction of image
CN115083303A (en) Method, medium and device for correcting spatial color of LED display screen under mobile visual angle
US8509529B2 (en) Color-image representative color decision apparatus and method of controlling operation thereof
JP6907748B2 (en) Color adjusters, color processing methods, color processing systems and programs
CN111242836B (en) Target image generation method, device and equipment for generating advertisement image
JP4361129B2 (en) Video signal monitoring apparatus and method
US10574958B2 (en) Display apparatus and recording medium
CN107341770A (en) Dynamic range expansion highlight information recovers
CN111586376A (en) Shooting method, device and equipment
CN111048034A (en) Control device and method for automatically lighting LED screen
Tódová et al. Wide Gamut Moment‐based Constrained Spectral Uplifting
CN110896473A (en) Detection method and system for display interface switching function
CN113239770B (en) Financial statement accounting method
CN115965848B (en) Image processing method and related device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant