Movatterモバイル変換


[0]ホーム

URL:


CN103841388A - Mosaic removing method and device - Google Patents

Mosaic removing method and device
Download PDF

Info

Publication number
CN103841388A
CN103841388ACN201410077102.3ACN201410077102ACN103841388ACN 103841388 ACN103841388 ACN 103841388ACN 201410077102 ACN201410077102 ACN 201410077102ACN 103841388 ACN103841388 ACN 103841388A
Authority
CN
China
Prior art keywords
pixel
current position
color
value
component
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.)
Withdrawn
Application number
CN201410077102.3A
Other languages
Chinese (zh)
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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies 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 Huawei Technologies Co LtdfiledCriticalHuawei Technologies Co Ltd
Priority to CN201410077102.3ApriorityCriticalpatent/CN103841388A/en
Publication of CN103841388ApublicationCriticalpatent/CN103841388A/en
Withdrawnlegal-statusCriticalCurrent

Links

Images

Landscapes

Abstract

Translated fromChinese

本发明的实施例提供一种去马赛克的方法及装置,涉及图像处理技术领域,改进了像素的彩色还原效果,恢复像素的真实颜色的效果较好。该方法包括:获得当前位置像素在多个预设方向上的梯度值,并根据多个预设方向上的梯度值确定梯度阈值;确定当前位置像素的相对亮度分量信息;根据当前位置像素的相对亮度分量信息,获得当前位置像素的各个目标方向上的颜色值,其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向;根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值;根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值;根据已知颜色分量值和缺失颜色分量值,输出当前位置像素。

Embodiments of the present invention provide a method and device for demosaicing, which relate to the technical field of image processing, improve the color restoration effect of pixels, and have a better effect of restoring the true colors of pixels. The method includes: obtaining the gradient values of the pixels at the current position in multiple preset directions, and determining the gradient threshold according to the gradient values in the multiple preset directions; determining the relative brightness component information of the pixels at the current position; Brightness component information, to obtain the color value of each target direction of the current position pixel, wherein, the target direction is the direction in which the gradient value of the current position pixel in multiple preset directions is less than the gradient threshold; according to the current position pixel in each target direction According to the known color component value and color average value of the current position pixel, the missing color component value of the current position pixel is obtained; according to the known color component value and the missing color component value, the current position pixel is output .

Description

Translated fromChinese
一种去马赛克的方法及装置A method and device for demosaicing

技术领域technical field

本发明涉及图像处理技术领域,尤其涉及一种去马赛克的方法及装置。The present invention relates to the technical field of image processing, in particular to a method and device for demosaicing.

背景技术Background technique

随着通信技术的不断发展,越来越多的电子设备能够用于拍摄数码影像。为了降低能够拍摄数码影像的电子设备中的光路控制及感光成像芯片的复杂度和成本,绝大多数的电子产品的成像原始RAW数据一般采用Bayer格式。With the continuous development of communication technology, more and more electronic devices can be used to capture digital images. In order to reduce the complexity and cost of optical path control and photosensitive imaging chips in electronic devices capable of shooting digital images, the imaging raw data of most electronic products generally adopts Bayer format.

Bayer格式的数码影像中每个像素只保存红绿蓝(RGB,Red GreenBlue)三原色中的其中一种颜色分量,另两种颜色分量由其邻近像素共享。如图1所示,Bayer格式的数码影像以GRGR、BGBG的格式排列,呈现出一种马赛克形状。在显示输出数码影像时,为了恢复数码影像的真实颜色信息,将数码影像从Bayer格式转换为RGB三通道格式,即对数码影像进行去马赛克(Demosaic,Decrease Mosaic)。RGB三通道格式的数码影像在存储颜色信息的时候会针对每个像素的RGB颜色进行存储,也就是存储每个像素的RGB值。如图2所示,RGB三通道格式的数码影像按照亮度从暗到亮的三种不同灰度分别代表RGB三个通道。In the digital image of Bayer format, each pixel only saves one of the three primary colors of red, green and blue (RGB, Red Green Blue) color components, and the other two color components are shared by its adjacent pixels. As shown in Figure 1, digital images in Bayer format are arranged in GRGR and BGBG formats, presenting a mosaic shape. When displaying and outputting digital images, in order to restore the true color information of the digital images, the digital images are converted from the Bayer format to the RGB three-channel format, that is, the digital images are demosaiced (Demosaic, Decrease Mosaic). Digital images in RGB three-channel format will store the RGB color of each pixel when storing color information, that is, store the RGB value of each pixel. As shown in Figure 2, digital images in the RGB three-channel format represent the three RGB channels according to three different gray levels from dark to bright.

现有技术中,Demosaic是利用像素之间的相关性由已知部分信息恢复缺失颜色分量信息,一般采用最近邻法、加权平均法、考虑梯度方向的选择性加权平均法以及可变梯度数(VNG,Various Number ofGradients)方法等算法对数码影像进行去马赛克。其中,VNG方法是根据颜色梯度的方向性而选择变化较小的方向的颜色信息进行平均得到当前像素缺失颜色信息的方法,是一种实际效果相对比较好的方法。In the prior art, Demosaic uses the correlation between pixels to restore the missing color component information from the known partial information. Generally, the nearest neighbor method, weighted average method, selective weighted average method considering the gradient direction and variable gradient number ( VNG, Various Number of Gradients) method and other algorithms to demosaic digital images. Among them, the VNG method is based on the directionality of the color gradient and selects the color information in a direction with a small change to average to obtain the missing color information of the current pixel. It is a method with relatively good actual effect.

然而,在颜色快速变化的同时亮度也急剧变化的场景中,采用现有技术中任一种算法对数码影像进行去马赛克时,均会出现异常彩条或彩点,恢复像素的真实颜色的效果较差。However, in a scene where the brightness changes rapidly while the color changes rapidly, when any algorithm in the prior art is used to demosaic the digital image, there will be abnormal color bars or color points, and the effect of restoring the true color of the pixels poor.

发明内容Contents of the invention

本发明的实施例提供一种去马赛克的方法及装置,能够有效的解决在场景亮度和色度快速变化的情况下,利用传统去马赛克方法对数码影像进行去马赛克处理时出现的彩点或彩条等异常问题,改进了像素的彩色还原效果,恢复像素的真实颜色的效果较好。Embodiments of the present invention provide a method and device for demosaicing, which can effectively solve the problem of color dots or color spots that appear when traditional demosaicing methods are used to demosaic digital images in the case of rapid changes in scene brightness and chromaticity. The color restoration effect of pixels is improved, and the effect of restoring the true color of pixels is better.

为达到上述目的,本发明的实施例采用如下技术方案:In order to achieve the above object, embodiments of the present invention adopt the following technical solutions:

第一方面,本发明实施例提供了一种去马赛克的方法,该方法包括:In a first aspect, an embodiment of the present invention provides a demosaicing method, the method comprising:

获得当前位置像素在多个预设方向上的梯度值,并根据所述多个预设方向上的梯度值确定当前位置像素的梯度阈值;Obtain the gradient values of the current location pixel in multiple preset directions, and determine the gradient threshold of the current location pixel according to the gradient values in the multiple preset directions;

确定所述当前位置像素的相对亮度分量信息;determining relative brightness component information of the pixel at the current position;

根据所述当前位置像素的相对亮度分量信息,获得所述当前位置像素在所述多个预设方向中的各个目标方向上的颜色值,其中,所述目标方向为所述当前位置像素在所述多个预设方向中的梯度值小于所述梯度阈值的方向,所述当前位置像素有至少一个目标方向;According to the relative brightness component information of the pixel at the current position, obtain the color value of the pixel at the current position in each target direction in the plurality of preset directions, wherein the target direction is the pixel at the current position in the specified direction. A direction in which the gradient value in the plurality of preset directions is smaller than the gradient threshold value, and the current position pixel has at least one target direction;

根据所述当前位置像素的各个目标方向上的颜色值,统计颜色平均值;According to the color value in each target direction of the pixel at the current position, calculate the color average value;

根据所述当前位置像素的已知颜色分量值和所述颜色平均值,获得所述当前位置像素的缺失颜色分量值;Obtaining the missing color component value of the pixel at the current position according to the known color component value of the pixel at the current position and the color average value;

根据所述已知颜色分量值和所述缺失颜色分量值,输出所述当前位置像素。Outputting the pixel at the current location according to the known color component value and the missing color component value.

在第一方面的第一种可能的实现方式中,所述获得当前位置像素在多个预设方向上的梯度值,并根据所述多个预设方向上的梯度值确定当前位置像素梯度阈值之后,确定所述当前位置像素的相对亮度分量信息之前,所述方法还包括:In a first possible implementation manner of the first aspect, the obtaining the gradient values of the current location pixel in multiple preset directions, and determining the gradient threshold of the current location pixel according to the gradient values in the multiple preset directions Afterwards, before determining the relative brightness component information of the pixel at the current position, the method further includes:

比较所述多个预设方向上的梯度值和所述梯度阈值;comparing the gradient values in the plurality of preset directions with the gradient threshold;

在所述多个预设方向中,将所述梯度值小于所述梯度阈值的方向确定为所述当前位置像素的目标方向。Among the plurality of preset directions, a direction whose gradient value is smaller than the gradient threshold is determined as a target direction of the current position pixel.

结合前述第一方面或者第一方面的第一种可能的实现方式,在第一方面的第二种可能的实现方式中,所述确定所述当前位置像素的相对亮度分量信息,包括:With reference to the foregoing first aspect or the first possible implementation manner of the first aspect, in the second possible implementation manner of the first aspect, the determining the relative brightness component information of the pixel at the current position includes:

若所述当前位置像素为绿色G分量像素,则将所述当前位置像素的G分量值作为所述当前位置像素的相对亮度分量信息;If the current position pixel is a green G component pixel, then use the G component value of the current position pixel as the relative brightness component information of the current position pixel;

若所述当前位置像素为红色R分量像素或蓝色B分量像素,则计算所述当前位置像素的所述各个目标方向的G分量值的第一算术平均值,并将所述第一算术平均值确定为所述当前位置像素的相对亮度分量信息。If the current position pixel is a red R component pixel or a blue B component pixel, then calculate the first arithmetic mean of the G component values of the respective target directions of the current position pixel, and take the first arithmetic mean The value is determined as the relative brightness component information of the pixel at the current position.

在第一方面的第三种可能的实现方式中,所述获得当前位置像素在多个预设方向上的梯度值之前,所述方法还包括:In a third possible implementation manner of the first aspect, before obtaining the gradient values of the pixel at the current position in multiple preset directions, the method further includes:

获取以所述当前位置像素为中心的n×n的像素阵列,其中,n大于等于3。Obtain an n×n pixel array centered on the current position pixel, where n is greater than or equal to 3.

结合第一方面的第三种可能的实现方式,在第一方面的第四种可能的实现方式中,所述获得所述当前位置像素在多个预设方向上的梯度值,包括:With reference to the third possible implementation manner of the first aspect, in the fourth possible implementation manner of the first aspect, the obtaining the gradient values of the pixel at the current position in multiple preset directions includes:

在所述像素阵列中,若所述当前位置像素为G分量像素,则按照第一预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值;In the pixel array, if the current position pixel is a G component pixel, calculate the gradient values of the current position pixel in multiple preset directions in the pixel array according to a first preset rule;

在所述像素阵列中,若所述当前位置为R分量像素或B分量像素,则按照第二预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值。In the pixel array, if the current position is an R component pixel or a B component pixel, calculate the gradient values of the pixel at the current position in multiple preset directions in the pixel array according to a second preset rule .

结合前述的第一方面或第一方面的第一种可能的实现方式至第四种可能的实现方式,在第一方面的第五种可能的实现方式中,在所述像素阵列中,获得各个目标方向上的每个位置像素的相对亮度分量信息;With reference to the aforementioned first aspect or the first possible implementation manner to the fourth possible implementation manner of the first aspect, in the fifth possible implementation manner of the first aspect, in the pixel array, each Relative brightness component information of each position pixel in the target direction;

根据所述当前位置像素的相对亮度分量信息和所述各个目标方向上的每个位置像素的相对亮度分量信息,获得所述当前位置像素的各个目标方向上的颜色值,所述各个目标方向上的颜色值包括目标方向上的R分量、G分量和B分量的值。According to the relative luminance component information of the pixel at the current position and the relative luminance component information of each position pixel in the respective target directions, obtain the color value of the pixel at the current position in each target direction, and in the respective target directions The color value of includes the values of R component, G component and B component in the target direction.

结合第一方面的第五种可能的实现方式,在第一方面的第六种可能的实现方式中,所述统计颜色平均值,包括:With reference to the fifth possible implementation manner of the first aspect, in the sixth possible implementation manner of the first aspect, the statistical color average value includes:

根据所述当前位置像素在所述各个目标方向上的梯度值和所述当前位置像素的各个目标方向上的颜色值,计算所述当前位置像素在所述各个目标方向上的梯度值的加权平均值,以获得所述颜色平均值;Calculate a weighted average of the gradient values of the current position pixel in the respective target directions according to the gradient values of the current position pixel in the respective target directions and the color values of the current position pixel in each target direction value to obtain the color average;

或者,or,

计算所述当前位置像素的各个目标方向上的颜色值的第二算术平均值,其中,所述第二算术平均值为所述颜色平均值。calculating a second arithmetic mean value of color values in each target direction of the pixel at the current position, wherein the second arithmetic mean value is the color mean value.

第二方面,本发明的实施例提供一种去马赛克的装置,该装置包括:In a second aspect, an embodiment of the present invention provides a demosaicing device, which includes:

获取单元,用于获得当前位置像素在多个预设方向上的梯度值,以及用于获得所述当前位置像素在所述多个预设方向中的各个目标方向上的颜色值,其中,所述目标方向为所述当前位置像素在所述多个预设方向中的梯度值小于所述梯度阈值的方向,所述当前位置像素有至少一个目标方向,以及用于根据所述当前位置像素的已知颜色分量值和所述颜色平均值,获得所述当前位置像素的缺失颜色分量值;An acquisition unit, configured to obtain the gradient value of the pixel at the current position in multiple preset directions, and to obtain the color value of the pixel at the current position in each target direction in the multiple preset directions, wherein the The target direction is a direction in which the gradient value of the current position pixel in the plurality of preset directions is smaller than the gradient threshold value, the current position pixel has at least one target direction, and is used to Knowing the color component value and the color average value, obtaining the missing color component value of the pixel at the current position;

确定单元,用于根据所述获取单元获取到的所述多个预设方向上的梯度值确定当前位置像素的梯度阈值,以及用于确定所述当前位置像素的相对亮度分量信息;A determination unit, configured to determine the gradient threshold of the pixel at the current position according to the gradient values in the plurality of preset directions acquired by the acquisition unit, and to determine the relative brightness component information of the pixel at the current position;

计算单元,用于根据所述获取单元获取到的所述当前位置像素的各个目标方向上的颜色值,统计颜色平均值;A calculation unit, configured to calculate the color average value according to the color values in each target direction of the pixel at the current position acquired by the acquisition unit;

输出单元,用于根据所述已知颜色分量值和所述获取单元获取到的所述缺失颜色分量值,输出所述当前位置像素。An output unit, configured to output the pixel at the current position according to the known color component value and the missing color component value acquired by the acquiring unit.

在第二方面的第一种可能实现方式中,所述确定单元,还用于在确定当前位置像素梯度阈值之后,确定所述当前位置像素的相对亮度分量信息之前,比较所述多个预设方向上的梯度值和所述梯度阈值,并在所述多个预设方向中,将所述梯度值小于所述梯度阈值的方向确定为所述当前位置像素的目标方向。In a first possible implementation manner of the second aspect, the determining unit is further configured to compare the plurality of preset The gradient value in the direction and the gradient threshold, and in the plurality of preset directions, determine the direction whose gradient value is smaller than the gradient threshold as the target direction of the current position pixel.

结合前述第二方面或第二方面的第一种可能实现方式,在第二方面的第二种可能实现方式中,所述确定单元,具体用于若所述当前位置像素为绿色G分量像素,则将所述当前位置像素的G分量值作为所述当前位置像素的相对亮度分量信息,以及具体用于若所述当前位置像素为红色R分量像素或蓝色B分量像素,则将所述计算单元计算的所述第一算术平均值确定为所述当前位置像素的相对亮度分量信息;With reference to the aforementioned second aspect or the first possible implementation manner of the second aspect, in the second possible implementation manner of the second aspect, the determining unit is specifically configured to, if the pixel at the current position is a green G component pixel, Then use the G component value of the current position pixel as the relative brightness component information of the current position pixel, and specifically for if the current position pixel is a red R component pixel or a blue B component pixel, the calculation The first arithmetic mean value calculated by the unit is determined as the relative brightness component information of the pixel at the current position;

所述计算单元,还用于若所述当前位置像素为红色R分量像素或蓝色B分量像素,则计算所述当前位置像素的所述各个目标方向的G分量值的第一算术平均值。The calculation unit is further configured to calculate a first arithmetic mean of the G component values of the respective target directions of the pixel at the current position if the pixel at the current position is a red R component pixel or a blue B component pixel.

在第二方面的第三种可能实现方式中,所述获取单元,还用于获取以所述当前位置像素为中心的n×n的像素阵列,其中,n大于等于3。In a third possible implementation manner of the second aspect, the acquiring unit is further configured to acquire an n×n pixel array centered on the pixel at the current position, where n is greater than or equal to 3.

结合第二方面的第三种可能的实现方式,在第二方面的第四种可能的实现方式中,所述计算单元,具体用于在所述获取单元获取到的所述像素阵列中,若所述当前位置像素为G分量像素,则按照第一预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值,以及还用于在所述获取单元获取到的所述像素阵列中,若所述当前位置为R分量像素或B分量像素,则按照第二预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值。With reference to the third possible implementation of the second aspect, in a fourth possible implementation of the second aspect, the calculation unit is specifically configured to, in the pixel array acquired by the acquisition unit, if If the current position pixel is a G component pixel, the gradient values of the current position pixel in multiple preset directions in the pixel array are calculated according to the first preset rule, and are also used for obtaining in the acquisition unit In the pixel array obtained, if the current position is an R component pixel or a B component pixel, the gradients of the current position pixel in multiple preset directions in the pixel array are calculated according to the second preset rule value.

结合前述的第二方面或第二方面的第一种可能的实现方式至第四种可能的实现方式中的任一种实现方式,在第二方面的第五种可能的实现方式中,所述获取单元,具体用于在所述像素阵列中,获得各个目标方向上的每个位置像素的相对亮度分量信息,以及用于根据所述当前位置像素的相对亮度分量信息和所述各个目标方向上的每个位置像素的相对亮度分量信息,获得所述当前位置像素的各个目标方向上的颜色值,所述各个目标方向上的颜色值包括各个目标方向上的R分量、G分量和B分量的值。In combination with any of the foregoing second aspect or the first possible implementation manner to the fourth possible implementation manner of the second aspect, in the fifth possible implementation manner of the second aspect, the The obtaining unit is specifically configured to obtain, in the pixel array, the relative brightness component information of each position pixel in each target direction, and is configured to obtain the relative brightness component information of the current position pixel and the relative brightness component information of each target direction in the pixel array. The relative luminance component information of each position pixel of the current position pixel is obtained to obtain the color value in each target direction of the current position pixel, and the color value in each target direction includes the R component, G component and B component in each target direction value.

结合第二方面的第五种可能的实现方式,在第二方面的第六种可能的实现方式中,所述计算单元,具体用于根据所述当前位置像素在所述各个目标方向上的梯度值和所述当前位置像素的各个目标方向上的颜色值,计算所述当前位置像素在所述各个目标方向上的梯度值的加权平均值,以获得所述颜色平均值,以及具体用于计算所述当前位置像素的各个目标方向上的颜色值的第二算术平均值,其中,所述第二算术平均值为所述颜色平均值。With reference to the fifth possible implementation manner of the second aspect, in a sixth possible implementation manner of the second aspect, the calculation unit is specifically configured to: value and the color value in each target direction of the current position pixel, calculate the weighted average value of the gradient value of the current position pixel in the each target direction, to obtain the color average value, and specifically used to calculate A second arithmetic mean value of color values in each target direction of the pixel at the current position, wherein the second arithmetic mean value is the color mean value.

本发明的实施例提供一种去马赛克的方法及装置,去马赛克的装置通过获得当前位置像素在多个预设方向上的梯度值,确定当前位置像素的梯度阈值和相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息,在多个预设方向中确定当前位置像素的至少一个目标方向,其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向,获得当前位置像素的各个目标方向上的颜色值,并根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值,最后,根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值,并根据已知颜色分量值和缺失颜色分量值,输出当前位置像素。通过该方案,本发明同时考虑了场景亮度和色度快速变化的情况,对色度和亮度进行了协同调整,解决了现有技术在此类型场景出现异常彩点或彩条的问题,改进了像素的彩色还原效果,能够有效恢复像素的真实颜色。Embodiments of the present invention provide a demosaicing method and device. The demosaicing device determines the gradient threshold and relative brightness component information of the current position pixel by obtaining the gradient values of the current position pixel in multiple preset directions, and then, According to the relative brightness component information of the pixel at the current position, determine at least one target direction of the pixel at the current position in multiple preset directions, wherein the target direction is a direction in which the gradient value of the pixel at the current position in the multiple preset directions is less than a gradient threshold , obtain the color values in each target direction of the pixel at the current position, and calculate the color average value according to the color values in each target direction of the pixel at the current position, and finally, according to the known color component values and the color average value of the pixel at the current position, Obtain the missing color component value of the pixel at the current position, and output the pixel at the current position according to the known color component value and the missing color component value. Through this solution, the present invention simultaneously considers the situation of rapid changes in scene brightness and chroma, coordinates adjustments to chroma and brightness, solves the problem of abnormal color dots or color bars in this type of scene in the prior art, and improves The color restoration effect of pixels can effectively restore the true colors of pixels.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. Those skilled in the art can also obtain other drawings based on these drawings without creative work.

图1为Bayer格式的数码影像的分布示意图;Fig. 1 is the distribution diagram of the digital image of Bayer format;

图2为RGB三通道格式的数码影像的分布示意图;Fig. 2 is the distribution schematic diagram of the digital image of RGB three-channel format;

图3为本发明实施例的去马赛克的方法的流程示意图一;FIG. 3 is a first schematic flow diagram of a demosaicing method according to an embodiment of the present invention;

图4为5×5区域的像素阵列结构示意图;FIG. 4 is a schematic diagram of a pixel array structure in a 5×5 area;

图5为本发明实施例的去马赛克的方法的流程示意图二;FIG. 5 is a second schematic flow diagram of a demosaicing method according to an embodiment of the present invention;

图6为5x5区域RGB分量数据示例图;Figure 6 is an example diagram of RGB component data in a 5x5 area;

图7为本发明实施例的去马赛克的装置的结构示意图一;FIG. 7 is a first structural schematic diagram of a demosaicing device according to an embodiment of the present invention;

图8为本发明实施例的去马赛克的装置的结构示意图二。FIG. 8 is a second structural schematic diagram of a demosaicing device according to an embodiment of the present invention.

具体实施方式Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.

从背景技术的描述中可以知道,在显示输出数码影像时,为了恢复数码影像的真实颜色信息,需要对数码影像进行去马赛克,即将数码影像从Bayer格式转换为RGB三通道格式。It can be known from the description of the background technology that when displaying and outputting digital images, in order to recover the true color information of the digital images, it is necessary to demosaic the digital images, that is, to convert the digital images from the Bayer format to the RGB three-channel format.

其中,在现有技术中,可变梯度数(VNG,Various Number ofGradients)方法是由于每个像素颜色的变化梯度在不同方向上是不同的,因此根据颜色梯度的方向性而选择变化较小的方向的颜色信息进行平均得到当前像素缺失颜色信息的方法,是目前去马赛克实际效果相对比较好的方法。Among them, in the prior art, the variable number of gradients (VNG, Various Number of Gradients) method is because the change gradient of each pixel color is different in different directions, so according to the directionality of the color gradient, the one with the smaller change is selected. The method of averaging the color information of the direction to obtain the missing color information of the current pixel is a relatively good method for demosaicing.

具体的,VNG方法的步骤为:Specifically, the steps of the VNG method are:

(1)计算当前位置像素5x5邻域水平竖直以及对角线等八个方向上的梯度值Grad(i)。(1) Calculate the gradient value Grad(i) in eight directions including horizontal, vertical and diagonal in the 5x5 neighborhood of the current position pixel.

(2)根据八个方向梯度值的最大最小值设定梯度阈值Threshold,并采用以下公式统计梯度值小于梯度阈值的所有方向上的红色(R,Red)、绿色(G,Green)、蓝色(B,Blue)分量的平均值Ravg,Gavg,Bavg:(2) Set the gradient threshold Threshold according to the maximum and minimum values of the gradient values in the eight directions, and use the following formula to count red (R, Red), green (G, Green), blue in all directions where the gradient value is less than the gradient threshold Average values of (B, Blue) components Ravg, Gavg, Bavg:

CavgCavg==11NN&Sigma;Ci&Sigma;CiGradGrad((ii))<<ThresholdThreshold

其中,Ci为在梯度值小于梯度阈值的各个方向上的R、G、B分量值,Grad(i)为当前位置像素在八个方向的任意一个方向上的梯度值,N为梯度值小于梯度阈值的方向的数量值。Among them, Ci is the R, G, and B component values in each direction where the gradient value is less than the gradient threshold, Grad(i) is the gradient value of the current position pixel in any one of the eight directions, and N is the gradient value is less than the gradient The magnitude value of the direction of the threshold.

(3)根据当前位置像素的已知颜色分量值以及Ravg、Gavg、Bavg的差值,计算当前位置像素的缺失颜色分量值。(3) Calculate the missing color component value of the pixel at the current position according to the known color component value of the pixel at the current position and the difference between Ravg, Gavg, and Bavg.

例如,若当前位置像素的已知颜色分量为G,则采用以下公式计算当前位置像素的缺失颜色分量值:For example, if the known color component of the pixel at the current position is G, the missing color component value of the pixel at the current position is calculated using the following formula:

R=Gori+Ravg-GavgR=Gori+Ravg-Gavg

B=Gori+Bavg-GavgB=Gori+Bavg-Gavg

G=GoriG=Gori

其中,若当前位置像素的已知颜色分量为R或B时,计算当前位置像素的缺失颜色分量值的方法与当前位置像素的已知颜色分量为G时的计算方法类似,此处不再详细说明。Among them, if the known color component of the current position pixel is R or B, the method of calculating the missing color component value of the current position pixel is similar to the calculation method when the known color component of the current position pixel is G, and will not be detailed here illustrate.

通过上述VNG方法的各个步骤可以知道,即使VNG方法在现有技术中是一种去马赛克实际效果相对比较好的方法,该方法在具体计算过程中也仅仅是考虑了色度的变化,而没有考虑亮度的变化,导致在颜色快速变化的同时亮度也急剧快速变化的场景中,去马赛克结果会出现彩点或彩条,恢复像素的真实颜色的效果较差。Through the various steps of the above-mentioned VNG method, it can be known that even though the VNG method is a method with a relatively good demosaic effect in the prior art, this method only considers the change of chromaticity in the specific calculation process, and does not Considering the change of brightness, in a scene where the brightness changes rapidly at the same time as the color changes rapidly, colored dots or colored bars will appear in the demosaic result, and the effect of restoring the true color of the pixel is poor.

为了在颜色快速变化的同时亮度也急剧变化的场景中,采用现有技术中任一种算法对数码影像进行去马赛克时,均会出现异常彩条或彩点,恢复像素的真实颜色的效果较差的问题,本发明实施例提供一种去马赛克的方法及装置。本发明同时考虑色度亮度快速变化的情况,采用色度亮度协同调整的方法对Bayer格式的数码影像进行去马赛克处理,有效的改进了像素的彩色还原效果,恢复像素的真实颜色的效果较好。In a scene where the brightness changes rapidly while the color changes rapidly, when any algorithm in the prior art is used to demosaic a digital image, abnormal color bars or color points will appear, and the effect of restoring the true color of the pixel is relatively low. To solve the poor problem, embodiments of the present invention provide a demosaicing method and device. At the same time, the present invention considers the rapid change of chromaticity and brightness, adopts the method of synergistic adjustment of chromaticity and brightness to perform demosaic processing on digital images in Bayer format, effectively improves the color restoration effect of pixels, and restores the real color of pixels better .

本文描述的各种技术适用于单反式相机、普通数码相机、卡片式相机、带拍照功能手机、网络摄像机、行车记录仪或视频监控设备等具有能够拍摄数码影像功能的电子设备中。The various technologies described in this article are applicable to electronic devices capable of capturing digital images, such as SLR cameras, ordinary digital cameras, card cameras, mobile phones with camera functions, network cameras, driving recorders, or video surveillance equipment.

实施例一Embodiment one

本发明实施例提供一种去马赛克的方法,如图3所示,该方法包括:An embodiment of the present invention provides a method for demosaicing, as shown in FIG. 3 , the method includes:

S101、去马赛克的装置获得当前位置像素在多个预设方向上的梯度值,并根据多个预设方向上的梯度值确定当前位置像素的梯度阈值。S101. The demosaicing device obtains gradient values of the pixel at the current position in multiple preset directions, and determines a gradient threshold of the pixel at the current position according to the gradient values in the multiple preset directions.

为了降低光路控制及感光成像芯片的复杂度和成本,绝大多数能够用于拍摄数码影像的电子产品的成像原始RAW数据一般采用Bayer格式。Bayer格式的数码影像中每个像素就只有一种颜色分量,或R或G或B,需要借助当前像素周围的颜色对其进行插值另外两种颜色。In order to reduce the complexity and cost of optical path control and photosensitive imaging chips, the imaging raw data of most electronic products that can be used to shoot digital images generally adopts the Bayer format. Each pixel in a digital image in Bayer format has only one color component, or R or G or B, and it needs to interpolate the other two colors with the help of the colors around the current pixel.

由于,自然景物颜色信息是平稳变化的,且每个像素颜色的变化梯度在不同方向上是不同的,为了保证对当前位置像素进行颜色插值后,当前位置像素的颜色能够有效恢复,去马赛克的装置选择颜色变化较小的方向,即去马赛克的装置选择颜色梯度较小的方向。Since the color information of natural scenery changes smoothly, and the color gradient of each pixel is different in different directions, in order to ensure that the color of the current position pixel can be effectively restored after the color interpolation is performed on the current position pixel, demosaicing The device chooses the direction with smaller color change, that is, the demosaiced device chooses the direction with smaller color gradient.

具体的,在对数码影像进行去马赛克处理时,为了获取到颜色梯度变化较小的方向,去马赛克的装置先获得当前位置像素在多个预设方向上的梯度值,并根据多个预设方向上的梯度值确定当前位置像素的梯度阈值。Specifically, when performing demosaic processing on a digital image, in order to obtain the direction in which the color gradient changes less, the demosaic device first obtains the gradient values of the pixels at the current position in multiple preset directions, and according to the multiple preset The gradient value in the direction determines the gradient threshold for the pixel at the current location.

进一步地,去马赛克的装置根据当前位置像素的颜色信息,按照与颜色信息相对应的预设规则计算当前位置像素在多个预设方向上的梯度值。在获得当前位置像素在多个预设方向上的梯度值后,去马赛克的装置根据获得到的多个梯度值,确定当前位置像素的梯度阈值,以保证能够确定当前位置像素的颜色变化最小的方向,进而有效获得当前位置像素的缺失颜色值。Further, the demosaicing device calculates the gradient values of the pixel at the current position in multiple preset directions according to the color information of the pixel at the current position according to a preset rule corresponding to the color information. After obtaining the gradient values of the pixel at the current position in multiple preset directions, the demosaicing device determines the gradient threshold of the pixel at the current position according to the obtained multiple gradient values, so as to ensure that the pixel at the current position has the smallest color change. direction, and then effectively obtain the missing color value of the pixel at the current position.

其中,去马赛克的装置是在以当前位置像素为中心的n×n(n大于等于3)的像素阵列中获得当前位置像素在多个预设方向上的梯度值,也就是说,去马赛克装置在获得当前位置像素在多个预设方向上的梯度值之前,需要先获取以当前位置像素为中心的n×n的像素阵列。Among them, the demosaicing device is to obtain the gradient values of the current position pixel in multiple preset directions in an n×n (n greater than or equal to 3) pixel array centered on the current position pixel, that is to say, the demosaicing device Before obtaining the gradient values of the current position pixel in multiple preset directions, it is necessary to obtain an n×n pixel array centered on the current position pixel.

示例性的,图4为一个5x5的像素阵列,Ci表示该像素阵列中各个位置的颜色分量值。Exemplarily, FIG. 4 is a 5x5 pixel array, and Ci represents the color component value of each position in the pixel array.

需要说明的是,如图4所示,预设方向可以为当前位置像素的东、西、南、北、东北、东南、西南和西北这八个方向,也可以为其他预设方向。It should be noted that, as shown in FIG. 4 , the preset directions may be eight directions of east, west, south, north, northeast, southeast, southwest and northwest of the current position pixel, or other preset directions.

进一步地,去马赛克的装置在获取到的像素阵列中,若当前位置像素为G分量像素,则按照第一预设规则计算当前位置像素在像素阵列中的多个预设方向上的梯度值;若当前位置为R分量像素或B分量像素,则按照第二预设规则计算当前位置像素在像素阵列中的多个预设方向上的梯度值。Further, in the acquired pixel array, if the pixel at the current position is a G component pixel, the device for demosaicing calculates gradient values of the pixel at the current position in multiple preset directions in the pixel array according to a first preset rule; If the current position is an R component pixel or a B component pixel, the gradient values of the pixel at the current position in multiple preset directions in the pixel array are calculated according to a second preset rule.

需要说明的是,去马赛克的装置确定的当前位置像素的梯度阈值可以为该梯度阈值小于当前位置像素在多个预设方向上的梯度值的最大值与最小值的差值的三分之二,也可以为该梯度阈值大于当前位置像素在多个预设方向上的梯度值的最小值,且小于当前位置像素在多个预设方向上的梯度的中间值,本发明实施例不做限定。It should be noted that the gradient threshold of the current position pixel determined by the demosaicing device may be less than two-thirds of the difference between the maximum value and the minimum value of the gradient values of the current position pixel in multiple preset directions. , it can also be that the gradient threshold is greater than the minimum value of the gradient value of the current position pixel in multiple preset directions, and smaller than the median value of the gradient value of the current position pixel in multiple preset directions, which is not limited in the embodiment of the present invention .

S102、去马赛克的装置确定当前位置像素的相对亮度分量信息。S102. The device for demosaicing determines the relative brightness component information of the pixel at the current position.

对数码影像进行去马赛克的过程中,不仅仅要考虑到色度的变化,也要考虑到亮度的变化。在色度亮度快速变化的场景中,尤其需要考虑亮度的变化对去马赛克结果的影响。In the process of demosaicing digital images, not only changes in chromaticity, but also changes in brightness must be considered. In a scene where the chroma and brightness change rapidly, it is especially necessary to consider the influence of the brightness change on the demosaicing result.

去马赛克的装置获得到当前位置像素在多个预设方向上的梯度值和当前位置像素的梯度阈值后,确定当前位置像素的相对亮度分量信息。After obtaining the gradient values of the pixel at the current position in multiple preset directions and the gradient threshold of the pixel at the current position, the device for demosaicing determines the relative brightness component information of the pixel at the current position.

Bayer格式的数码影像每个像素仅保存RGB三原色中的其中一种颜色分量,另两种颜色分量由其邻近像素共享。由图1可以知道,Bayer格式的数码影像中G分量的分布密度是R、B的两倍,任意一行或一列中均有G分量,而R分量或B分量是间隔一行或一列分布的。因此,在一个设定的领域内,G分量在四个或八个方向上均有采样值,但R或B分量只在部分方向存在采样值。Each pixel of a digital image in Bayer format only saves one of the RGB primary colors, and the other two color components are shared by its adjacent pixels. It can be known from Figure 1 that the distribution density of the G component in the Bayer format digital image is twice that of R and B, and there is a G component in any row or column, while the R component or B component is distributed every other row or column. Therefore, in a set area, the G component has sampling values in four or eight directions, but the R or B component only has sampling values in some directions.

实际场景的亮度、色度只会在某个趋势方向上快速变化,而G分量在各个方向上均存在采样值并且G分量对于像素亮度的贡献为60%,可以代表亮度的变化趋势。因此,本发明方法优先选择G分量作为场景亮度变化趋势的控制参数。The brightness and chromaticity of the actual scene will only change rapidly in a certain trend direction, while the G component has sampling values in all directions and the contribution of the G component to the pixel brightness is 60%, which can represent the change trend of brightness. Therefore, the method of the present invention preferably selects the G component as the control parameter of the scene brightness variation trend.

具体的,若当前位置像素为G分量像素,则将当前位置像素的G分量值作为当前位置像素的相对亮度分量信息;若当前位置像素为R分量像素或B分量像素,则计算当前位置像素的各个目标方向的G分量值的第一算术平均值,并将第一算术平均值确定为当前位置像素的相对亮度分量信息。Specifically, if the current position pixel is a G component pixel, then use the G component value of the current position pixel as the relative brightness component information of the current position pixel; if the current position pixel is an R component pixel or a B component pixel, then calculate the current position pixel’s A first arithmetic mean value of the G component values in each target direction, and determine the first arithmetic mean value as the relative brightness component information of the pixel at the current position.

S103、去马赛克的装置根据当前位置像素的相对亮度分量信息,获得当前位置像素在所述多个预设方向中的各个目标方向上的颜色值。S103. The device for demosaicing obtains the color value of the pixel at the current position in each target direction in the plurality of preset directions according to the relative brightness component information of the pixel at the current position.

其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向,当前位置像素有至少一个目标方向。Wherein, the target direction is a direction in which the gradient value of the current position pixel in multiple preset directions is smaller than the gradient threshold, and the current position pixel has at least one target direction.

具体的,去马赛克的装置在像素阵列中,获得各个目标方向上的每个位置像素的相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息和各个目标方向上的每个位置像素的相对亮度分量信息,计算当前位置像素的各个目标方向上的颜色值。Specifically, the demosaicing device obtains the relative brightness component information of each position pixel in each target direction in the pixel array, and then, according to the relative brightness component information of the current position pixel and each position pixel in each target direction Calculate the color value of the pixel at the current position in each target direction relative to the brightness component information.

其中,各个目标方向上至少有一个像素,去马赛克的装置获得各个目标方向上的每个位置像素的相对亮度分量信息的方法与去马赛克的装置获得当前位置像素的相对亮度分量信息的方法是相同的。Where there is at least one pixel in each target direction, the method for the demosaicing device to obtain the relative brightness component information of each position pixel in each target direction is the same as the method for the demosaicing device to obtain the relative brightness component information of the current position pixel of.

示例性的,去马赛克的装置获得当前位置像素的东侧的第一位置像素的相对亮度分量信息的方法为:去马赛克的装置获取以第一位置像素为中心的n×n的第一像素阵列,按照本发明实施例中的S101和S102的方法获得当前位置像素的东侧的第一位置像素的相对亮度分量信息。Exemplarily, the method for the demosaicing device to obtain the relative brightness component information of the first position pixel on the east side of the current position pixel is as follows: the demosaicing device obtains a first n×n pixel array centered on the first position pixel According to the method of S101 and S102 in the embodiment of the present invention, the relative brightness component information of the pixel at the first position on the east side of the pixel at the current position is obtained.

需要说明的是,各个目标方向上的颜色值包括各个目标方向上的R分量、G分量和B分量的值。It should be noted that the color values in each target direction include the values of R component, G component and B component in each target direction.

S104、去马赛克的装置根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值。S104. The device for demosaicing calculates a color average value according to the color values of the pixel at the current position in each target direction.

目标方向是梯度值小于梯度阈值的方向,去马赛克的装置在各个目标方向上获取到颜色值后,根据颜色信息将这些颜色值进行平均获得颜色平均值,进而利用颜色平均值对当前位置像素进行颜色插值,即去马赛克的装置根据获得到的当前位置像素的各个目标方向上的颜色值,统计颜色平均值。The target direction is the direction where the gradient value is less than the gradient threshold. After the demosaicing device obtains the color values in each target direction, it averages these color values according to the color information to obtain the color average value, and then uses the color average value to perform a Color interpolation, that is, the device for demosaicing calculates the color average value according to the obtained color values in each target direction of the pixel at the current position.

具体的,去马赛克的装置获取到各个目标方向上的R分量、G分量和B分量的值后,将获取到的颜色值根据颜色信息的不同,分别计算出R分量、G分量和B分量的颜色平均值。Specifically, after the demosaicing device acquires the values of the R component, the G component, and the B component in each target direction, it calculates the values of the R component, the G component, and the B component from the acquired color values according to the color information. Color average.

进一步地,去马赛克的装置根据当前位置像素在各个目标方向上的梯度值和当前位置像素的各个目标方向上的颜色值,计算当前位置像素在各个目标方向上的梯度值的加权平均值,以获得颜色平均值;Further, the demosaicing device calculates the weighted average value of the gradient value of the current position pixel in each target direction according to the gradient value of the current position pixel in each target direction and the color value of the current position pixel in each target direction, to obtain Get the color average;

或者,or,

去马赛克的装置计算当前位置像素的各个目标方向上的颜色值的第二算术平均值,其中,第二算术平均值为颜色平均值。The device for demosaicing calculates a second arithmetic mean value of color values in each target direction of the pixel at the current position, wherein the second arithmetic mean value is a color mean value.

S105、去马赛克的装置根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值。S105. The demosaicing device obtains the missing color component value of the pixel at the current position according to the known color component value and the color average value of the pixel at the current position.

去马赛克的装置统计出颜色平均值后,利用当前位置像素的已知颜色分量值和颜色平均值,即可直接计算出当前位置像素的缺失颜色分量值。After the demosaicing device counts the color average value, the missing color component value of the pixel at the current position can be directly calculated by using the known color component value and the color average value of the pixel at the current position.

S106、去马赛克的装置根据当前位置像素的已知颜色分量值和当前位置像素的缺失颜色分量值,输出当前位置像素。S106. The demosaicing device outputs the pixel at the current position according to the known color component value of the pixel at the current position and the missing color component value of the pixel at the current position.

RGB三通道格式的数码影像在存储颜色信息的时候会针对每个像素的RGB颜色进行存储,也就是存储每个像素的RGB值。在显示输出数码影像时,为了恢复数码影像的真实颜色信息,将数码影像从Bayer格式转换为RGB三通道格式,即对数码影像进行Demosaic。Digital images in RGB three-channel format will store the RGB color of each pixel when storing color information, that is, store the RGB value of each pixel. When displaying and outputting digital images, in order to restore the true color information of the digital images, the digital images are converted from the Bayer format to the RGB three-channel format, that is, the digital images are demosaiced.

去马赛克的装置在获得到当前位置像素的缺失颜色分量值后,去马赛克的装置获就获得了当前位置像素的三原色中的三种颜色分量值,去马赛克的装置将当前位置像素按照这三种颜色分量值输出,即完成了对当前位置像素的去马赛克处理。After the demosaicing device obtains the missing color component values of the current position pixel, the demosaicing device obtains the three color component values of the three primary colors of the current position pixel, and the demosaicing device converts the current position pixel according to the three primary colors. The color component value is output, that is, the demosaic processing of the pixel at the current position is completed.

现有的去马赛克的方法仅仅是考虑颜色梯度的方向性而选择变化较小的方向的颜色信息进行平均得到当前位置像素的缺失颜色信息。与现有的去马赛克的方法不同,本发明方法中,由于去马赛克的装置获得的各个目标方向的颜色值是根据当前位置像素的相对亮度分量信息和各个目标方向上的每个位置像素的相对亮度分量信息得到的,因此,去马赛克的装置获得的颜色平均值也是依据相对亮度分量信息得到的。这样,本发明方法中,去马赛克的装置获得的当前位置像素的缺失颜色分量值更加准确,即使在颜色快速变化的同时亮度也急剧变化的场景中,也能有效的恢复像素的真实颜色。The existing demosaicing method only considers the directionality of the color gradient and selects the color information in a direction with a small change for averaging to obtain the missing color information of the pixel at the current position. Different from the existing demosaicing method, in the method of the present invention, the color value of each target direction obtained by the demosaicing device is based on the relative brightness component information of the current position pixel and the relative brightness of each position pixel in each target direction. Therefore, the color average value obtained by the demosaicing device is also obtained based on the relative brightness component information. In this way, in the method of the present invention, the missing color component value of the pixel at the current position obtained by the demosaicing device is more accurate, even in a scene where the brightness changes rapidly while the color changes rapidly, the true color of the pixel can be effectively restored.

本发明的实施例提供一种去马赛克的方法,去马赛克的装置通过获得当前位置像素在多个预设方向上的梯度值,确定当前位置像素的和梯度阈值和相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息,在多个预设方向中确定当前位置像素的至少一个目标方向,其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向,获得当前位置像素的各个目标方向上的颜色值,并根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值,最后,根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值,并根据已知颜色分量值和缺失颜色分量值,输出当前位置像素。通过该方案,本发明同时考虑了场景亮度和色度快速变化的情况,对色度和亮度进行了协同调整,解决了现有技术在此类型场景出现异常彩点或彩条的问题,改进了像素的彩色还原效果,能够有效恢复像素的真实颜色。An embodiment of the present invention provides a demosaicing method. The demosaicing device determines the sum gradient threshold and relative brightness component information of the current position pixel by obtaining the gradient values of the current position pixel in multiple preset directions, and then, according to The relative brightness component information of the pixel at the current position determines at least one target direction of the pixel at the current position in a plurality of preset directions, wherein the target direction is a direction in which the gradient value of the pixel at the current position in the plurality of preset directions is smaller than the gradient threshold, Obtain the color values in each target direction of the pixel at the current position, and calculate the color average value according to the color values in each target direction of the pixel at the current position, and finally, obtain The missing color component value of the pixel at the current position, and output the pixel at the current position according to the known color component value and the missing color component value. Through this solution, the present invention simultaneously considers the situation of rapid changes in scene brightness and chroma, coordinates adjustments to chroma and brightness, solves the problem of abnormal color dots or color bars in this type of scene in the prior art, and improves The color restoration effect of pixels can effectively restore the true colors of pixels.

实施例二Embodiment two

本发明实施例提供一种去马赛克的方法,如图5所示,该方法包括:An embodiment of the present invention provides a method for demosaicing, as shown in FIG. 5 , the method includes:

S201、去马赛克的装置获取Bayer格式的数码影像,并在该数码影像中获取以当前位置像素为中心的n×n的像素阵列,其中,n大于等于3。S201. The demosaicing device acquires a digital image in Bayer format, and acquires an n×n pixel array centered on a pixel at a current position in the digital image, where n is greater than or equal to 3.

为了降低光路控制及感光成像芯片的复杂度和成本,绝大多数能够用于拍摄数码影像的电子产品的成像原始RAW数据一般采用Bayer格式。Bayer格式的数码影像中每个像素仅存在红、绿、蓝三原色中的其中一种颜色分量,需要借助当前像素周围的颜色对其进行插值另外两种颜色。In order to reduce the complexity and cost of optical path control and photosensitive imaging chips, the imaging raw data of most electronic products that can be used to shoot digital images generally adopts the Bayer format. In the digital image of Bayer format, only one of the three primary colors of red, green, and blue exists in each pixel, and the other two colors need to be interpolated with the help of the colors around the current pixel.

具体的,去马赛克的装置获取到Bayer格式的数码影像,在对其进行去马赛克处理时,需要在该数码影像中获取以当前位置像素为中心的n×n(n大于等于3)的像素阵列,以获取到当前位置像素的颜色缺失分量。Specifically, the demosaicing device obtains a digital image in Bayer format, and when performing demosaic processing on it, it is necessary to obtain an n×n (n greater than or equal to 3) pixel array centered on the current position pixel in the digital image , to get the missing color component of the pixel at the current location.

其中,n等于5为本发明方法的最优选择,本发明实施例中采用n等于5来进行说明。Wherein, n equal to 5 is the optimal choice of the method of the present invention, and n is equal to 5 in the embodiment of the present invention for illustration.

示例性的,图4为一个5x5的像素阵列,Ci表示该像素阵列中各个位置的颜色分量值。Exemplarily, FIG. 4 is a 5x5 pixel array, and Ci represents the color component value of each position in the pixel array.

S202、去马赛克的装置获得当前位置像素在多个预设方向上的梯度值,并根据多个预设方向上的梯度值确定当前位置像素的梯度阈值。S202. The demosaicing device obtains gradient values of the pixel at the current position in multiple preset directions, and determines a gradient threshold of the pixel at the current position according to the gradient values in the multiple preset directions.

由于,自然景物颜色信息是平稳变化的,且每个像素颜色的变化梯度在不同方向上是不同的,为了保证对当前位置像素进行颜色插值后,当前位置像素的颜色能够有效恢复,去马赛克的装置选择颜色变化较小的方向,即去马赛克的装置选择颜色梯度较小的方向。Since the color information of natural scenery changes smoothly, and the color gradient of each pixel is different in different directions, in order to ensure that the color of the current position pixel can be effectively restored after the color interpolation is performed on the current position pixel, demosaicing The device chooses the direction with smaller color change, that is, the demosaiced device chooses the direction with smaller color gradient.

具体的,在对数码影像进行去马赛克处理时,为了获取到颜色梯度变化较小的方向,去马赛克的装置先获得当前位置像素在多个预设方向上的梯度值,并根据多个预设方向上的梯度值确定梯度阈值。Specifically, when performing demosaic processing on a digital image, in order to obtain the direction in which the color gradient changes less, the demosaic device first obtains the gradient values of the pixels at the current position in multiple preset directions, and according to the multiple preset The gradient value in the direction determines the gradient threshold.

其中,如图4所示,多个预设方向可以为当前位置像素的东、西、南、北、东北、东南、西南和西北这八个方向,也可以为其他预设方向。Wherein, as shown in FIG. 4 , the multiple preset directions may be eight directions of east, west, south, north, northeast, southeast, southwest and northwest of the current position pixel, or other preset directions.

具体的,去马赛克的装置根据当前位置像素的颜色信息,按照与颜色信息相对应的预设规则计算当前位置像素在多个预设方向上的梯度值。在获得当前位置像素在多个预设方向上的梯度值后,去马赛克的装置根据获得到的多个梯度值,确定当前位置像素的梯度阈值,以保证能够确定当前位置像素的颜色变化最小的方向,进而有效获得当前位置像素的缺失颜色值。Specifically, according to the color information of the pixel at the current position, the demosaicing device calculates the gradient values of the pixel at the current position in multiple preset directions according to a preset rule corresponding to the color information. After obtaining the gradient values of the pixel at the current position in multiple preset directions, the demosaicing device determines the gradient threshold of the pixel at the current position according to the obtained multiple gradient values, so as to ensure that the pixel at the current position has the smallest color change. direction, and then effectively obtain the missing color value of the pixel at the current position.

进一步地,去马赛克的装置在获取到的像素阵列中,若当前位置像素为G分量像素,则按照第一预设规则计算当前位置像素在像素阵列中的多个预设方向上的梯度值;若当前位置为R分量像素或B分量像素,则按照第二预设规则计算当前位置像素在像素阵列中的多个预设方向上的梯度值。Further, in the acquired pixel array, if the pixel at the current position is a G component pixel, the device for demosaicing calculates gradient values of the pixel at the current position in multiple preset directions in the pixel array according to a first preset rule; If the current position is an R component pixel or a B component pixel, the gradient values of the pixel at the current position in multiple preset directions in the pixel array are calculated according to a second preset rule.

示例性的,若像素阵列为5x5的阵列,当前位置(x,y)像素为G分量像素,多个预设方向为当前位置像素的东、西、南、北、东北、东南、西南和西北这八个方向,则采用以下公式计算当前位置像素在这八个方向上的梯度值:Exemplarily, if the pixel array is a 5x5 array, the current position (x, y) pixel is the G component pixel, and the multiple preset directions are east, west, south, north, northeast, southeast, southwest and northwest of the current position pixel For these eight directions, use the following formula to calculate the gradient value of the current position pixel in these eight directions:

GradGrad__NN==absabs((BLSBLS[[11]][[33]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[22]][[33]]--BLSBLS[[44]][[33]]))++absabs((BLSBLS[[22]][[22]]))--BLSBLS[[44]][[22]]++absabs((BLSBLS[[22]][[44]]--BLSBLS[[44]][[44]]))++absabs((BLSBLS[[11]][[22]]--BLSBLS[[33]][[22]]))++absabs((BLSBLS[[11]][[44]]--BLSBLS[[33]][[44]]))//44

GradGrad__EE.==absabs((BLSBLS[[33]][[44]]--BLSBLS[[33]][[22]]))++absabs((BLSBLS[[33]][[55]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[22]][[44]]))--BLSBLS[[22]][[22]]++absabs((BLSBLS[[22]][[44]]--BLSBLS[[44]][[44]]))++absabs((BLSBLS[[22]][[55]]--BLSBLS[[22]][[33]]))++absabs((BLSBLS[[44]][[55]]--BLSBLS[[44]][[33]]))//44

GradGrad__SS==absabs((BLSBLS[[44]][[33]]--BLSBLS[[22]][[33]]))++absabs((BLSBLS[[55]][[33]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[44]][[44]]))--BLSBLS[[22]][[44]]++absabs((BLSBLS[[44]][[22]]--BLSBLS[[22]][[22]]))++absabs((BLSBLS[[55]][[44]]--BLSBLS[[33]][[44]]))++absabs((BLSBLS[[55]][[22]]--BLSBLS[[33]][[22]]))//44

GradGrad__WW==absabs((BLSBLS[[33]][[22]]--BLSBLS[[33]][[44]]))++absabs((BLSBLS[[33]][[11]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[44]][[22]]))--BLSBLS[[44]][[44]]++absabs((BLSBLS[[22]][[22]]--BLSBLS[[22]][[44]]))++absabs((BLSBLS[[44]][[11]]--BLSBLS[[44]][[33]]))++absabs((BLSBLS[[22]][[11]]--BLSBLS[[22]][[33]]))//44

Grad_NE=abs(BLS[2][4]-BLS[4][2])+abs(BLS[1][5]-BLS[3][3])+abs(BLS[1][4]-BLS[3][2])+abs(BLS[2][5]-BLS[4][3])Grad_NE=abs(BLS[2][4]-BLS[4][2])+abs(BLS[1][5]-BLS[3][3])+abs(BLS[1][4]- BLS[3][2])+abs(BLS[2][5]-BLS[4][3])

Grad_SE=abs(BLS[4][4]-BLS[2][2])+abs(BLS[5][5]-BLS[3][3])+abs(BLS[4][5]-BLS[2][3])+abs(BLS[5][4]-BLS[3][2])Grad_SE=abs(BLS[4][4]-BLS[2][2])+abs(BLS[5][5]-BLS[3][3])+abs(BLS[4][5]- BLS[2][3])+abs(BLS[5][4]-BLS[3][2])

Grad_NW=abs(BLS[2][2]-BLS[4][4])+abs(BLS[1][1]-BLS[3][3])+abs(BLS[2][1]-BLS[4][3])+abs(BLS[1][2]-BLS[3][4])Grad_NW=abs(BLS[2][2]-BLS[4][4])+abs(BLS[1][1]-BLS[3][3])+abs(BLS[2][1]- BLS[4][3])+abs(BLS[1][2]-BLS[3][4])

Grad_SW=abs(BLS[4][2]-BLS[2][4])+abs(BLS[5][1]-BLS[3][3])+abs(BLS[5][2]-BLS[3][4])+abs(BLS[4][1]-BLS[2][3])Grad_SW=abs(BLS[4][2]-BLS[2][4])+abs(BLS[5][1]-BLS[3][3])+abs(BLS[5][2]- BLS[3][4])+abs(BLS[4][1]-BLS[2][3])

其中,N代表当前位置像素的北方向,E代表当前位置像素的东方向,E代表当前位置像素的西方向,S代表当前位置像素的南方向,NE代表当前位置像素的东北方向,SE代表当前位置像素的东南方向,NW代表当前位置像素的西北方向,SW代表当前位置像素的西南向,Grad_N、Grad_E、Grad_S、Grad_W、Grad_NE、Grad_SE、Grad_NW、Grad_SW分别为对应方向的梯度值,BLS[y][x]表示Bayer格式的5x5邻域第y行第x列的像素值,abs(.)表示求绝对值。Among them, N represents the north direction of the current position pixel, E represents the east direction of the current position pixel, E represents the west direction of the current position pixel, S represents the south direction of the current position pixel, NE represents the northeast direction of the current position pixel, and SE represents the current The southeast direction of the position pixel, NW represents the northwest direction of the current position pixel, SW represents the southwest direction of the current position pixel, Grad_N, Grad_E, Grad_S, Grad_W, Grad_NE, Grad_SE, Grad_NW, Grad_SW are the gradient values of the corresponding directions, BLS[y ][x] indicates the pixel value of row y and column x in the 5x5 neighborhood of Bayer format, and abs (.) indicates the absolute value.

若像素阵列为5x5的阵列,当前位置(x,y)像素为R分量像素或者B分量像素,多个预设方向为当前位置像素的东、西、南、北、东北、东南、西南和西北这八个方向,则采用以下公式计算当前位置像素在这八个方向上的梯度值:If the pixel array is a 5x5 array, the current position (x, y) pixel is an R component pixel or a B component pixel, and multiple preset directions are east, west, south, north, northeast, southeast, southwest and northwest of the current position pixel For these eight directions, use the following formula to calculate the gradient value of the current position pixel in these eight directions:

GradGrad__NN==absabs((BLSBLS[[22]][[33]]--BLSBLS[[44]][[33]]))++absabs((BLSBLS[[11]][[33]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[22]][[22]]))--BLSBLS[[44]][[22]]++absabs((BLSBLS[[22]][[44]]--BLSBLS[[44]][[44]]))++absabs((BLSBLS[[11]][[22]]--BLSBLS[[33]][[22]]))++absabs((BLSBLS[[11]][[44]]--BLSBLS[[33]][[44]]))//22

GradGrad__EE.==absabs((BLSBLS[[33]][[44]]--BLSBLS[[33]][[22]]))++absabs((BLSBLS[[33]][[55]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[22]][[44]]))--BLSBLS[[22]][[22]]++absabs((BLSBLS[[44]][[44]]--BLSBLS[[44]][[22]]))++absabs((BLSBLS[[22]][[55]]--BLSBLS[[22]][[33]]))++absabs((BLSBLS[[44]][[55]]--BLSBLS[[44]][[33]]))//22

GradGrad__SS==absabs((BLSBLS[[44]][[33]]--BLSBLS[[22]][[33]]))++absabs((BLSBLS[[55]][[33]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[44]][[44]]))--BLSBLS[[22]][[44]]++absabs((BLSBLS[[44]][[22]]--BLSBLS[[22]][[22]]))++absabs((BLSBLS[[55]][[44]]--BLSBLS[[33]][[44]]))++absabs((BLSBLS[[55]][[22]]--BLSBLS[[33]][[22]]))//22

GradGrad__WW==absabs((BLSBLS[[33]][[22]]--BLSBLS[[33]][[44]]))++absabs((BLSBLS[[33]][[11]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[44]][[22]]))--BLSBLS[[44]][[44]]++absabs((BLSBLS[[22]][[22]]--BLSBLS[[22]][[44]]))++absabs((BLSBLS[[44]][[11]]--BLSBLS[[44]][[33]]))++absabs((BLSBLS[[22]][[11]]--BLSBLS[[22]][[33]]))//22

GradGrad__NENE==absabs((BLSBLS[[22]][[44]]--BLSBLS[[44]][[22]]))++absabs((BLSBLS[[11]][[55]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[22]][[33]]))--BLSBLS[[33]][[22]]++absabs((BLSBLS[[33]][[44]]--BLSBLS[[44]][[33]]))++absabs((BLSBLS[[11]][[44]]--BLSBLS[[22]][[33]]))++absabs((BLSBLS[[22]][[55]]--BLSBLS[[33]][[44]]))//22

GradGrad__SESE==absabs((BLSBLS[[44]][[44]]--BLSBLS[[22]][[22]]))++absabs((BLSBLS[[55]][[55]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[33]][[44]]))--BLSBLS[[22]][[33]]++absabs((BLSBLS[[44]][[33]]--BLSBLS[[33]][[22]]))++absabs((BLSBLS[[44]][[55]]--BLSBLS[[33]][[44]]))++absabs((BLSBLS[[55]][[44]]--BLSBLS[[44]][[33]]))//22

GradGrad__NWNW==absabs((BLSBLS[[22]][[22]]--BLSBLS[[44]][[44]]))++absabs((BLSBLS[[11]][[11]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[33]][[22]]))--BLSBLS[[44]][[33]]++absabs((BLSBLS[[22]][[33]]--BLSBLS[[33]][[44]]))++absabs((BLSBLS[[22]][[11]]--BLSBLS[[33]][[22]]))++absabs((BLSBLS[[11]][[22]]--BLSBLS[[22]][[33]]))//22

GradGrad__SWSW==absabs((BLSBLS[[44]][[22]]--BLSBLS[[22]][[44]]))++absabs((BLSBLS[[55]][[11]]--BLSBLS[[33]][[33]]))++absabs((BLSBLS[[44]][[33]]))--BLSBLS[[33]][[44]]++absabs((BLSBLS[[33]][[22]]--BLSBLS[[22]][[33]]))++absabs((BLSBLS[[55]][[22]]--BLSBLS[[44]][[33]]))++absabs((BLSBLS[[44]][[11]]--BLSBLS[[33]][[22]]))//22

其中,N代表当前位置像素的北方向,E代表当前位置像素的东方向,E代表当前位置像素的西方向,S代表当前位置像素的南方向,NE代表当前位置像素的东北方向,SE代表当前位置像素的东南方向,NW代表当前位置像素的西北方向,SW代表当前位置像素的西南向,Grad_N、Grad_E、Grad_S、Grad_W、Grad_NE、Grad_SE、Grad_NW、Grad_SW分别为对应方向的梯度值,BLS[y][x]表示Bayer格式的5x5邻域第y行第x列的像素值,abs(.)表示求绝对值。Among them, N represents the north direction of the current position pixel, E represents the east direction of the current position pixel, E represents the west direction of the current position pixel, S represents the south direction of the current position pixel, NE represents the northeast direction of the current position pixel, and SE represents the current The southeast direction of the position pixel, NW represents the northwest direction of the current position pixel, SW represents the southwest direction of the current position pixel, Grad_N, Grad_E, Grad_S, Grad_W, Grad_NE, Grad_SE, Grad_NW, Grad_SW are the gradient values of the corresponding directions, BLS[y ][x] indicates the pixel value of row y and column x in the 5x5 neighborhood of Bayer format, and abs (.) indicates the absolute value.

需要说明的是,去马赛克的装置确定的梯度阈值可以为该梯度阈值小于当前位置像素在多个预设方向上的梯度值的最大值与最小值的差值的三分之二,也可以为该梯度阈值大于当前位置像素在多个预设方向上的梯度值的最小值,且小于当前位置像素在多个预设方向上的梯度值的中间值,本发明实施例不做限定。It should be noted that the gradient threshold determined by the demosaicing device may be less than two-thirds of the difference between the maximum value and the minimum value of the gradient values of the current location pixel in multiple preset directions, or may be The gradient threshold is greater than the minimum value of the gradient values of the pixel at the current position in multiple preset directions, and is smaller than the median value of the gradient values of the pixel at the current position in multiple preset directions, which is not limited in this embodiment of the present invention.

例如,去马赛克的装置对一幅包含平行栅栏的建筑物Bayer格式图像进行去马赛克处理,图6为其中一个5x5区域RGB分量数据示例。其中,R分量用斜体表示,B分量加下划线表示,G分量加粗表示。去马赛克的装置按照上述计算梯度值的公式,计算图中各个位置像素八个邻域方向的梯度值,其中,图6中心点位置像素为R分量像素,采用本文前述当前位置像素为R分量像素时计算当前位置像素的梯度值的公式计算该中心位置像素的八个梯度值,这八个邻域方向的梯度值从中心点位置像素的北方向开始,按照方向的顺时针排列依次为:567、480、23、459、559、462、19、461。去马赛克的装置在获得中心点位置像素在八个方向上的梯度值后,根据这八个梯度值,将梯度值范围的一半加上最小梯度值的1.5倍确定为梯度阈值,即梯度阈值为302。For example, the demosaicing device performs demosaic processing on a Bayer format image of a building containing parallel fences, and FIG. 6 is an example of RGB component data of a 5x5 area. Among them, the R component is shown in italics, the B component is underlined, and the G component is bolded. The demosaicing device calculates the gradient values in eight neighborhood directions of each position pixel in the figure according to the above formula for calculating the gradient value, wherein the pixel at the center point in Figure 6 is the R component pixel, and the current position pixel mentioned above in this article is used as the R component pixel The formula for calculating the gradient value of the current position pixel calculates the eight gradient values of the center position pixel. The gradient values of the eight neighborhood directions start from the north direction of the center point position pixel and are arranged clockwise according to the direction: 567 , 480, 23, 459, 559, 462, 19, 461. After the demosaicing device obtains the gradient values of the center point pixel in eight directions, according to these eight gradient values, half of the gradient value range plus 1.5 times the minimum gradient value is determined as the gradient threshold, that is, the gradient threshold is 302.

S203、去马赛克的装置比较多个预设方向上的梯度值和当前位置像素的梯度阈值,并在多个预设方向确定梯度值小于梯度阈值的方向为当前位置像素的目标方向。S203. The demosaicing device compares the gradient values in multiple preset directions with the gradient threshold value of the current position pixel, and determines that the direction whose gradient value is smaller than the gradient threshold value in multiple preset directions is the target direction of the current position pixel.

为了保证对当前位置像素进行颜色插值后,当前位置像素的颜色能够有效恢复,去马赛克的装置在获得当前位置像素在多个预设方向上的梯度值,并根据多个预设方向上的梯度值确定当前位置像素的梯度阈值后,比较多个预设方向上的梯度值和当前位置像素的梯度阈值,确定选择颜色变化较小的方向,即去马赛克的装置选择颜色梯度较小的方向。In order to ensure that the color of the pixel at the current position can be effectively restored after color interpolation is performed on the pixel at the current position, the demosaicing device obtains the gradient values of the pixel at the current position in multiple preset directions, and according to the gradient values in the multiple preset directions After the gradient threshold of the current position pixel is determined, the gradient values in multiple preset directions are compared with the gradient threshold of the current position pixel to determine the direction with smaller color change, that is, the demosaic device selects the direction with smaller color gradient.

具体的,去马赛克的装置比较多个预设方向上的梯度值和当前位置像素的梯度阈值,然后,去马赛克的装置在多个预设方向中,将梯度值小于梯度阈值的方向确定为当前位置像素的目标方向。Specifically, the demosaicing device compares the gradient values in multiple preset directions with the gradient threshold value of the current position pixel, and then, among the multiple preset directions, the demosaicing device determines the direction whose gradient value is smaller than the gradient threshold value as the current The target orientation of the loxel.

S204、去马赛克的装置确定当前位置像素的相对亮度分量信息。S204. The device for demosaicing determines the relative brightness component information of the pixel at the current position.

对数码影像进行去马赛克的过程中,不仅仅要考虑到色度的变化,也要考虑到亮度的变化。在色度亮度快速变化的场景中,尤其需要考虑亮度的变化对去马赛克结果的影响。In the process of demosaicing digital images, not only changes in chromaticity, but also changes in brightness must be considered. In a scene where the chroma and brightness change rapidly, it is especially necessary to consider the influence of the brightness change on the demosaicing result.

去马赛克的装置获得到当前位置像素在多个预设方向上的梯度值和当前位置像素的梯度阈值后,确定当前位置像素的相对亮度分量信息。After obtaining the gradient values of the pixel at the current position in multiple preset directions and the gradient threshold of the pixel at the current position, the device for demosaicing determines the relative brightness component information of the pixel at the current position.

Bayer格式的数码影像中G分量的分布密度是R、B的两倍,任意一行或一列中均有G分量,而R或B分量是间隔一行或一列分布的。因此,在一个设定的领域内,G分量在四个或八个方向上均有采样值,但R或B分量只在部分方向存在采样值。The distribution density of the G component in the Bayer format digital image is twice that of R and B, and there is a G component in any row or column, while the R or B components are distributed every other row or column. Therefore, in a set area, the G component has sampling values in four or eight directions, but the R or B component only has sampling values in some directions.

实际场景的亮度、色度只会在某个趋势方向上快速变化,而G分量在各个方向上均存在采样值并且G分量对于像素亮度的贡献为60%,可以代表亮度的变化趋势。因此,本发明方法优先选择G分量作为场景亮度变化趋势的控制参数。The brightness and chromaticity of the actual scene will only change rapidly in a certain trend direction, while the G component has sampling values in all directions and the contribution of the G component to the pixel brightness is 60%, which can represent the change trend of brightness. Therefore, the method of the present invention preferably selects the G component as the control parameter of the scene brightness variation trend.

具体的,若当前位置像素为G分量像素,则将当前位置像素的G分量值作为当前位置像素的相对亮度分量信息;若当前位置像素为R分量像素或B分量像素,则计算当前位置像素的各个目标方向的G分量值的第一算术平均值,并将第一算术平均值确定为当前位置像素的相对亮度分量信息,其中,目标方向为梯度值小于梯度阈值的方向,当前位置像素的目标方向至少有一个。Specifically, if the current position pixel is a G component pixel, then use the G component value of the current position pixel as the relative brightness component information of the current position pixel; if the current position pixel is an R component pixel or a B component pixel, then calculate the current position pixel’s The first arithmetic mean value of the G component value of each target direction, and determine the first arithmetic mean value as the relative brightness component information of the current position pixel, wherein, the target direction is the direction whose gradient value is less than the gradient threshold value, and the target value of the current position pixel There is at least one direction.

进一步地,去马赛克的装置采用以下公式确定当前位置像素的相对亮度分量信息:Further, the demosaicing device uses the following formula to determine the relative brightness component information of the pixel at the current position:

Figure BDA0000472681420000191
Figure BDA0000472681420000191

其中,Y代表当前位置像素的相对亮度分量信息,N为梯度值小于梯度阈值的方向个数,Gi为梯度值小于梯度阈值的方向上的G分量值,Grad(i)为当前位置像素的在各个预设方向上的梯度值,Threshold为去马赛克的装置确定的梯度阈值,

Figure BDA0000472681420000192
为当前位置像素的各个目标方向的G分量值的求和。Among them, Y represents the relative brightness component information of the pixel at the current position, N is the number of directions where the gradient value is less than the gradient threshold, Gi is the G component value in the direction where the gradient value is less than the gradient threshold, and Grad(i) is the pixel at the current position. The gradient value in each preset direction, Threshold is the gradient threshold determined by the demosaicing device,
Figure BDA0000472681420000192
It is the sum of the G component values of each target direction of the current position pixel.

示例性的,图6中心点位置像素为R分量像素,该中心点位置像素的八个邻域方向的梯度值从中心点位置像素的北方向起,按照方向的顺时针排列依次为:567、480、23、459、559、462、19、461,梯度阈值为302。这八个邻域方向的梯度值中,梯度值23和19均小于梯度阈值302,即中心点位置像素的东方向和西方向的梯度值小于梯度阈值。中心点位置像素的东方向的G分量值为256,西方向的G分量值为257,因此,去马赛克的装置在计算中心点位置的相对亮度分量信息时,具体计算公式为:Y=(256+257)/2=256.5。Exemplarily, the pixel at the center point in Figure 6 is an R component pixel, and the gradient values of the eight neighborhood directions of the pixel at the center point start from the north direction of the pixel at the center point, and are arranged clockwise according to the directions: 567, 480, 23, 459, 559, 462, 19, 461 with a gradient threshold of 302. Among the gradient values in the eight neighborhood directions, the gradient values 23 and 19 are both smaller than the gradient threshold 302 , that is, the gradient values in the east and west directions of the pixel at the center point are smaller than the gradient threshold. The G component value of the east direction of the center point pixel is 256, and the G component value of the west direction is 257. Therefore, when the demosaic device calculates the relative brightness component information of the center point position, the specific calculation formula is: Y=(256 +257)/2=256.5.

S205、去马赛克的装置根据当前位置像素的相对亮度分量信息,获得当前位置像素的各个目标方向上的颜色值。S205. The device for demosaicing obtains color values in each target direction of the pixel at the current position according to the relative brightness component information of the pixel at the current position.

具体的,当前位置像素在像素阵列中的各个目标方向上,至少有一个像素存在,去马赛克的装置在像素阵列中,先获得各个目标方向上的每个位置像素的相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息和各个目标方向上的每个位置像素的相对亮度分量信息,计算当前位置像素的各个目标方向上的颜色值。Specifically, at least one pixel exists in each target direction of the current position pixel in the pixel array, and the demosaic device first obtains the relative brightness component information of each position pixel in each target direction in the pixel array, and then, According to the relative brightness component information of the pixel at the current position and the relative brightness component information of each pixel at each target direction, the color value of the pixel at the current position in each target direction is calculated.

需要说明的是,去马赛克的装置获得各个目标方向上的每个位置像素的相对亮度分量信息的方法与去马赛克的装置获得当前位置像素的相对亮度分量信息的方法是相同的。It should be noted that the method for the demosaicing device to obtain the relative brightness component information of each position pixel in each target direction is the same as the method for the demosaicing device to obtain the relative brightness component information of the current position pixel.

示例性的,去马赛克的装置获得当前位置像素的东侧的第一位置像素的相对亮度分量信息的方法为:去马赛克的装置获取以第一位置像素为中心的n×n的第一像素阵列,按照本发明实施例中的S202和S203的方法获得当前位置像素的东侧的第一位置像素的相对亮度分量信息。Exemplarily, the method for the demosaicing device to obtain the relative brightness component information of the first position pixel on the east side of the current position pixel is as follows: the demosaicing device obtains a first n×n pixel array centered on the first position pixel According to the method of S202 and S203 in the embodiment of the present invention, the relative brightness component information of the pixel at the first position on the east side of the pixel at the current position is obtained.

需要说明的是,各个目标方向上的颜色值包括各个目标方向上的R分量、G分量和B分量的值。It should be noted that the color values in each target direction include the values of R component, G component and B component in each target direction.

具体的,当前位置像素的各个目标方向上的颜色值的计算公式为:Specifically, the calculation formula of the color value in each target direction of the pixel at the current position is:

CaCa((ii))==11NNYY&Sigma;&Sigma;GradGrad((ii))<<ThresholdThresholdCiCi//YiYi

其中,Ca(i)为各个目标方向上的R分量、G分量、B分量的颜色值,N为目标方向的个数,Y为当前位置像素的相对亮度分量信息,Ci为目标方向的每个位置像素的颜色分量值,Yi为与Ci对应的相对亮度分量信息,

Figure BDA0000472681420000202
为在各个目标方向上对Ci/Yi求和。Among them, Ca(i) is the color value of R component, G component, and B component in each target direction, N is the number of target directions, Y is the relative brightness component information of the current position pixel, and Ci is the color value of each target direction. The color component value of the position pixel, Yi is the relative brightness component information corresponding to Ci,
Figure BDA0000472681420000202
To sum Ci/Yi in each target direction.

S206、去马赛克的装置根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值。S206. The device for demosaicing calculates a color average value according to the color values in each target direction of the pixel at the current position.

目标方向是梯度值小于梯度阈值的方向,去马赛克的装置在各个目标方向上获取到颜色值后,根据颜色信息将这些颜色值进行平均获得颜色平均值,进而利用颜色平均值对当前位置像素进行颜色插值,即去马赛克的装置根据获得到的当前位置像素的各个目标方向上的颜色值,统计颜色平均值。The target direction is the direction where the gradient value is less than the gradient threshold. After the demosaicing device obtains the color values in each target direction, it averages these color values according to the color information to obtain the color average value, and then uses the color average value to perform a Color interpolation, that is, the device for demosaicing calculates the color average value according to the obtained color values in each target direction of the pixel at the current position.

具体的,去马赛克的装置获取到各个目标方向上的R分量、G分量和B分量的颜色值后,将获取到的颜色值根据颜色信息的不同,分别计算出R分量、G分量和B分量的颜色平均值。Specifically, after the demosaicing device acquires the color values of the R component, G component and B component in each target direction, it calculates the R component, G component and B component from the acquired color values according to the color information. color average.

进一步地,去马赛克的装置根据当前位置像素在各个目标方向上的梯度值和当前位置像素的各个目标方向上的颜色值,计算当前位置像素在各个目标方向上的梯度值的加权平均值,以获得颜色平均值;Further, the demosaicing device calculates the weighted average value of the gradient value of the current position pixel in each target direction according to the gradient value of the current position pixel in each target direction and the color value of the current position pixel in each target direction, to obtain Get the color average;

或者,or,

去马赛克的装置计算当前位置像素的各个目标方向上的颜色值的第二算术平均值,其中,第二算术平均值为颜色平均值。The device for demosaicing calculates a second arithmetic mean value of color values in each target direction of the pixel at the current position, wherein the second arithmetic mean value is a color mean value.

具体的,去马赛克的装置根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值采用以下公式:Specifically, the device for demosaicing uses the following formula to calculate the average value of colors according to the color values in each target direction of the pixel at the current position:

CwavgCwavg==11NN**GradSumGradSum&Sigma;&Sigma;GradGrad((ii))<<ThresholdThresholdCaCa((ii))**[[GardSumGardSum--GardGard((ii))]]

其中,Cwavg为不同颜色信息的颜色平均值,N为目标方向的数量,GradSum为梯度值小于梯度阈值的各个方向上的梯度值之和,Ca(i)为各个目标方向上的R分量、G分量、B分量的颜色值,Grad(i)为各个目标方向的梯度值。Among them, Cwavg is the color average value of different color information, N is the number of target directions, GradSum is the sum of gradient values in each direction whose gradient value is less than the gradient threshold, Ca(i) is the R component in each target direction, G The color values of component and B component, Grad(i) is the gradient value of each target direction.

进一步地,由于本发明的方法已设定了梯度阈值,只对梯度较小的邻域方向进行运算,因此,去马赛克的装置在统计颜色平均值时,也可以不根据各个方向的梯度加权平均而简化为等权计算,具体采用以下公式:Further, since the method of the present invention has set the gradient threshold, and only performs calculations on the neighborhood directions with small gradients, the demosaicing device may not use the weighted average of the gradients in each direction when counting the average color. However, it is simplified to equal-weight calculation, and the following formula is used specifically:

CwavgCwavg==11NN&Sigma;&Sigma;GradGrad((ii))<<ThresholdThresholdCaCa((ii))

其中,Cwavg为不同颜色信息的颜色平均值,N为目标方向的数量,Ca(i)为各个目标方向上的R分量、G分量、B分量的颜色值,为对各个目标方向上的颜色值进行求和。Among them, Cwavg is the color average value of different color information, N is the number of target directions, Ca(i) is the color value of R component, G component, and B component in each target direction, To sum the color values in each target direction.

示例性的,按照上述公式,计算得到图6中心点位置像素小于梯度阈值的方向邻域颜色平均值为:R分量为179,G分量为257,B分量为156。Exemplarily, according to the above formula, the average value of the neighborhood color in the direction where the pixel at the center point in Fig. 6 is smaller than the gradient threshold is calculated as follows: the R component is 179, the G component is 257, and the B component is 156.

S207、去马赛克的装置根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值。S207. The demosaicing device obtains the missing color component value of the pixel at the current position according to the known color component value and the color average value of the pixel at the current position.

去马赛克的装置统计出颜色平均值后,利用当前位置像素的已知颜色分量值和颜色平均值,即可直接计算出当前位置像素的缺失颜色分量值。After the demosaicing device counts the color average value, the missing color component value of the pixel at the current position can be directly calculated by using the known color component value and the color average value of the pixel at the current position.

具体的,去马赛克的装置计算当前位置像素的缺失颜色分量值采用以下公式:Specifically, the demosaicing device calculates the missing color component value of the pixel at the current position using the following formula:

C1=C0+C1wavg-C0wavgC1=C0+C1wavg-C0wavg

C2=C0+C2wavg-C0wavgC2=C0+C2wavg-C0wavg

其中,C0为当前位置像素的已知颜色分量值,C1、C2为当前位置像素的缺失颜色分量值,C0wavg为当前位置像素在各个目标方向上的已知颜色分量的平均值,C1wavg、C2wavg为当前位置像素在各个目标方向上的缺失颜色分量的平均值。Among them, C0 is the known color component value of the pixel at the current position, C1 and C2 are the missing color component values of the pixel at the current position, C0wavg is the average value of the known color components of the pixel at the current position in each target direction, and C1wavg and C2wavg are The average of the missing color components of the pixel at the current location in each target direction.

需要说明的是,本发明的方法中,去马赛克的装置对Bayer格式的数码影像进行去马赛克处理时,对该数码影像中的每个位置的像素都采用如本发明实施例说明的方法获得缺失颜色分量值。It should be noted that, in the method of the present invention, when the demosaicing device performs demosaic processing on the digital image in Bayer format, the pixels at each position in the digital image are obtained by the method as described in the embodiment of the present invention to obtain the missing Color component values.

示例性的,按照本发明实施例的方法计算图6中心点位置像素的RGB分量为:180,258,157。Exemplarily, the RGB components calculated according to the method of the embodiment of the present invention are: 180, 258, 157 of the pixel at the center point in Fig. 6 .

相对应的,对于图6中心点位置像素的RGB分量,如果采用现有的去马赛克方法中的实际效果最好的VNG方法来计算的话,图6中心点位置像素的RGB分量为180,257,236。与本发明的方法相比较,采用VNG方法进行去马赛克的话,将会导致B通道值显著偏高,进而导致彩点异常值。Correspondingly, for the RGB components of the pixel at the center point in Figure 6, if the VNG method with the best actual effect among the existing demosaicing methods is used to calculate, the RGB components of the pixel at the center point in Figure 6 are 180,257,236. Compared with the method of the present invention, if the VNG method is used for demosaicing, the value of the B channel will be significantly higher, and then the abnormal value of the color point will be caused.

S208、去马赛克的装置根据当前位置像素的已知颜色分量值和当前位置像素的缺失颜色分量值,输出当前位置像素。S208. The demosaicing device outputs the pixel at the current position according to the known color component value of the pixel at the current position and the missing color component value of the pixel at the current position.

RGB三通道格式的数码影像在存储颜色信息的时候会针对每个像素的RGB颜色进行存储,也就是存储每个像素的RGB值。在显示输出数码影像时,为了恢复数码影像的真实颜色信息,将数码影像从Bayer格式转换为RGB三通道格式,即对数码影像进行Demosaic。Digital images in RGB three-channel format will store the RGB color of each pixel when storing color information, that is, store the RGB value of each pixel. When displaying and outputting digital images, in order to restore the true color information of the digital images, the digital images are converted from the Bayer format to the RGB three-channel format, that is, the digital images are demosaiced.

去马赛克的装置在获得到当前位置像素的缺失颜色分量值后,将该缺失颜色分量值存储,去马赛克的装置获就获得了当前位置像素的三原色中的三种颜色分量值,去马赛克的装置将当前位置像素按照这三种颜色分量值输出,即去马赛克的装置将该当前位置像素按照RGB格式输出显示,即完成了对当前位置像素的去马赛克处理。After the demosaicing device obtains the missing color component value of the current position pixel, it stores the missing color component value, and the demosaicing device obtains the three color component values in the three primary colors of the current position pixel, and the demosaicing device The pixel at the current position is output according to the values of the three color components, that is, the demosaicing device outputs and displays the pixel at the current position according to the RGB format, that is, the demosaicing process on the pixel at the current position is completed.

进一步地,去马赛克的装置对Bayer格式的数码影像进行去马赛克处理时,对该数码影像中的每个位置的像素都采用如本发明实施例说明的方法获得其缺失颜色分量值,最终,去马赛克的装置将Bayer格式的数码影像中的每个位置的像素均以RGB格式输出,完成对Bayer格式的数码影像的去马赛克处理。Further, when the demosaicing device performs demosaic processing on a digital image in Bayer format, the pixel at each position in the digital image is obtained by the method as described in the embodiment of the present invention to obtain its missing color component value, and finally, the de-mosaic The mosaic device outputs the pixels of each position in the Bayer format digital image in RGB format, and completes the demosaic processing of the Bayer format digital image.

现有的去马赛克的方法仅仅是考虑颜色梯度的方向性而选择变化较小的方向的颜色信息进行平均得到当前位置像素的缺失颜色信息。与现有的去马赛克的方法不同,本发明方法中,由于去马赛克的装置获得的各个目标方向的颜色值是根据当前位置像素的相对亮度分量信息和各个目标方向上的每个位置像素的相对亮度分量信息得到的,因此,去马赛克的装置获得的颜色平均值也是依据相对亮度分量信息得到的。这样,本发明方法中,去马赛克的装置获得的当前位置像素的缺失颜色分量值更加准确,即使在颜色快速变化的同时亮度也急剧变化的场景中,也能有效的恢复像素的真实颜色。The existing demosaicing method only considers the directionality of the color gradient and selects the color information in a direction with a small change for averaging to obtain the missing color information of the pixel at the current position. Different from the existing demosaicing method, in the method of the present invention, the color value of each target direction obtained by the demosaicing device is based on the relative brightness component information of the current position pixel and the relative brightness of each position pixel in each target direction. Therefore, the color average value obtained by the demosaicing device is also obtained based on the relative brightness component information. In this way, in the method of the present invention, the missing color component value of the pixel at the current position obtained by the demosaicing device is more accurate, even in a scene where the brightness changes rapidly while the color changes rapidly, the true color of the pixel can be effectively restored.

本发明的实施例提供一种去马赛克的方法,去马赛克的装置通过获得当前位置像素在多个预设方向上的梯度值,确定当前位置像素的和梯度阈值和相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息,在多个预设方向中确定当前位置像素的至少一个目标方向,其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向,获得当前位置像素的各个目标方向上的颜色值,其中,当前位置像素在所述目标方向上的梯度值小于所述梯度阈值,并根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值,最后,根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值,并根据已知颜色分量值和缺失颜色分量值,输出当前位置像素。通过该方案,本发明同时考虑了场景亮度和色度快速变化的情况,对色度和亮度进行了协同调整,解决了现有技术在此类型场景出现异常彩点或彩条的问题,改进了像素的彩色还原效果,能够有效恢复像素的真实颜色。An embodiment of the present invention provides a demosaicing method. The demosaicing device determines the sum gradient threshold and relative brightness component information of the current position pixel by obtaining the gradient values of the current position pixel in multiple preset directions, and then, according to The relative brightness component information of the pixel at the current position determines at least one target direction of the pixel at the current position in a plurality of preset directions, wherein the target direction is a direction in which the gradient value of the pixel at the current position in the plurality of preset directions is smaller than the gradient threshold, Obtain the color values of the current position pixel in each target direction, wherein the gradient value of the current position pixel in the target direction is smaller than the gradient threshold, and according to the color values of the current position pixel in each target direction, the statistical color average Finally, according to the known color component value and the color average value of the current position pixel, the missing color component value of the current position pixel is obtained, and according to the known color component value and the missing color component value, the current position pixel is output. Through this solution, the present invention simultaneously considers the situation of rapid changes in scene brightness and chroma, coordinates adjustments to chroma and brightness, solves the problem of abnormal color dots or color bars in this type of scene in the prior art, and improves The color restoration effect of pixels can effectively restore the true colors of pixels.

实施例三Embodiment three

本发明提供一种去马赛克的装置,如图7所示,包括:The present invention provides a demosaic device, as shown in Figure 7, comprising:

获取单元10,用于获得当前位置像素在多个预设方向上的梯度值,以及用于获得所述当前位置像素在所述多个预设方向中的各个目标方向上的颜色值,其中,所述目标方向为所述当前位置像素在所述多个预设方向中的梯度值小于所述梯度阈值的方向,所述当前位置像素有至少一个目标方向,以及用于根据所述当前位置像素的已知颜色分量值和所述颜色平均值,获得所述当前位置像素的缺失颜色分量值;The obtaining unit 10 is configured to obtain the gradient value of the pixel at the current position in multiple preset directions, and to obtain the color value of the pixel at the current position in each target direction in the multiple preset directions, wherein, The target direction is a direction in which the gradient value of the current position pixel in the plurality of preset directions is smaller than the gradient threshold, the current position pixel has at least one target direction, and is used to The known color component value and the color average value to obtain the missing color component value of the pixel at the current position;

确定单元11,用于根据所述获取单元10获取到的所述多个预设方向上的梯度值确定当前位置像素的梯度阈值,以及用于确定所述当前位置像素的相对亮度分量信息;A determining unit 11, configured to determine the gradient threshold of the pixel at the current position according to the gradient values in the plurality of preset directions acquired by the acquiring unit 10, and to determine the relative brightness component information of the pixel at the current position;

计算单元12,用于根据所述获取单元10获取到的所述当前位置像素的各个目标方向上的颜色值,统计颜色平均值;A calculation unit 12, configured to calculate a color average value according to the color values in each target direction of the pixel at the current position acquired by the acquisition unit 10;

输出单元13,用于根据所述已知颜色分量值和所述获取单元10获取到的所述缺失颜色分量值,输出所述当前位置像素。The output unit 13 is configured to output the pixel at the current position according to the known color component value and the missing color component value acquired by the acquiring unit 10 .

进一步地,所述确定单元11,还用于在确定当前位置像素梯度阈值之后,确定所述当前位置像素的相对亮度分量信息之前,比较所述多个预设方向上的梯度值和所述梯度阈值,并在所述多个预设方向中,将所述梯度值小于所述梯度阈值的方向确定为所述当前位置像素的目标方向。Further, the determining unit 11 is further configured to compare the gradient values in the plurality of preset directions with the gradient value after determining the gradient threshold of the current position pixel and before determining the relative brightness component information of the current position pixel. threshold, and among the plurality of preset directions, determine a direction whose gradient value is smaller than the gradient threshold as the target direction of the pixel at the current position.

进一步地,所述确定单元11,具体用于若所述当前位置像素为绿色G分量像素,则将所述当前位置像素的G分量值作为所述当前位置像素的相对亮度分量信息,以及具体用于若所述当前位置像素为红色R分量像素或蓝色B分量像素,则将所述计算单元计算的所述第一算术平均值确定为所述当前位置像素的相对亮度分量信息;Further, the determining unit 11 is specifically configured to use the G component value of the current position pixel as the relative brightness component information of the current position pixel if the current position pixel is a green G component pixel, and specifically use If the current position pixel is a red R component pixel or a blue B component pixel, determining the first arithmetic mean value calculated by the calculation unit as the relative brightness component information of the current position pixel;

所述计算单元12,还用于若所述当前位置像素为红色R分量像素或蓝色B分量像素,则计算所述当前位置像素的所述各个目标方向的G分量值的第一算术平均值。The calculation unit 12 is further configured to calculate the first arithmetic mean of the G component values of the respective target directions of the current position pixel if the current position pixel is a red R component pixel or a blue B component pixel .

进一步地,所述获取单元10,还用于获取以所述当前位置像素为中心的n×n的像素阵列,其中,n大于等于3。Further, the obtaining unit 10 is further configured to obtain an n×n pixel array centered on the pixel at the current position, where n is greater than or equal to 3.

进一步地,所述计算单元12,具体用于在所述获取单元10获取到的所述像素阵列中,若所述当前位置像素为G分量像素,则按照第一预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值,以及还用于在所述获取单元10获取到的所述像素阵列中,若所述当前位置为R分量像素或B分量像素,则按照第二预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值。Further, the calculation unit 12 is specifically configured to, in the pixel array acquired by the acquisition unit 10, if the pixel at the current position is a G component pixel, calculate the current position according to a first preset rule Gradient values of pixels in multiple preset directions in the pixel array, and also used in the pixel array acquired by the acquisition unit 10, if the current position is an R component pixel or a B component pixel , then calculate the gradient values of the pixel at the current position in multiple preset directions in the pixel array according to a second preset rule.

进一步地,所述获取单元10,具体用于在所述像素阵列中,获得各个目标方向上的每个位置像素的相对亮度分量信息,以及用于根据所述当前位置像素的相对亮度分量信息和所述各个目标方向上的每个位置像素的相对亮度分量信息,获得所述当前位置像素的各个目标方向上的颜色值,所述各个目标方向上的颜色值包括目标方向上的R分量、G分量和B分量的值。Further, the obtaining unit 10 is specifically configured to obtain, in the pixel array, the relative brightness component information of each position pixel in each target direction, and to obtain the relative brightness component information of the current position pixel according to the relative brightness component information and The relative brightness component information of each position pixel in each target direction obtains the color value in each target direction of the current position pixel, and the color value in each target direction includes R component, G component and the value of the B component.

进一步地,所述计算单元12,具体用于根据所述当前位置像素在所述各个目标方向上的梯度值和所述当前位置像素的各个目标方向上的颜色值,计算所述当前位置像素在所述各个目标方向上的梯度值的加权平均值,以获得所述颜色平均值,以及具体用于计算所述当前位置像素的各个目标方向上的颜色值的第二算术平均值,其中,所述第二算术平均值为所述颜色平均值。Further, the calculation unit 12 is specifically configured to calculate the current position pixel at the current position according to the gradient value of the current position pixel in the respective target direction and the color value of the current position pixel in each target direction. A weighted average of the gradient values in each target direction to obtain the color average value, and specifically used to calculate a second arithmetic average value of the color values in each target direction of the pixel at the current position, wherein the The second arithmetic mean is the color mean.

本发明的实施例提供一种去马赛克的装置,主要包括获取单元、确定单元和计算单元。去马赛克的装置通过获得当前位置像素在多个预设方向上的梯度值,确定当前位置像素的梯度阈值和相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息,在多个预设方向中确定当前位置像素的至少一个目标方向,其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向,获得当前位置像素的各个目标方向上的颜色值,并根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值,最后,根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值,并根据已知颜色分量值和缺失颜色分量值,输出当前位置像素。通过该方案,本发明同时考虑了场景亮度和色度快速变化的情况,对色度和亮度进行了协同调整,解决了现有技术在此类型场景出现异常彩点或彩条的问题,改进了像素的彩色还原效果,能够有效恢复像素的真实颜色。An embodiment of the present invention provides a demosaicing device, which mainly includes an acquisition unit, a determination unit, and a calculation unit. The device for demosaicing determines the gradient threshold and relative brightness component information of the current position pixel by obtaining the gradient values of the current position pixel in multiple preset directions, and then, according to the relative brightness component information of the current position pixel, in multiple preset directions Determine at least one target direction of the current position pixel in the direction, wherein the target direction is a direction in which the gradient value of the current position pixel in multiple preset directions is less than the gradient threshold value, and obtain the color value in each target direction of the current position pixel, and According to the color value of each target direction of the pixel at the current position, the color average value is calculated, and finally, according to the known color component value and the color average value of the pixel at the current position, the missing color component value of the pixel at the current position is obtained, and according to the known color Component value and missing color component value, output the current position pixel. Through this solution, the present invention simultaneously considers the situation of rapid changes in scene brightness and chroma, coordinates adjustments to chroma and brightness, solves the problem of abnormal color dots or color bars in this type of scene in the prior art, and improves The color restoration effect of pixels can effectively restore the true colors of pixels.

实施例四Embodiment four

本发明提供一种去马赛克的装置,如图8所示,包括:The present invention provides a demosaic device, as shown in Figure 8, comprising:

处理器20,用于获得当前位置像素在多个预设方向上的梯度值,并根据所述多个预设方向上的梯度值确定当前位置像素的梯度阈值,以及用于确定所述当前位置像素的相对亮度分量信息,以及用于根据所述当前位置像素的相对亮度分量信息,获得所述当前位置像素的各个目标方向上的颜色值,其中,所述目标方向为所述当前位置像素在所述多个预设方向中的梯度值小于所述梯度阈值的方向,所述当前位置像素有至少一个目标方向,以及用于根据所述当前位置像素的已知颜色分量值和所述颜色平均值,获得所述当前位置像素的缺失颜色分量值;Processor 20, configured to obtain gradient values of the pixel at the current position in multiple preset directions, determine a gradient threshold of the pixel at the current position according to the gradient values in the multiple preset directions, and determine the current position The relative brightness component information of the pixel, and used for obtaining the color value in each target direction of the pixel at the current position according to the relative brightness component information of the pixel at the current position, wherein the target direction is that the pixel at the current position is in The direction in which the gradient value of the plurality of preset directions is smaller than the gradient threshold value, the current position pixel has at least one target direction, and the known color component value of the current position pixel and the color average value, to obtain the missing color component value of the pixel at the current position;

计算器21,用于根据所述处理器20获得的所述当前位置像素的各个目标方向上的颜色值,统计颜色平均值;A calculator 21, configured to calculate the color average value according to the color values in each target direction of the pixel at the current position obtained by the processor 20;

显示器22,用于根据所述已知颜色分量值和所述处理器20获取到的所述缺失颜色分量值,输出所述当前位置像素。The display 22 is configured to output the pixel at the current position according to the known color component value and the missing color component value obtained by the processor 20 .

进一步地,所述处理器20,还用于在确定当前位置像素梯度阈值之后,确定所述当前位置像素的相对亮度分量信息之前,比较所述多个预设方向上的梯度值和所述梯度阈值,并在所述多个预设方向中,将所述梯度值小于所述梯度阈值的方向确定为所述当前位置像素的目标方向。Further, the processor 20 is further configured to compare the gradient values in the plurality of preset directions with the gradient value before determining the relative brightness component information of the current position pixel after determining the gradient threshold value of the current position pixel. threshold, and among the plurality of preset directions, determine a direction whose gradient value is smaller than the gradient threshold as the target direction of the pixel at the current position.

进一步地,所述处理器20,具体用于若所述当前位置像素为绿色G分量像素,则将所述当前位置像素的G分量值作为所述当前位置像素的相对亮度分量信息,以及具体用于若所述当前位置像素为红色R分量像素或蓝色B分量像素,则将所述计算器21计算的所述第一算术平均值确定为所述当前位置像素的相对亮度分量信息;Further, the processor 20 is specifically configured to use the G component value of the current position pixel as the relative brightness component information of the current position pixel if the current position pixel is a green G component pixel, and specifically use If the current position pixel is a red R component pixel or a blue B component pixel, determining the first arithmetic mean value calculated by the calculator 21 as the relative brightness component information of the current position pixel;

所述计算器21,还用于若所述当前位置像素为红色R分量像素或蓝色B分量像素,则计算所述当前位置像素的所述各个目标方向的G分量值的第一算术平均值。The calculator 21 is further configured to calculate the first arithmetic mean of the G component values of the respective target directions of the current position pixel if the current position pixel is a red R component pixel or a blue B component pixel .

进一步地,所述处理器20,还用于获取以所述当前位置像素为中心的n×n的像素阵列,其中,n大于等于3。Further, the processor 20 is further configured to acquire an n×n pixel array centered on the pixel at the current position, where n is greater than or equal to 3.

进一步地,所述计算器21,具体用于在所述处理器20获取到的所述像素阵列中,若所述当前位置像素为G分量像素,则按照第一预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值,以及还用于在所述处理器20获取到的所述像素阵列中,若所述当前位置为R分量像素或B分量像素,则按照第二预设规则计算所述当前位置像素在所述像素阵列中的多个预设方向上的梯度值。Further, the calculator 21 is specifically configured to, in the pixel array obtained by the processor 20, if the pixel at the current position is a G component pixel, calculate the current position according to a first preset rule Gradient values of pixels in multiple preset directions in the pixel array, and also used in the pixel array acquired by the processor 20, if the current position is an R component pixel or a B component pixel , then calculate the gradient values of the pixel at the current position in multiple preset directions in the pixel array according to a second preset rule.

进一步地,所述处理器20,具体用于在所述像素阵列中,获得各个目标方向上的每个位置像素的相对亮度分量信息,以及用于根据所述当前位置像素的相对亮度分量信息和所述各个目标方向上的每个位置像素的相对亮度分量信息,获得所述当前位置像素的各个目标方向上的颜色值,所述各个目标方向上的颜色值包括目标方向上的R分量、G分量和B分量的值。Further, the processor 20 is specifically configured to obtain, in the pixel array, the relative brightness component information of each position pixel in each target direction, and to obtain the relative brightness component information of the current position pixel according to the relative brightness component information and The relative brightness component information of each position pixel in each target direction obtains the color value in each target direction of the current position pixel, and the color value in each target direction includes R component, G component and the value of the B component.

进一步地,所述计算器21,具体用于根据所述当前位置像素在所述各个目标方向上的梯度值和所述当前位置像素的各个目标方向上的颜色值,计算所述当前位置像素在所述各个目标方向上的梯度值的加权平均值,以获得所述颜色平均值,以及具体用于计算所述当前位置像素的各个目标方向上的颜色值的第二算术平均值,其中,所述第二算术平均值为所述颜色平均值。Further, the calculator 21 is specifically configured to calculate, according to the gradient value of the current position pixel in each target direction and the color value of the current position pixel in each target direction, A weighted average of the gradient values in each target direction to obtain the color average value, and specifically used to calculate a second arithmetic average value of the color values in each target direction of the pixel at the current position, wherein the The second arithmetic mean is the color mean.

本发明的实施例提供一种去马赛克的装置,主要包括处理器、计算器和显示器。去马赛克的装置通过获得当前位置像素在多个预设方向上的梯度值,确定当前位置像素的梯度阈值和相对亮度分量信息,然后,根据当前位置像素的相对亮度分量信息,在多个预设方向中确定当前位置像素的至少一个目标方向,其中,目标方向为当前位置像素在多个预设方向中的梯度值小于梯度阈值的方向,获得当前位置像素的各个目标方向上的颜色值,其中,当前位置像素在所述目标方向上的梯度值小于所述梯度阈值,并根据当前位置像素的各个目标方向上的颜色值,统计颜色平均值,最后,根据当前位置像素的已知颜色分量值和颜色平均值,获得当前位置像素的缺失颜色分量值,并根据已知颜色分量值和缺失颜色分量值,输出当前位置像素。通过该方案,本发明同时考虑了场景亮度和色度快速变化的情况,对色度和亮度进行了协同调整,解决了现有技术在此类型场景出现异常彩点或彩条的问题,改进了像素的彩色还原效果,能够有效恢复像素的真实颜色。An embodiment of the present invention provides a demosaicing device, which mainly includes a processor, a calculator, and a display. The device for demosaicing determines the gradient threshold and relative brightness component information of the current position pixel by obtaining the gradient values of the current position pixel in multiple preset directions, and then, according to the relative brightness component information of the current position pixel, in multiple preset directions Determine at least one target direction of the current position pixel in the direction, wherein the target direction is a direction in which the gradient value of the current position pixel in multiple preset directions is smaller than the gradient threshold value, and obtain the color value of each target direction of the current position pixel, wherein , the gradient value of the current position pixel in the target direction is smaller than the gradient threshold, and according to the color values of the current position pixel in each target direction, the color average value is calculated, and finally, according to the known color component value of the current position pixel and the color average value to obtain the missing color component value of the pixel at the current position, and output the pixel at the current position according to the known color component value and the missing color component value. Through this solution, the present invention simultaneously considers the situation of rapid changes in scene brightness and chroma, coordinates adjustments to chroma and brightness, solves the problem of abnormal color dots or color bars in this type of scene in the prior art, and improves The color restoration effect of pixels can effectively restore the true colors of pixels.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional modules according to needs. The internal structure of the device is divided into different functional modules to complete all or part of the functions described above. For the specific working process of the above-described system, device, and unit, reference may be made to the corresponding process in the foregoing method embodiments, and details are not repeated here.

在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the 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. For example, multiple units or components can be Incorporation may either be integrated into another system, or some features may be omitted, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.

Claims (14)

1. A method of demosaicing, comprising:
obtaining gradient values of a current position pixel in a plurality of preset directions, and determining a gradient threshold value of the current position pixel according to the gradient values in the plurality of preset directions;
determining relative brightness component information of the current position pixel;
obtaining a color value of the current position pixel in each target direction in the preset directions according to relative brightness component information of the current position pixel, wherein the target direction is a direction in which a gradient value of the current position pixel in the preset directions is smaller than the gradient threshold value, and the current position pixel has at least one target direction;
counting a color average value according to color values of the current position pixel in all target directions;
obtaining a missing color component value of the current position pixel according to the known color component value of the current position pixel and the color average value;
outputting the current loxel based on the known color component value and the missing color component value.
2. The method for demosaicing as claimed in claim 1, wherein after obtaining gradient values of the current-position pixel in a plurality of preset directions and determining a gradient threshold of the current-position pixel according to the gradient values in the plurality of preset directions, before determining the relative luminance component information of the current-position pixel, the method further comprises:
comparing the gradient values in the plurality of preset directions with the gradient threshold value;
and determining the direction of which the gradient value is smaller than the gradient threshold value as the target direction of the current position pixel in the plurality of preset directions.
3. The demosaicing method according to claim 1 or 2, wherein the determining the relative luminance component information of the current position pixel comprises:
if the current position pixel is a green G component pixel, taking the G component value of the current position pixel as the relative brightness component information of the current position pixel;
if the current position pixel is a red R component pixel or a blue B component pixel, calculating a first arithmetic mean value of G component values of all the target directions of the current position pixel, and determining the first arithmetic mean value as the relative brightness component information of the current position pixel.
4. The demosaicing method according to claim 1, wherein before obtaining gradient values of the current-position pixel in a plurality of preset directions, the method further comprises:
and acquiring an n multiplied by n pixel array taking the current position pixel as a center, wherein n is more than or equal to 3.
5. The method for demosaicing as claimed in claim 4, wherein said obtaining gradient values of the current position pixel in a plurality of preset directions comprises:
in the pixel array, if the current position pixel is a G component pixel, calculating gradient values of the current position pixel in a plurality of preset directions in the pixel array according to a first preset rule;
in the pixel array, if the current position is an R component pixel or a B component pixel, gradient values of the current position pixel in a plurality of preset directions in the pixel array are calculated according to a second preset rule.
6. The demosaicing method according to any one of claims 1 to 5, wherein the obtaining color values of the current loxel in respective target directions includes:
in the pixel array, obtaining relative brightness component information of each position pixel in each target direction;
and obtaining a color value of the current position pixel in each target direction according to the relative brightness component information of the current position pixel and the relative brightness component information of each position pixel in each target direction, wherein the color value in each target direction comprises values of an R component, a G component and a B component in each target direction.
7. The method of demosaicing as claimed in claim 6, wherein the statistical color mean comprises:
calculating a weighted average value of the gradient values of the current position pixel in each target direction according to the gradient values of the current position pixel in each target direction and the color values of the current position pixel in each target direction to obtain the color average value;
or,
and calculating a second arithmetic mean value of the color values of the current position pixel in each target direction, wherein the second arithmetic mean value is the color mean value.
8. An apparatus for demosaicing, comprising:
an obtaining unit, configured to obtain gradient values of a current location pixel in multiple preset directions, and to obtain a color value of the current location pixel in each target direction of the multiple preset directions, where the target direction is a direction in which the gradient value of the current location pixel in the multiple preset directions is smaller than the gradient threshold, and the current location pixel has at least one target direction, and to obtain a missing color component value of the current location pixel according to a known color component value and the color average value of the current location pixel;
a determining unit, configured to determine a gradient threshold of a current position pixel according to the gradient values in the multiple preset directions acquired by the acquiring unit, and determine relative luminance component information of the current position pixel;
the calculating unit is used for counting the average color value according to the color values of the current position pixel in all target directions acquired by the acquiring unit;
an output unit, configured to output the current location pixel according to the known color component value and the missing color component value acquired by the acquisition unit.
9. The apparatus for demosaicing according to claim 8,
the determining unit is further configured to, after determining a gradient threshold of a current position pixel and before determining relative luminance component information of the current position pixel, compare gradient values in the multiple preset directions with the gradient threshold, and determine, as a target direction of the current position pixel, a direction in which the gradient value is smaller than the gradient threshold among the multiple preset directions.
10. The demosaicing apparatus according to claim 8 or 9,
the determining unit is specifically configured to use a G component value of the current location pixel as the relative luminance component information of the current location pixel if the current location pixel is a green G component pixel, and is specifically configured to determine the first arithmetic average value calculated by the calculating unit as the relative luminance component information of the current location pixel if the current location pixel is a red R component pixel or a blue B component pixel;
the calculating unit is further configured to calculate a first arithmetic average of G component values of the current position pixel in each object direction if the current position pixel is a red R component pixel or a blue B component pixel.
11. The apparatus for demosaicing according to claim 8,
the acquiring unit is further configured to acquire an n × n pixel array centered on the current position pixel, where n is greater than or equal to 3.
12. The apparatus for demosaicing according to claim 11,
the calculating unit is specifically configured to calculate, in the pixel array acquired by the acquiring unit, gradient values of the current position pixel in multiple preset directions in the pixel array according to a first preset rule if the current position pixel is a G component pixel, and also configured to calculate, in the pixel array acquired by the acquiring unit, gradient values of the current position pixel in multiple preset directions in the pixel array according to a second preset rule if the current position is an R component pixel or a B component pixel.
13. The demosaicing apparatus according to any one of claims 8 to 12,
the obtaining unit is specifically configured to obtain, in the pixel array, relative luminance component information of each location pixel in each target direction, and obtain a color value of the current location pixel in each target direction according to the relative luminance component information of the current location pixel and the relative luminance component information of each location pixel in each target direction, where the color value in each target direction includes values of an R component, a G component, and a B component in each target direction.
14. The apparatus for demosaicing according to claim 13,
the calculating unit is specifically configured to calculate a weighted average of the gradient values of the current location pixel in each target direction according to the gradient values of the current location pixel in each target direction and the color values of the current location pixel in each target direction to obtain the color average, and is specifically configured to calculate a second arithmetic average of the color values of the current location pixel in each target direction, where the second arithmetic average is the color average.
CN201410077102.3A2014-03-042014-03-04Mosaic removing method and deviceWithdrawnCN103841388A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201410077102.3ACN103841388A (en)2014-03-042014-03-04Mosaic removing method and device

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201410077102.3ACN103841388A (en)2014-03-042014-03-04Mosaic removing method and device

Publications (1)

Publication NumberPublication Date
CN103841388Atrue CN103841388A (en)2014-06-04

Family

ID=50804477

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201410077102.3AWithdrawnCN103841388A (en)2014-03-042014-03-04Mosaic removing method and device

Country Status (1)

CountryLink
CN (1)CN103841388A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN104539919A (en)*2014-12-312015-04-22上海富瀚微电子股份有限公司Demosaicing method and device of image sensor
CN106303474A (en)*2016-09-292017-01-04杭州雄迈集成电路技术有限公司A kind of demosaicing methods based on G pattern color filter array and device
CN107466410A (en)*2015-03-272017-12-12英特尔公司New edge sensing for original image processing is measured
CN107615331A (en)*2015-05-152018-01-19深圳市大疆创新科技有限公司System and method for supporting the image denoising based on neighborhood block dimensionality reduction
CN110089103A (en)*2016-12-282019-08-02华为技术有限公司 A demosaic method and device
CN113949850A (en)*2020-07-172022-01-18爱思开海力士有限公司 Demosaic operation circuit, image sensing device and operation method thereof

Cited By (13)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN104539919B (en)*2014-12-312017-01-25上海富瀚微电子股份有限公司Demosaicing method and device of image sensor
CN104539919A (en)*2014-12-312015-04-22上海富瀚微电子股份有限公司Demosaicing method and device of image sensor
CN107466410B (en)*2015-03-272021-11-05英特尔公司New edge sensing metrics for raw image processing
CN107466410A (en)*2015-03-272017-12-12英特尔公司New edge sensing for original image processing is measured
CN107615331A (en)*2015-05-152018-01-19深圳市大疆创新科技有限公司System and method for supporting the image denoising based on neighborhood block dimensionality reduction
CN107615331B (en)*2015-05-152021-03-02深圳市大疆创新科技有限公司System and method for supporting image denoising based on neighborhood block dimension reduction
CN106303474A (en)*2016-09-292017-01-04杭州雄迈集成电路技术有限公司A kind of demosaicing methods based on G pattern color filter array and device
CN110089103A (en)*2016-12-282019-08-02华为技术有限公司 A demosaic method and device
CN110089103B (en)*2016-12-282020-08-07华为技术有限公司 A method and device for demosaicing
US11017501B2 (en)2016-12-282021-05-25Huawei Technologies Co., Ltd.Demosaicing method and apparatus
CN113949850A (en)*2020-07-172022-01-18爱思开海力士有限公司 Demosaic operation circuit, image sensing device and operation method thereof
CN113949850B (en)*2020-07-172023-08-01爱思开海力士有限公司 Demosaic operation circuit, image sensing device and operation method thereof
US11750783B2 (en)2020-07-172023-09-05SK Hynix Inc.Demosaic operation circuit, image sensing device and operation method of the same

Similar Documents

PublicationPublication DateTitle
USRE49256E1 (en)High resolution thin multi-aperture imaging systems
KR100782812B1 (en) Edge adaptive color interpolation method and apparatus
JP2023025085A (en)Camera image processing method and camera
CN103841388A (en)Mosaic removing method and device
KR100992362B1 (en) Color interpolation device
US9007488B2 (en)Systems and methods for generating interpolated high-dynamic-range images
US20110141321A1 (en)Method and apparatus for transforming a lens-distorted image to a perspective image in bayer space
US20170257584A1 (en)Image processing device, image processing method, and image processing system
US10834341B2 (en)Systems and methods for simultaneous capture of two or more sets of light images
CN103905802A (en)Method and device for mosaic removal based on P-mode color filter array
CN103053163A (en)Image generation device, and image generation system, method, and program
KR20070103229A (en) Color interpolation method and device
TW201526646A (en)Image processing method and module
US20150055861A1 (en)Methods and Systems for Image Demosaicing
US8346019B2 (en)Image generation method and apparatus, program therefor, and storage medium which stores the program
CN103259960B (en)The interpolation method of data and device, image output method and device
CN118317211A (en)Demosaicing method, demosaicing device, electronic equipment and storage medium
CN103313066B (en) Interpolation method and device
CN113888439B (en) Image processing method, device, electronic device and computer readable storage medium
CN113242413B (en)Interpolation calculation method and system for anti-sawtooth RCCB filter array
WO2018234616A1 (en) IMAGE PROCESSING
KR20150094350A (en)Method and apparatus for executing demosaicking using edge information
US20130038772A1 (en)Image processing apparatus and image processing method
CN113781349A (en)Image processing method, image processing apparatus, electronic device, and storage medium
KR101566201B1 (en)Method of converting WRGB to RGB and device for executing the same

Legal Events

DateCodeTitleDescription
C06Publication
PB01Publication
C10Entry into substantive examination
SE01Entry into force of request for substantive examination
C04Withdrawal of patent application after publication (patent law 2001)
WW01Invention patent application withdrawn after publication

Application publication date:20140604


[8]ページ先頭

©2009-2025 Movatter.jp