CN114882125A - Method and device for graying image data, terminal device and readable storage medium - Google Patents
Method and device for graying image data, terminal device and readable storage medium Download PDFInfo
- Publication number
- CN114882125A CN114882125A CN202110162145.1A CN202110162145A CN114882125A CN 114882125 A CN114882125 A CN 114882125A CN 202110162145 A CN202110162145 A CN 202110162145A CN 114882125 A CN114882125 A CN 114882125A
- Authority
- CN
- China
- Prior art keywords
- pixel
- image data
- processed
- grayscale
- value
- 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.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/90—Determination of colour characteristics
Landscapes
- Engineering & Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Image Processing (AREA)
Abstract
本申请适用于图像处理技术领域,提供了一种图像数据的灰度化方法、装置、终端设备及可读存储介质,方法包括:确定待处理图像数据的灰度转化系数、像素值和色彩对比度之间的第一关系,确定待处理图像数据中的多个像素对的像素值和色彩对比度,根据第一关系、多个像素对的像素值和色彩对比度确定灰度转化系数,根据灰度转化系数对待处理图像数据进行灰度转化,获得目标灰度图像数据。通过待处理图像数据中多个像素对的像素值和色彩对比度,计算获得转化系数并对待处理图像系数进行灰度转化,获得目标灰度图像数据,计算量小,同时使得转化后的目标灰度图像数据能够保留待处理图像数据的对比度信息,提高了灰度转化效率及目标灰度图像数据的质量。
The present application is applicable to the technical field of image processing, and provides a grayscale method, device, terminal device and readable storage medium for image data. The method includes: determining a grayscale conversion coefficient, pixel value and color contrast of the image data to be processed The first relationship between, determine the pixel value and color contrast of multiple pixel pairs in the image data to be processed, determine the grayscale conversion coefficient according to the first relationship, the pixel value and color contrast of the multiple pixel pairs, and determine the grayscale conversion coefficient according to the grayscale conversion. The coefficients perform grayscale transformation on the image data to be processed to obtain target grayscale image data. Through the pixel values and color contrasts of multiple pixel pairs in the image data to be processed, the conversion coefficients are calculated and obtained, and the grayscale conversion of the image coefficients to be processed is performed to obtain the target grayscale image data. The amount of calculation is small, and the converted target grayscale The image data can retain the contrast information of the image data to be processed, thereby improving the grayscale conversion efficiency and the quality of the target grayscale image data.
Description
技术领域technical field
本申请属于图像处理技术领域,尤其涉及一种图像数据的灰度化方法、装置、终端设备及可读存储介质。The present application belongs to the technical field of image processing, and in particular, relates to a grayscale method, apparatus, terminal device and readable storage medium for image data.
背景技术Background technique
在图像应用技术中,图像灰度化技术是一种常用手段,灰度图像常应用于数字打印、照片渲染等领域。In image application technology, image grayscale technology is a common method, and grayscale images are often used in digital printing, photo rendering and other fields.
现有的图像灰度化技术通常无法保留原图像数据的对比度,导致转换后的灰度图像存在信息丢失的问题。Existing image grayscale techniques usually cannot preserve the contrast of the original image data, resulting in the problem of information loss in the converted grayscale image.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供了一种图像数据的灰度化方法、装置、终端设备及可读存储介质,可以解决现有的图像灰度化技术无法保留原图像数据的对比度,导致转换后的灰度图像存在信息丢失的问题。The embodiments of the present application provide a grayscale method, device, terminal device, and readable storage medium for image data, which can solve the problem that the existing image grayscale technology cannot preserve the contrast of the original image data, resulting in the converted grayscale The image suffers from loss of information.
第一方面,本申请实施例提供了一种图像数据的灰度化方法,包括:In a first aspect, an embodiment of the present application provides a grayscale method for image data, including:
确定待处理图像数据的灰度转化系数、像素值和色彩对比度之间的第一关系;determining the first relationship between the grayscale conversion coefficient, pixel value and color contrast of the image data to be processed;
确定所述待处理图像数据中的多个像素对的像素值和色彩对比度;其中,所述像素对包括图像块对或像素点对;determining pixel values and color contrasts of a plurality of pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs;
根据所述第一关系、所述像素值和所述色彩对比度确定灰度转化系数;determining a grayscale conversion coefficient according to the first relationship, the pixel value, and the color contrast;
根据所述灰度转化系数对所述待处理图像数据进行灰度转化,获得目标灰度图像数据。Perform grayscale conversion on the to-be-processed image data according to the grayscale conversion coefficient to obtain target grayscale image data.
在一个实施例中,所述根据所述灰度转化系数对所述待处理图像数据进行灰度转化,获得目标灰度图像数据,包括:In one embodiment, performing grayscale conversion on the to-be-processed image data according to the grayscale conversion coefficient to obtain target grayscale image data includes:
根据所述灰度转化系数确定所述待处理图像数据中的预设像素点的灰度值;Determine the grayscale value of the preset pixel point in the image data to be processed according to the grayscale conversion coefficient;
根据所述灰度值确定所述待处理图像数据对应的目标灰度图像数据。The target grayscale image data corresponding to the to-be-processed image data is determined according to the grayscale value.
在一个实施例中,所述确定所述待处理图像数据中的多个像素对的像素值和色彩对比度,包括:In one embodiment, the determining pixel values and color contrasts of multiple pixel pairs in the image data to be processed includes:
选取所述待处理图像数据中的多个图像块,并根据所述多个图像块构建多个图像块对;Selecting multiple image blocks in the image data to be processed, and constructing multiple image block pairs according to the multiple image blocks;
根据每个图像块中所有像素点的像素值,计算获得每个图像块对的像素值和色彩对比度。According to the pixel values of all pixels in each image block, the pixel value and color contrast of each image block pair are obtained by calculation.
在一个实施例中,所述根据每个图像块中所有像素点的像素值,计算获得每个图像块对的像素值和色彩对比度,包括:In one embodiment, calculating and obtaining the pixel value and color contrast of each image block pair according to the pixel values of all pixels in each image block includes:
根据每个图像块中所有像素点的RGB三通道像素值,分别计算获得每个图像块在RGB三通道的像素平均值,作为每个图像块的RGB三通道像素值;According to the RGB three-channel pixel values of all pixels in each image block, calculate and obtain the pixel average value of each image block in the RGB three-channel respectively, as the RGB three-channel pixel value of each image block;
根据每个图像块中所有像素点的Lab三通道像素值,分别计算获得每个图像块在Lab三通道的像素平均值,作为每个图像块的Lab三通道像素值;According to the Lab three-channel pixel values of all pixels in each image block, calculate and obtain the pixel average value of each image block in the Lab three-channel, as the Lab three-channel pixel value of each image block;
根据每个图像块对中每个图像块的Lab三通道像素值,计算确定对应每个图像块对的色彩对比度。According to the Lab three-channel pixel value of each image block in each image block pair, the color contrast corresponding to each image block pair is calculated and determined.
在一个实施例中,所述确定所述待处理图像数据中的多个像素对的像素值和色彩对比度,还包括:In one embodiment, the determining pixel values and color contrasts of multiple pixel pairs in the image data to be processed further includes:
选取所述待处理图像数据中的多个像素点,并根据所述多个像素点构建多个像素点对;Selecting a plurality of pixel points in the image data to be processed, and constructing a plurality of pixel point pairs according to the plurality of pixel points;
确定每个像素点对的RGB三通道像素值和色彩对比度。Determine the RGB three-channel pixel value and color contrast for each pixel pair.
在一个实施例中,所述根据所述第一关系、所述像素值和所述色彩对比度确定灰度转化系数,包括:In one embodiment, the determining a grayscale conversion coefficient according to the first relationship, the pixel value and the color contrast includes:
将所述多个像素对的RGB三通道像素值和色彩对比度代入所述第一关系,获得灰度转化系数矩阵;Substitute the RGB three-channel pixel value and color contrast of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix;
根据所述多个像素对的像素值和色彩对比度计算获得灰度转化系数矩阵的最小二乘解,作为所述灰度转化系数。The least squares solution of the grayscale conversion coefficient matrix is obtained by calculation according to the pixel values of the plurality of pixel pairs and the color contrast, as the grayscale conversion coefficient.
在一个实施例中,所述确定待处理图像数据的灰度转化系数、像素值和色彩对比度之间的第一关系,包括:In one embodiment, the determining the first relationship between the grayscale conversion coefficient, the pixel value and the color contrast of the image data to be processed includes:
根据所述待处理图像数据的第二关系和第三关系,确定所述第一关系;其中,第二关系为灰度值与所述色彩对比度之间的关系,所述第三关系为所述灰度转化系数、所述像素值和所述灰度值之间的关系。The first relationship is determined according to the second relationship and the third relationship of the image data to be processed; wherein, the second relationship is the relationship between the gray value and the color contrast, and the third relationship is the The relationship between the grayscale conversion coefficient, the pixel value, and the grayscale value.
第二方面,本申请实施例提供了一种图像数据的灰度化装置,包括:In a second aspect, an embodiment of the present application provides a grayscale device for image data, including:
第一确定模块,用于确定待处理图像数据的灰度转化系数、像素值和色彩对比度之间的第一关系;a first determination module, configured to determine the first relationship between the grayscale conversion coefficient, pixel value and color contrast of the image data to be processed;
第二确定模块,用于确定所述待处理图像数据中的多个像素对的像素值和色彩对比度;其中,所述像素对包括图像块对或像素点对;a second determination module, configured to determine pixel values and color contrasts of a plurality of pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs;
第三确定模块,用于根据所述第一关系、所述像素值和所述色彩对比度确定灰度转化系数;a third determining module, configured to determine a grayscale conversion coefficient according to the first relationship, the pixel value and the color contrast;
转化模块,用于根据所述灰度转化系数对所述待处理图像数据进行灰度转化,获得目标灰度图像数据。A conversion module, configured to perform grayscale conversion on the to-be-processed image data according to the grayscale conversion coefficient to obtain target grayscale image data.
在一个实施例中,所述转化模块,包括:In one embodiment, the conversion module includes:
转化单元,用于根据所述灰度转化系数确定所述待处理图像数据中的预设像素点的灰度值;a conversion unit, configured to determine the grayscale value of a preset pixel point in the to-be-processed image data according to the grayscale conversion coefficient;
遍历单元,用于根据所述灰度值确定所述待处理图像数据对应的目标灰度图像数据。A traversing unit, configured to determine target grayscale image data corresponding to the to-be-processed image data according to the grayscale value.
在一个实施例中,所述第二确定模块,包括:In one embodiment, the second determining module includes:
第一选取单元,用于选取所述待处理图像数据中的多个图像块,并根据所述多个图像块构建多个图像块对;a first selection unit, configured to select multiple image blocks in the image data to be processed, and construct multiple image block pairs according to the multiple image blocks;
第一计算单元,用于根据每个图像块中所有像素点的像素值,计算获得每个图像块对的像素值和色彩对比度。The first calculation unit is configured to calculate and obtain the pixel value and color contrast of each image block pair according to the pixel values of all pixel points in each image block.
在一个实施例中,所述第一计算单元,包括:In one embodiment, the first computing unit includes:
第一计算子单元,用于根据每个图像块中所有像素点的RGB三通道像素值,分别计算获得每个图像块在RGB三通道的像素平均值,作为每个图像块的RGB三通道像素值;The first calculation subunit is used to calculate and obtain the pixel average value of each image block in the RGB three channels according to the RGB three-channel pixel values of all pixels in each image block, as the RGB three-channel pixel of each image block. value;
第二计算子单元,用于根据每个图像块中所有像素点的Lab三通道像素值,分别计算获得每个图像块在Lab三通道的像素平均值,作为每个图像块的Lab三通道像素值;The second calculation subunit is used to calculate and obtain the pixel average value of each image block in the Lab three channels according to the Lab three-channel pixel values of all pixels in each image block, as the Lab three-channel pixels of each image block. value;
第三计算子单元,用于根据每个图像块对中每个图像块的Lab三通道像素值,计算确定对应每个图像块对的色彩对比度。The third calculation subunit is configured to calculate and determine the color contrast corresponding to each image block pair according to the Lab three-channel pixel value of each image block pair in each image block pair.
在一个实施例中,所述第二确定模块,包括:In one embodiment, the second determining module includes:
第二选取单元,用于选取所述待处理图像数据中的多个像素点,并根据所述多个像素点构建多个像素点对;a second selection unit, configured to select a plurality of pixel points in the to-be-processed image data, and construct a plurality of pixel point pairs according to the plurality of pixel points;
确定单元,用于确定每个像素点对的RGB三通道像素值和色彩对比度。The determining unit is used to determine the RGB three-channel pixel value and color contrast of each pixel pair.
在一个实施例中,所述第三确定模块,包括:In one embodiment, the third determining module includes:
第二计算单元,用于将所述多个像素对的RGB三通道像素值和色彩对比度代入所述第一关系,获得灰度转化系数矩阵;a second calculation unit, configured to substitute the RGB three-channel pixel values and color contrasts of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix;
第三计算单元,用于根据所述多个像素对的像素值和色彩对比度计算获得灰度转化系数矩阵的最小二乘解,作为所述灰度转化系数。The third calculation unit is configured to calculate and obtain the least squares solution of the grayscale conversion coefficient matrix according to the pixel values of the plurality of pixel pairs and the color contrast, as the grayscale conversion coefficient.
在一个实施例中,所述确定模块,包括:In one embodiment, the determining module includes:
确定单元,用于根据所述待处理图像数据的第二关系和第三关系,确定所述第一关系;其中,第二关系为灰度值与所述色彩对比度之间的关系,所述第三关系为所述灰度转化系数、所述像素值和所述灰度值之间的关系。a determining unit, configured to determine the first relationship according to the second relationship and the third relationship of the image data to be processed; wherein, the second relationship is the relationship between the gray value and the color contrast, and the first relationship The three relationships are the relationship between the grayscale conversion coefficient, the pixel value, and the grayscale value.
第三方面,本申请实施例提供了一种终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如上述第一方面中任一项所述的图像数据的灰度化方法。In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, when the processor executes the computer program The grayscale method for image data according to any one of the above first aspects is implemented.
第四方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如上述第一方面中任一项所述的图像数据的灰度化方法。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any one of the above-mentioned first aspects is implemented. The grayscale method of the image data described above.
第五方面,本申请实施例提供了一种计算机程序产品,当计算机程序产品在终端设备上运行时,使得终端设备执行上述第一方面中任一项所述的图像数据的灰度化方法。In a fifth aspect, an embodiment of the present application provides a computer program product that, when the computer program product runs on a terminal device, enables the terminal device to execute the grayscale method for image data according to any one of the first aspects above.
通过待处理图像数据中多个像素对的像素值和色彩对比度,计算获得灰度转化系数,并根据灰度转化系数对待处理图像系数进行灰度转化,获得目标灰度图像数据,计算量小,同时使得转化后的目标灰度图像数据能够保留待处理图像数据的对比度信息,提高了灰度转化效率及目标灰度图像数据的质量。Through the pixel value and color contrast of multiple pixel pairs in the image data to be processed, the grayscale conversion coefficient is calculated and obtained, and the grayscale conversion is performed on the coefficient of the image to be processed according to the grayscale conversion coefficient to obtain the target grayscale image data. The amount of calculation is small, At the same time, the converted target grayscale image data can retain the contrast information of the to-be-processed image data, thereby improving the grayscale conversion efficiency and the quality of the target grayscale image data.
可以理解的是,上述第二方面至第五方面的有益效果可以参见上述第一方面中的相关描述,在此不再赘述。It can be understood that, for the beneficial effects of the second aspect to the fifth aspect, reference may be made to the relevant description in the first aspect, which is not repeated here.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only for the present application. In some embodiments, for those of ordinary skill in the art, other drawings can also be obtained according to these drawings without any creative effort.
图1是本申请实施例提供的图像数据的灰度化方法的流程示意图;1 is a schematic flowchart of a grayscale method for image data provided by an embodiment of the present application;
图2是本申请实施例提供的图像数据的灰度化方法的步骤S104的流程示意图;2 is a schematic flowchart of step S104 of the grayscale method for image data provided by an embodiment of the present application;
图3是本申请实施例提供的图像数据的灰度化方法的步骤S102的流程示意图;3 is a schematic flowchart of step S102 of the grayscale method for image data provided by an embodiment of the present application;
图4是本申请实施例提供的图像数据的灰度化方法的步骤S1022的流程示意图;4 is a schematic flowchart of step S1022 of the grayscale method for image data provided by an embodiment of the present application;
图5是本申请实施例提供的图像数据的灰度化方法的步骤S102的另一流程示意图;5 is another schematic flowchart of step S102 of the grayscale method for image data provided by an embodiment of the present application;
图6(a)、6(b)、6(c)是本申请实施例提供的基于不同图像灰度化方法获得的灰度图像数据的示意图;6(a), 6(b), and 6(c) are schematic diagrams of grayscale image data obtained based on different image grayscale methods provided by the embodiments of the present application;
图7是本申请实施例提供的图像数据的灰度化装置的结构示意图;7 is a schematic structural diagram of a grayscale device for image data provided by an embodiment of the present application;
图8是本申请实施例提供的终端设备的结构示意图。FIG. 8 is a schematic structural diagram of a terminal device provided by an embodiment of the present application.
具体实施方式Detailed ways
以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。然而,本领域的技术人员应当清楚,在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中,省略对众所周知的系统、装置、电路以及方法的详细说明,以免不必要的细节妨碍本申请的描述。In the following description, for the purpose of illustration rather than limitation, specific details such as a specific system structure and technology are set forth in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be practiced in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
应当理解,当在本申请说明书和所附权利要求书中使用时,术语“包括”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。It is to be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described feature, integer, step, operation, element and/or component, but does not exclude one or more other The presence or addition of features, integers, steps, operations, elements, components and/or sets thereof.
还应当理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。It will also be understood that, as used in this specification and the appended claims, the term "and/or" refers to and including any and all possible combinations of one or more of the associated listed items.
如在本申请说明书和所附权利要求书中所使用的那样,术语“如果”可以依据上下文被解释为“当...时”或“一旦”或“响应于确定”或“响应于检测到”。类似地,短语“如果确定”或“如果检测到[所描述条件或事件]”可以依据上下文被解释为意指“一旦确定”或“响应于确定”或“一旦检测到[所描述条件或事件]”或“响应于检测到[所描述条件或事件]”。As used in the specification of this application and the appended claims, the term "if" may be contextually interpreted as "when" or "once" or "in response to determining" or "in response to detecting ". Similarly, the phrases "if it is determined" or "if the [described condition or event] is detected" may be interpreted, depending on the context, to mean "once it is determined" or "in response to the determination" or "once the [described condition or event] is detected. ]" or "in response to detection of the [described condition or event]".
另外,在本申请说明书和所附权利要求书的描述中,术语“第一”、“第二”、“第三”等仅用于区分描述,而不能理解为指示或暗示相对重要性。In addition, in the description of the specification of the present application and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the description, and should not be construed as indicating or implying relative importance.
在本申请说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。References in this specification to "one embodiment" or "some embodiments" and the like mean that a particular feature, structure or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in other embodiments," etc. in various places in this specification are not necessarily All refer to the same embodiment, but mean "one or more but not all embodiments" unless specifically emphasized otherwise. The terms "including", "including", "having" and their variants mean "including but not limited to" unless specifically emphasized otherwise.
本申请实施例提供的图像数据的灰度化方法可以应用于手机、平板电脑、笔记本电脑等终端设备上,本申请实施例对终端设备的具体类型不作任何限制。The grayscale method for image data provided by the embodiments of the present application may be applied to terminal devices such as mobile phones, tablet computers, and notebook computers, and the embodiments of the present application do not impose any restrictions on specific types of terminal devices.
图1示出了本申请提供的图像数据的灰度化方法的示意性流程图,作为示例而非限定,该方法可以应用于上述笔记本电脑中。FIG. 1 shows a schematic flow chart of a grayscale method for image data provided by the present application. As an example but not a limitation, the method can be applied to the above-mentioned notebook computer.
S101、确定待处理图像数据的灰度转化系数、像素值和色彩对比度之间的第一关系。S101. Determine a first relationship among grayscale conversion coefficients, pixel values, and color contrasts of the image data to be processed.
在具体应用中,可根据待处理图像数据中像素点对的像素值和转化系数确定获得灰度值,并根据像素点对的灰度值确定对应的色彩对比度,进而确定灰度转化系数、像素值和色彩对比度之间的第一关系。像素点对是指在待处理图像数据中位于不同位置的一对像素点。In specific applications, the gray value can be determined and obtained according to the pixel value and conversion coefficient of the pixel pair in the image data to be processed, and the corresponding color contrast can be determined according to the gray value of the pixel pair, and then the gray conversion coefficient, pixel value can be determined. The first relationship between value and color contrast. A pixel point pair refers to a pair of pixel points located at different positions in the image data to be processed.
其中,待处理图像数据是指需进行灰度化处理的真实的图像数据。可以理解的是,在图像灰度化过程中,需要分别确定R、G、B三个通道对应转化系数WR、WG、WB,进而对待处理图像数据中像素点的RGB三通道进行灰度转化。The image data to be processed refers to the real image data that needs to be processed in grayscale. It can be understood that in the process of image grayscale, it is necessary to determine the corresponding conversion coefficients WR, WG, and WB of the three channels R , G , and B respectively, and then gray the RGB three channels of the pixels in the image data to be processed. degree conversion.
在一个实施例中,所述步骤S101,包括:In one embodiment, the step S101 includes:
根据所述待处理图像数据的第二关系和第三关系,确定所述第一关系;其中,第二关系为灰度值与所述色彩对比度之间的关系,所述第三关系为所述灰度转化系数、所述像素值和所述灰度值之间的关系。The first relationship is determined according to the second relationship and the third relationship of the image data to be processed; wherein, the second relationship is the relationship between the gray value and the color contrast, and the third relationship is the The relationship between the grayscale conversion coefficient, the pixel value, and the grayscale value.
在具体应用中,为使转化后的目标灰度图像数据尽可能多的保留待处理图像数据的色彩对比度,设定转化目标为:使待处理图像数据像素点对间的色彩对比度最小,进而可以确定像素点对的灰度值与色彩对比度之间的第二关系表示为:In a specific application, in order to keep the color contrast of the image data to be processed as much as possible in the converted target grayscale image data, the conversion target is set as: the color contrast between the pixel pairs of the image data to be processed is minimized, and then the color contrast between the pixel pairs of the image data to be processed can be minimized The second relationship between the gray value of the pixel pair and the color contrast is determined as:
min∑x,y(gx-gy-δx,y)2;公式(1)min∑ x,y (g x -g y -δ x,y ) 2 ; formula (1)
在实际应用中,像素点的灰度值是根据三通道转化系数分别对像素点的RGB三个通道的像素值进行灰度转化确定的,因此,可确定第三关系表示为:In practical applications, the gray value of a pixel is determined by gray-scale conversion of the pixel values of the three RGB channels of the pixel according to the three-channel conversion coefficient. Therefore, it can be determined that the third relationship is expressed as:
式中,x,y表示待处理图像数据中的一对像素点,gx表示待处理图像数据中像素点x的灰度值,gy表示待处理图像数据中像素点y的灰度值,δx,y表示对应的色彩对比度;WR、WG、WB分别表示RGB三通道的转化系数,Rx、Gx、Bx分别表示待处理图像数据中像素点x的R、G、B三个通道的像素值,Ry、Gy、By分别表待处理图像数据中像素点y的R、G、B三个通道的像素值。In the formula, x and y represent a pair of pixel points in the image data to be processed, g x represents the gray value of the pixel point x in the image data to be processed, g y represents the gray value of the pixel point y in the image data to be processed, δ x, y represents the corresponding color contrast; W R , W G , and W B represent the conversion coefficients of the three RGB channels, respectively, and R x , G x , and B x represent the R, G, The pixel values of the three channels of B, R y , G y , and By represent the pixel values of the three channels of R, G, and B of the pixel point y in the image data to be processed, respectively.
在具体应用中,通过将灰度转化系数、像素值和灰度值之间的第三关系代入灰度值与色彩对比度间的第二关系,令第二关系的多项式等于0,可得到:In a specific application, by substituting the third relationship between the grayscale conversion coefficient, pixel value and grayscale value into the second relationship between grayscale value and color contrast, and setting the polynomial of the second relationship equal to 0, it can be obtained:
WR·Rx+WG·Gx+WB·Bx-(WR·Ry+WG·Gy+WB·By)=δx,y;公式(3)W R R x +W G G x +W B B x -(W R R y +W G G y +W B B y )=δ x,y ; Equation (3)
通过对公式(3)进行整理获得:By arranging formula (3), we can obtain:
WR·(Rx-Ry)+WG·(Gx-Gy)+WB·(Bx-By)=δx,y;公式(4)W R ·(R x -R y )+W G ·(G x -G y )+W B ·(B x -B y )=δ x,y ; formula (4)
令IR=Rx-Ry、IG=Gx-Gy、IB=Bx-By,得到灰度转化系数、像素值和色彩对比度之间的第一关系:Let I R =R x -R y , IG = G x -G y , I B =B x -B y , obtain the first relationship between grayscale conversion coefficient, pixel value and color contrast:
WR·IR+WG·IG+WB·IB=δx,y;公式(5)。W R · I R + W G · I G + W B · I B = δ x,y ; formula (5).
其中,像素点对的色彩对比度,可通过下式获得:Among them, the color contrast of the pixel pair can be obtained by the following formula:
式中,Lx表示待处理图像数据中像素点x的L通道像素值,ax表示待处理图像数据中像素点x的a通道像素值,bx表示待处理图像数据中像素点x的b通道像素值;Ly表示待处理图像数据中像素点y的L通道像素值,ay表示待处理图像数据中像素点y的a通道像素值,by表示待处理图像数据中像素点y的b通道像素值。In the formula, L x represents the L channel pixel value of the pixel x in the image data to be processed, a x represents the a channel pixel value of the pixel x in the image data to be processed, b x represents the b of the pixel x in the image data to be processed Channel pixel value; Ly represents the L channel pixel value of the pixel point y in the image data to be processed, a y represents the a channel pixel value of the pixel point y in the image data to be processed, and b y represents the pixel point y in the image data to be processed. b channel pixel value.
S102、确定所述待处理图像数据中的多个像素对的像素值和色彩对比度;其中,所述像素对包括图像块对或像素点对。S102. Determine pixel values and color contrasts of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs.
在具体应用中,通过选取待处理图像数据中的多个像素对(像素对包括但不限于图像块对或像素点对),根据多个像素对的像素值和色彩对比度可以计算确定较优的灰度转化系数,进而对待处理图想数据进行灰度转化获得目标灰度图像数据。图像块对是指在待处理图像数据中位于不同位置的一对图像块(block)。In a specific application, by selecting a plurality of pixel pairs in the image data to be processed (pixel pairs include but not limited to image block pairs or pixel point pairs), the optimal pixel value and color contrast of the plurality of pixel pairs can be calculated and determined. Grayscale conversion coefficient, and then grayscale conversion of the image data to be processed to obtain target grayscale image data. An image block pair refers to a pair of image blocks located at different positions in the image data to be processed.
S103、根据所述第一关系、所述像素值和所述色彩对比度确定灰度转化系数。S103. Determine a grayscale conversion coefficient according to the first relationship, the pixel value, and the color contrast.
在具体应用中,通过选取多个待处理图像数据中的像素对,确定多个图像素对的像素值和色彩对比度,根据多个像素对的像素值和色彩对比度将第一关系转化为灰度转化系数矩阵,进而计算获得灰度转化系数矩阵的最小二乘解,得到灰度转化系数。In a specific application, by selecting a plurality of pixel pairs in the image data to be processed, the pixel values and color contrasts of the plurality of image pixel pairs are determined, and the first relationship is converted into grayscale according to the pixel values and color contrasts of the plurality of pixel pairs. The conversion coefficient matrix is then calculated to obtain the least squares solution of the grayscale conversion coefficient matrix, and the grayscale conversion coefficient is obtained.
S104、根据所述灰度转化系数对所述待处理图像数据进行灰度转化,获得目标灰度图像数据。S104. Perform grayscale conversion on the to-be-processed image data according to the grayscale conversion coefficient to obtain target grayscale image data.
在具体应用中,通过灰度转化系数对待处理图像数据中的每个像素点进行灰度转化,获得与待处理图像数据对应的目标灰度图像数据。In a specific application, each pixel in the to-be-processed image data is gray-scaled by a gray-scale conversion coefficient to obtain target gray-scale image data corresponding to the to-be-processed image data.
如图2所示,在一个实施例中,所述步骤S104,包括:As shown in FIG. 2, in one embodiment, the step S104 includes:
S1041、根据所述灰度转化系数确定所述待处理图像数据中的预设像素点的灰度值;S1041. Determine the grayscale value of a preset pixel point in the to-be-processed image data according to the grayscale conversion coefficient;
S1042、根据所述灰度值确定所述待处理图像数据对应的目标灰度图像数据。S1042. Determine target grayscale image data corresponding to the to-be-processed image data according to the grayscale value.
在具体应用中,在确定R、G、B三个通道的转化系数时,获取待处理图像数据中的预设像素点中R、G、B三个通道的像素值,通过R、G、B三个通道的转化系数分别对预设像素点的R、G、B三通道值进行灰度转化,获得转化后该预设像素点的灰度值,根据预设像素点的灰度值,获得与待处理图像数据对应的目标灰度图像数据。In a specific application, when determining the conversion coefficients of the three channels of R, G, and B, the pixel values of the three channels of R, G, and B in the preset pixel points in the image data to be processed are obtained, and the pixel values of the three channels of R, G, and B are obtained through the R, G, B The conversion coefficients of the three channels respectively perform grayscale conversion on the R, G, and B three channel values of the preset pixel point to obtain the grayscale value of the preset pixel point after conversion, and obtain the grayscale value of the preset pixel point according to the grayscale value of the preset pixel point. Target grayscale image data corresponding to the image data to be processed.
可以理解的是,在进行灰度转化的过程中,需对待处理图像数据中的每个像素点分别进行灰度转换,因此对应设定预设像素点为待处理图像数据中的所有像素点。即:通过R、G、B三个通道的转化系数分别对待处理图像数据中的每个像素点的R、G、B三通道值进行灰度转化,获得转化后处理图像数据中的每个像素点的灰度值,进而获得与待处理图像数据对应的目标灰度图像数据。It can be understood that in the process of grayscale conversion, each pixel point in the image data to be processed needs to be grayscale converted separately, so the preset pixel points are correspondingly set as all the pixel points in the image data to be processed. That is: through the conversion coefficients of the three channels of R, G, and B, the R, G, and B three-channel values of each pixel in the image data to be processed are converted to grayscale, and each pixel in the converted image data is obtained. The grayscale value of the point is obtained, and then the target grayscale image data corresponding to the image data to be processed is obtained.
其中,通过转化系数对像素值进行灰度转化可表示为:Among them, the grayscale conversion of the pixel value through the conversion coefficient can be expressed as:
g(o,c)=WR·R(o,c)+WG·G(o,c)+WB·B(o,c)公式(7);g(o,c)=W R ·R(o,c)+W G ·G(o,c)+W B ·B(o,c) Formula (7);
式中,R(o,c)表示待处理图像数据中第o行第c列的像素点的R通道的像素值,G(o,c)表示待处理图像数据中第o行第c列的像素点的G通道的像素值,B(o,c)表示待处理图像数据中第o行第c列的像素点的B通道的像素值,g(o,c)表示转化后的第o行第c列的像素点的灰度值。In the formula, R(o,c) represents the pixel value of the R channel of the pixel in the oth row and the cth column of the image data to be processed, and G(o,c) represents the oth row and the cth column of the image data to be processed. The pixel value of the G channel of the pixel point, B(o,c) represents the pixel value of the B channel of the pixel point in the oth row and the cth column of the image data to be processed, and g(o,c) represents the converted oth row The gray value of the pixel point in the c-th column.
如图3所示,在一个实施例中,所述步骤S102,包括:As shown in FIG. 3, in one embodiment, the step S102 includes:
S1021、选取所述待处理图像数据中的多个图像块,并根据所述多个图像块构建多个图像块对;S1021, selecting multiple image blocks in the image data to be processed, and constructing multiple image block pairs according to the multiple image blocks;
S1022、根据每个图像块中所有像素点的像素值,计算获得每个图像块对的像素值和色彩对比度。S1022: Calculate and obtain the pixel value and color contrast of each image block pair according to the pixel values of all pixel points in each image block.
在具体应用中,随机选取待处理图像数据中的多个图像块,并根据多个图像块进行随机配对,构建获得多个图像块对对,识别每个图像块中所有像素点的像素值,计算每个图像块中所有像素点分别在R、G、B三通道的像素平均值,作为每个图像块R、G、B三通道的像素值;并通过计算获得每个图像块中所有像素点分别在CIELab颜色空间下L、a、b三个通道的像素平均值,作为每个图像块L、a、b三通道的像素值,根据每对图像块中每个图像块的L、a、b三通道的像素值(具体带入公式6),计算获得每个图像块对的色彩对比度。In a specific application, multiple image blocks in the image data to be processed are randomly selected, and randomly paired according to multiple image blocks to construct and obtain multiple image block pairs, and the pixel values of all pixel points in each image block are identified, Calculate the pixel average value of all pixels in each image block in the R, G, B three channels respectively, as the pixel value of each image block R, G, B three channels; and obtain all pixels in each image block through calculation The pixel average value of the three channels of L, a, and b in the CIELab color space is taken as the pixel value of the three channels of L, a, and b for each image block. The pixel values of the three channels , b (specifically brought into formula 6), and the color contrast of each image block pair is obtained by calculation.
如图4所示,在一个实施例中,所述步骤S1022,包括:As shown in FIG. 4, in one embodiment, the step S1022 includes:
S10221、根据每个图像块中所有像素点的RGB三通道像素值,分别计算获得每个图像块在RGB三通道的像素平均值,作为每个图像块的RGB三通道像素值;S10221, according to the RGB three-channel pixel values of all pixels in each image block, calculate and obtain the pixel average value of each image block in the RGB three-channel, respectively, as the RGB three-channel pixel value of each image block;
S10222、根据每个图像块中所有像素点的Lab三通道像素值,分别计算获得每个图像块在Lab三通道的像素平均值,作为每个图像块的Lab三通道像素值;S10222, according to the Lab three-channel pixel values of all pixels in each image block, calculate and obtain the pixel average value of each image block in the Lab three-channel respectively, as the Lab three-channel pixel value of each image block;
S10223、根据每个图像块对中每个图像块的Lab三通道像素值,计算确定对应每个图像块对的色彩对比度。S10223: Calculate and determine the color contrast corresponding to each image block pair according to the Lab three-channel pixel value of each image block pair in each image block pair.
在具体应用中,分别获取每个图像块中所有像素点的R、G、B三个通道的像素值,根据每个图像块中所有像素点的R、G、B三个通道的像素值,分别计算获得每个图像块中R通道的像素平均值、G通道的像素平均值及B通道的像素平均值,作为每个图像块的R、G、B三个通道的像素值;分别获取每个图像块中所有像素点在CIELab颜色空间下的L、a、b三个通道的像素值,根据每个图像块中所有像素点的L、a、b三个通道的像素值,分别计算获得每个图像块中L通道的像素平均值、a通道的像素平均值及b通道的像素平均值,作为每个图像块的L、a、b三个通道的像素值,根据每个图像块对中每个图像块的L、a、b三个通道的像素值,计算获得每个图像块对的色彩对比度。In a specific application, the pixel values of the R, G, and B channels of all pixels in each image block are obtained respectively, and according to the pixel values of the R, G, and B channels of all pixels in each image block, Calculate and obtain the pixel average value of the R channel, the pixel average value of the G channel and the pixel average value of the B channel in each image block, as the pixel values of the R, G, and B channels of each image block; The pixel values of the L, a, b channels of all pixels in each image block in the CIELab color space are calculated separately according to the pixel values of the L, a, b channels of all pixels in each image block. The pixel average value of the L channel, the pixel average value of the a channel and the pixel average value of the b channel in each image block are taken as the pixel values of the L, a and b channels of each image block. The pixel values of the L, a, and b channels of each image block are calculated to obtain the color contrast of each image block pair.
其中,图像块对x,y中R通道的像素平均值、G通道的像素平均值及B通道的像素平均值,可通过下式获得:Among them, the pixel average value of the R channel, the pixel average value of the G channel and the pixel average value of the B channel in the image block pair x, y can be obtained by the following formula:
式中,Rx,i表示待处理图像数据中图像块x中第i个像素点的R通道的像素值、Gx,i表示待处理图像数据中图像块x中第i个像素点的G通道的像素值,Bx,i表示待处理图像数据中图像块x中第i个像素点的B通道的像素值。Rx-block表示待处理图像数据中图像块x的R通道的像素平均值;Gx-block表示待处理图像数据中图像块x的G通道的像素平均值;Bx-block表示待处理图像数据中图像块x的B通道的像素平均值;对应的,待处理图像数据中图像块y的R、G、B三个通道的像素平均值Ry-block、Gy-block、By-block以及对应的图像块y的色彩对比度δx,y-block的计算方法与Rx-block、Gx-block、Bx-block的计算方法相同,在此不再赘述。In the formula, R x,i represents the pixel value of the R channel of the ith pixel in the image block x in the image data to be processed, and G x,i represents the G of the ith pixel in the image block x in the image data to be processed. The pixel value of the channel, B x,i represents the pixel value of the B channel of the ith pixel in the image block x in the image data to be processed. R x-block represents the pixel average value of the R channel of the image block x in the image data to be processed; G x-block represents the pixel average value of the G channel of the image block x in the image data to be processed; B x-block represents the image to be processed. The pixel average value of the B channel of the image block x in the data; correspondingly, the pixel average value of the R, G, and B channels of the image block y in the image data to be processed R y-block , G y-block , By- The calculation method of the color contrast δ x,y-block of the block and the corresponding image block y is the same as the calculation method of R x-block , G x-block , and B x-block , and will not be repeated here.
如图5所示,在一个实施例中,所述步骤S102,还包括:As shown in FIG. 5, in one embodiment, the step S102 further includes:
S1023、选取所述待处理图像数据中的多个像素点,并根据所述多个像素点构建多个像素点对;S1023, selecting a plurality of pixel points in the image data to be processed, and constructing a plurality of pixel point pairs according to the plurality of pixel points;
S1024、确定每个像素点对的RGB三通道像素值和色彩对比度。S1024. Determine the RGB three-channel pixel value and color contrast of each pixel pair.
在具体应用中,随机选取待处理图像数据中的多个像素点,并根据多个像素点进行随机配对,构建多个像素点对,识别每个像素点对中每个像素点的RGB三通道像素值,以及每个像素点对中每个像素点的Lab三通道像素值,并根据每个像素点对中每个像素点的Lab三通道像素值,通过上述公式6计算确定每个像素点对的色彩对比度。In a specific application, randomly select multiple pixels in the image data to be processed, and perform random pairing according to multiple pixel points to construct multiple pixel pairs, and identify the RGB three-channel of each pixel in each pixel pair. The pixel value, and the Lab three-channel pixel value of each pixel point in each pixel point pair, and according to the Lab three-channel pixel value of each pixel point in each pixel point pair, each pixel point is calculated and determined by the above formula 6 correct color contrast.
在实际应用中,由于单个像素点的像素值容易受噪声影响而不稳定,使得根据随机确定的像素点对计算获得的计算结果的精度不稳定。对应设定通过选取待处理图想数据中的图像块对,以每个图像块对中所有像素点的像素值的平均值作为每个图像块对的像素值,以每个图像块对中所有像素点色彩对比度的平均值作为每个图像块对的色彩对比度,进而根据每个图像块对的像素值和色彩对比度计算获得对应的转化系数,提高计算结果的精度和稳定性。In practical applications, since the pixel value of a single pixel point is easily affected by noise and becomes unstable, the accuracy of the calculation result obtained by the calculation of the randomly determined pixel point pair is unstable. Corresponding setting By selecting the image block pairs in the image data to be processed, the average value of the pixel values of all pixels in each image block pair is taken as the pixel value of each image block pair, and the average value of all pixel values in each image block pair The average value of the color contrast of the pixel points is used as the color contrast of each image block pair, and then the corresponding conversion coefficient is calculated and obtained according to the pixel value and color contrast of each image block pair, which improves the accuracy and stability of the calculation result.
在一个实施例中,所述步骤S103,包括:In one embodiment, the step S103 includes:
将所述多个像素对的RGB三通道像素值和色彩对比度代入所述第一关系,获得灰度转化系数矩阵;Substitute the RGB three-channel pixel value and color contrast of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix;
根据所述多个像素对的像素值和色彩对比度计算获得灰度转化系数矩阵的最小二乘解,作为所述灰度转化系数。The least squares solution of the grayscale conversion coefficient matrix is obtained by calculation according to the pixel values of the plurality of pixel pairs and the color contrast, as the grayscale conversion coefficient.
在具体应用中,通过选取多个像素对,将多个像素对的RGB三通道像素值和色彩对比度代入第一关系(即上述公式5),可获得对应的方程组,进而获得对应的灰度转化系数矩阵,根据多个像素对的像素值和色彩对比度计算获得灰度转化系数矩阵的最小二乘解,作为对应的灰度转化系数。In a specific application, by selecting multiple pixel pairs, and substituting the RGB three-channel pixel values and color contrasts of the multiple pixel pairs into the first relationship (that is, the above formula 5), the corresponding equation system can be obtained, and then the corresponding grayscale can be obtained. The conversion coefficient matrix is calculated according to the pixel values and color contrasts of multiple pixel pairs to obtain the least squares solution of the grayscale conversion coefficient matrix, which is used as the corresponding grayscale conversion coefficient.
以像素对为图像块对为例,将m个图像块对的RGB三通道像素值和色彩对比度代入第一关系,可以获得:Taking pixel pairs as image block pairs as an example, substituting the RGB three-channel pixel values and color contrasts of m image block pairs into the first relationship, we can obtain:
其中,IR-block=Rx-block-Ry-block,IG-block=Gx-block-Gy-block,IB-block=Bx-block-By-block;Wherein, IR -block =Rx -block- Ry-block , IG-block =Gx -block -Gy -block , IB-block =Bx -block -By -block ;
通过对公式(9)进行转换,获得灰度转化系数矩阵如下:By converting formula (9), the grayscale conversion coefficient matrix is obtained as follows:
令可简化获得灰度转化系数矩阵为:UV=k;make The grayscale conversion coefficient matrix can be simplified as: UV=k;
当UT·U可逆时,可根据V=(UT·U)-1UTk计算获得灰度转化系数矩阵的最小二乘解 When U T · U is invertible, the least squares solution of the grayscale conversion coefficient matrix can be obtained by calculating V=(U T · U) -1 U T k
通过随机选取多个待处理图像数据中的像素对,计算获得的灰度转化系数的稳定性更好,实现最大程度地保留待处理图像数据的对比度,使得目标灰度图像数据的对比度与待处理图像数据的对比度最为接近。By randomly selecting a plurality of pixel pairs in the image data to be processed, the stability of the calculated grayscale conversion coefficient is better, and the contrast of the image data to be processed can be preserved to the greatest extent, so that the contrast of the target grayscale image data is different from the one to be processed. The contrast of the image data is the closest.
图6示例性的提供了一种基于不同图像灰度化方法获得的灰度图像数据的示意图;6 exemplarily provides a schematic diagram of grayscale image data obtained based on different image grayscale methods;
针对相同待处理图像,图6(a)为基于像素点对的RGB三通道像素值和色彩对比度计算确定转化系数,进而通过图像灰度化获得的第一灰度图像数据;图6(b)为基于图像块对的RGB三通道像素值和色彩对比度计算确定转化系数,进而通过图像灰度化获得的目标灰度图像数据;图6(c)为基于现有灰度化方法获得的第二灰度图像数据。For the same image to be processed, Fig. 6(a) is the first grayscale image data obtained by calculating the RGB three-channel pixel value and color contrast based on the pixel point pair to determine the conversion coefficient, and then the first grayscale image data obtained by graying the image; Fig. 6(b) Determine the conversion coefficient based on the RGB three-channel pixel value and color contrast calculation based on the image block pair, and then obtain the target grayscale image data through image grayscale; Figure 6(c) is based on the existing grayscale method. Grayscale image data.
本实施例通过待处理图像数据中多个像素对的像素值和色彩对比度,计算获得灰度转化系数,并根据灰度转化系数对待处理图像系数进行灰度转化,获得目标灰度图像数据,计算量小,同时使得转化后的目标灰度图像数据能够保留待处理图像数据的对比度信息,提高了灰度转化效率及目标灰度图像数据的质量。In this embodiment, grayscale conversion coefficients are obtained by calculating the pixel values and color contrasts of multiple pixel pairs in the image data to be processed, and grayscale conversion is performed on the coefficients of the image to be processed according to the grayscale conversion coefficients to obtain target grayscale image data. At the same time, the converted target grayscale image data can retain the contrast information of the to-be-processed image data, thereby improving the grayscale conversion efficiency and the quality of the target grayscale image data.
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that the size of the sequence numbers of the steps in the above embodiments does not mean the sequence of execution, and the execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
对应于上文实施例所述的图像数据的灰度化方法,图7示出了本申请实施例提供的图像数据的灰度化装置的结构框图,为了便于说明,仅示出了与本申请实施例相关的部分。Corresponding to the grayscale method for image data described in the above embodiments, FIG. 7 shows a block diagram of the structure of the device for grayscale image data provided by the embodiment of the present application. Example relevant part.
参照图7,该图像数据的灰度化装置100包括:Referring to FIG. 7 , the
第一确定模块101,用于确定待处理图像数据的灰度转化系数、像素值和色彩对比度之间的第一关系;a
第二确定模块102,用于确定所述待处理图像数据中的多个像素对的像素值和色彩对比度;其中,所述像素对包括图像块对或像素点对;The
第三确定模块103,用于根据所述第一关系、所述像素值和所述色彩对比度确定灰度转化系数;a third determining
转化模块104,用于根据所述灰度转化系数对所述待处理图像数据进行灰度转化,获得目标灰度图像数据。The
在一个实施例中,所述转化模块104,包括:In one embodiment, the
转化单元,用于根据所述灰度转化系数确定所述待处理图像数据中的预设像素点的灰度值;a conversion unit, configured to determine the grayscale value of a preset pixel point in the to-be-processed image data according to the grayscale conversion coefficient;
遍历单元,用于根据所述灰度值确定所述待处理图像数据对应的目标灰度图像数据。A traversing unit, configured to determine target grayscale image data corresponding to the to-be-processed image data according to the grayscale value.
在一个实施例中,所述第二确定模块102,包括:In one embodiment, the second determining
第一选取单元,用于选取所述待处理图像数据中的多个图像块,并根据所述多个图像块构建多个图像块对;a first selection unit, configured to select multiple image blocks in the image data to be processed, and construct multiple image block pairs according to the multiple image blocks;
第一计算单元,用于根据每个图像块中所有像素点的像素值,计算获得每个图像块对的像素值和色彩对比度。The first calculation unit is configured to calculate and obtain the pixel value and color contrast of each image block pair according to the pixel values of all pixel points in each image block.
在一个实施例中,所述第一计算单元,包括:In one embodiment, the first computing unit includes:
第一计算子单元,用于根据每个图像块中所有像素点的RGB三通道像素值,分别计算获得每个图像块在RGB三通道的像素平均值,作为每个图像块的RGB三通道像素值;The first calculation subunit is used to calculate and obtain the pixel average value of each image block in the RGB three channels according to the RGB three-channel pixel values of all pixels in each image block, as the RGB three-channel pixel of each image block. value;
第二计算子单元,用于根据每个图像块中所有像素点的Lab三通道像素值,分别计算获得每个图像块在Lab三通道的像素平均值,作为每个图像块的Lab三通道像素值;The second calculation subunit is used to calculate and obtain the pixel average value of each image block in the Lab three channels according to the Lab three-channel pixel values of all pixels in each image block, as the Lab three-channel pixels of each image block. value;
第三计算子单元,用于根据每个图像块对中每个图像块的Lab三通道像素值,计算确定对应每个图像块对的色彩对比度。The third calculation subunit is configured to calculate and determine the color contrast corresponding to each image block pair according to the Lab three-channel pixel value of each image block pair in each image block pair.
在一个实施例中,所述第二确定模块102,包括:In one embodiment, the second determining
第二选取单元,用于选取所述待处理图像数据中的多个像素点,并根据所述多个像素点构建多个像素点对;a second selection unit, configured to select a plurality of pixel points in the to-be-processed image data, and construct a plurality of pixel point pairs according to the plurality of pixel points;
确定单元,用于确定每个像素点对的RGB三通道像素值和色彩对比度。The determining unit is used to determine the RGB three-channel pixel value and color contrast of each pixel pair.
在一个实施例中,所述第三确定模块103,包括:In one embodiment, the third determining
第二计算单元,用于将所述多个像素对的RGB三通道像素值和色彩对比度代入所述第一关系,获得灰度转化系数矩阵;a second calculation unit, configured to substitute the RGB three-channel pixel values and color contrasts of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix;
第三计算单元,用于根据所述多个像素对的像素值和色彩对比度计算获得灰度转化系数矩阵的最小二乘解,作为所述灰度转化系数。The third calculation unit is configured to calculate and obtain the least squares solution of the grayscale conversion coefficient matrix according to the pixel values of the plurality of pixel pairs and the color contrast, as the grayscale conversion coefficient.
在一个实施例中,所述确定模块101,包括:In one embodiment, the determining
确定单元,用于根据所述待处理图像数据的第二关系和第三关系,确定所述第一关系;其中,第二关系为灰度值与所述色彩对比度之间的关系,所述第三关系为所述灰度转化系数、所述像素值和所述灰度值之间的关系。a determining unit, configured to determine the first relationship according to the second relationship and the third relationship of the image data to be processed; wherein, the second relationship is the relationship between the gray value and the color contrast, and the first relationship The three relationships are the relationship between the grayscale conversion coefficient, the pixel value, and the grayscale value.
本实施例通过待处理图像数据中多个像素对的像素值和色彩对比度,计算获得灰度转化系数,并根据灰度转化系数对待处理图像系数进行灰度转化,获得目标灰度图像数据,计算量小,同时使得转化后的目标灰度图像数据能够保留待处理图像数据的对比度信息,提高了灰度转化效率及目标灰度图像数据的质量。In this embodiment, the grayscale conversion coefficients are obtained by calculating the pixel values and color contrasts of multiple pixel pairs in the image data to be processed, and grayscale conversion is performed on the coefficients of the image to be processed according to the grayscale conversion coefficients to obtain target grayscale image data. At the same time, the converted target grayscale image data can retain the contrast information of the to-be-processed image data, thereby improving the grayscale conversion efficiency and the quality of the target grayscale image data.
需要说明的是,上述装置/单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其具体功能及带来的技术效果,具体可参见方法实施例部分,此处不再赘述。It should be noted that the information exchange, execution process and other contents between the above-mentioned devices/units are based on the same concept as the method embodiments of the present application. For specific functions and technical effects, please refer to the method embodiments section. It is not repeated here.
图8为本申请一实施例提供的终端设备的结构示意图。如图8所示,该实施例的终端设备8包括:至少一个处理器80(图8中仅示出一个)处理器、存储器81以及存储在所述存储器81中并可在所述至少一个处理器80上运行的计算机程序82,所述处理器80执行所述计算机程序82时实现上述任意各个图像数据的灰度化方法实施例中的步骤。FIG. 8 is a schematic structural diagram of a terminal device provided by an embodiment of the present application. As shown in FIG. 8 , the
所述终端设备8可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。该终端设备可包括,但不仅限于,处理器80、存储器81。本领域技术人员可以理解,图8仅仅是终端设备8的举例,并不构成对终端设备8的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如还可以包括输入输出设备、网络接入设备等。The
所称处理器80可以是中央处理单元(Central Processing Unit,CPU),该处理器80还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The so-called
所述存储器81在一些实施例中可以是所述终端设备8的内部存储单元,例如终端设备8的硬盘或内存。所述存储器81在另一些实施例中也可以是所述终端设备8的外部存储设备,例如所述终端设备8上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字卡(Secure Digital,SD),闪存卡(Flash Card)等。进一步地,所述存储器81还可以既包括所述终端设备8的内部存储单元也包括外部存储设备。所述存储器81用于存储操作系统、应用程序、引导装载程序(BootLoader)、数据以及其他程序等,例如所述计算机程序的程序代码等。所述存储器81还可以用于暂时地存储已经输出或者将要输出的数据。The
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. Module completion, that is, dividing the internal structure of the device into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment may be integrated in one processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit, and the above-mentioned integrated units may adopt hardware. It can also be realized in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing from each other, and are not used to limit the protection scope of the present application. For the specific working processes of the units and modules in the above-mentioned system, reference may be made to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现可实现上述各个方法实施例中的步骤。Embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps in the foregoing method embodiments can be implemented.
本申请实施例提供了一种计算机程序产品,当计算机程序产品在移动终端上运行时,使得移动终端执行时实现可实现上述各个方法实施例中的步骤。The embodiments of the present application provide a computer program product, when the computer program product runs on a mobile terminal, the steps in the foregoing method embodiments can be implemented when the mobile terminal executes the computer program product.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质至少可以包括:能够将计算机程序代码携带到拍照装置/终端设备的任何实体或装置、记录介质、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,RandomAccess Memory)、电载波信号、电信信号以及软件分发介质。例如U盘、移动硬盘、磁碟或者光盘等。在某些司法管辖区,根据立法和专利实践,计算机可读介质不可以是电载波信号和电信信号。The integrated unit, if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a computer-readable storage medium. Based on this understanding, the present application realizes all or part of the processes in the methods of the above embodiments, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When executed by a processor, the steps of each of the above method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file or some intermediate form, and the like. The computer-readable medium may include at least: any entity or device capable of carrying the computer program code to the photographing device/terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), electrical carrier signal, telecommunication signal, and software distribution medium. For example, U disk, mobile hard disk, disk or CD, etc. In some jurisdictions, under legislation and patent practice, computer readable media may not be electrical carrier signals and telecommunications signals.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。In the foregoing embodiments, the description of each embodiment has its own emphasis. For parts that are not described or described in detail in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each particular application, but such implementations should not be considered beyond the scope of this application.
在本申请所提供的实施例中,应该理解到,所揭露的装置/网络设备和方法,可以通过其它的方式实现。例如,以上所描述的装置/网络设备实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通讯连接可以是通过一些接口,装置或单元的间接耦合或通讯连接,可以是电性,机械或其它的形式。In the embodiments provided in this application, it should be understood that the disclosed apparatus/network device and method may be implemented in other manners. For example, the apparatus/network device embodiments described above are only illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units. Or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the above-mentioned embodiments, those of ordinary skill in the art should understand that: it can still be used for the above-mentioned implementations. The technical solutions described in the examples are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions in the embodiments of the application, and should be included in the within the scope of protection of this application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110162145.1A CN114882125A (en) | 2021-02-05 | 2021-02-05 | Method and device for graying image data, terminal device and readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110162145.1A CN114882125A (en) | 2021-02-05 | 2021-02-05 | Method and device for graying image data, terminal device and readable storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN114882125A true CN114882125A (en) | 2022-08-09 |
Family
ID=82667900
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110162145.1A Pending CN114882125A (en) | 2021-02-05 | 2021-02-05 | Method and device for graying image data, terminal device and readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114882125A (en) |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115100081A (en) * | 2022-08-24 | 2022-09-23 | 深圳佳弟子科技有限公司 | LCD display screen gray scale image enhancement method, device, equipment and storage medium |
| CN116993611A (en) * | 2023-07-28 | 2023-11-03 | 重庆赛力斯新能源汽车设计院有限公司 | Image loading method and device, electronic equipment and readable storage medium |
| CN117522760A (en) * | 2023-11-13 | 2024-02-06 | 书行科技(北京)有限公司 | Image processing method, device, electronic equipment, medium and product |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20090278982A1 (en) * | 2006-05-15 | 2009-11-12 | Takumi Imai | Color image display device and color conversion device |
| CN108765501A (en) * | 2018-04-16 | 2018-11-06 | 深圳技术大学(筹) | A kind of image gray processing method and storage medium |
| CN109993690A (en) * | 2019-03-19 | 2019-07-09 | 西安工程大学 | A high-precision grayscale method for color images based on structural similarity |
| CN111275696A (en) * | 2020-02-10 | 2020-06-12 | 腾讯科技(深圳)有限公司 | A kind of medical image processing method, image processing method and device |
| CN112085755A (en) * | 2020-09-14 | 2020-12-15 | 贝壳技术有限公司 | Object contour detection method, device and equipment and storage medium |
-
2021
- 2021-02-05 CN CN202110162145.1A patent/CN114882125A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20090278982A1 (en) * | 2006-05-15 | 2009-11-12 | Takumi Imai | Color image display device and color conversion device |
| CN108765501A (en) * | 2018-04-16 | 2018-11-06 | 深圳技术大学(筹) | A kind of image gray processing method and storage medium |
| CN109993690A (en) * | 2019-03-19 | 2019-07-09 | 西安工程大学 | A high-precision grayscale method for color images based on structural similarity |
| CN111275696A (en) * | 2020-02-10 | 2020-06-12 | 腾讯科技(深圳)有限公司 | A kind of medical image processing method, image processing method and device |
| CN112085755A (en) * | 2020-09-14 | 2020-12-15 | 贝壳技术有限公司 | Object contour detection method, device and equipment and storage medium |
Non-Patent Citations (1)
| Title |
|---|
| 刘美等: "对比度增强的彩色图像灰度化算法", 长春理工大学学报, vol. 41, no. 5, 31 October 2018 (2018-10-31), pages 70 - 71 * |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115100081A (en) * | 2022-08-24 | 2022-09-23 | 深圳佳弟子科技有限公司 | LCD display screen gray scale image enhancement method, device, equipment and storage medium |
| CN115100081B (en) * | 2022-08-24 | 2022-11-15 | 深圳佳弟子科技有限公司 | LCD display screen gray scale image enhancement method, device, equipment and storage medium |
| CN116993611A (en) * | 2023-07-28 | 2023-11-03 | 重庆赛力斯新能源汽车设计院有限公司 | Image loading method and device, electronic equipment and readable storage medium |
| CN117522760A (en) * | 2023-11-13 | 2024-02-06 | 书行科技(北京)有限公司 | Image processing method, device, electronic equipment, medium and product |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN114882125A (en) | Method and device for graying image data, terminal device and readable storage medium | |
| JP6718978B2 (en) | System language switching method and system language switching terminal device | |
| CN111968563A (en) | Brightness compensation method, device and system of display panel, display panel and medium | |
| CN109309826B (en) | Image color balancing method and device, terminal equipment and readable storage medium | |
| CN111275622B (en) | Image stitching method, device and terminal equipment | |
| US9813762B2 (en) | Creating hash values indicative of differences in images | |
| CN112997479B (en) | Method, system, and computer-readable medium for processing images across stage skip connections | |
| CN111915673A (en) | Image processing method, image processing device, terminal equipment and storage medium | |
| US20210185285A1 (en) | Image processing method and apparatus, electronic device, and readable storage medium | |
| CN111290684A (en) | Image display method, image display device and terminal equipment | |
| CN113505885A (en) | Training method of monocular depth estimation network based on preset loss function | |
| CN113436285A (en) | Color space conversion method and device, electronic equipment and readable storage medium | |
| CN109242750B (en) | Picture signature method, picture matching method, device, equipment and storage medium | |
| CN118509537B (en) | Image encryption method and device | |
| CN110232302B (en) | A change detection method integrating gray value, spatial information and category knowledge | |
| CN110018851A (en) | Data processing method, relevant device and computer-readable medium | |
| WO2025138715A1 (en) | Image processing method and related device thereof | |
| CN111402276B (en) | Binary image generation method and device, electronic equipment and readable storage medium | |
| CN104851114B (en) | A kind of method and terminal for realizing image local discoloration | |
| CN110879948B (en) | Image processing method, device and storage medium | |
| CN108629219B (en) | A method and device for identifying one-dimensional codes | |
| CN114301964B (en) | Terminal device and network connection method thereof, communication system and storage medium | |
| CN111160363B (en) | Method and device for generating feature descriptors, readable storage medium and terminal equipment | |
| CN112862907B (en) | Microscopic image correction methods, devices, equipment, storage media and products | |
| CN111382831A (en) | Method and device for accelerating forward reasoning of convolutional neural network model |
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 |