The present application relates to the technical field of 3D image displaying, and in particular to a 3D image generating method, a 3D image generating device and a computer device.
A RGBD image includes two images, one is an ordinary RGB three-channel color image, and the other is a depth image. The RGB image includes color information of graphics and the depth image includes depth information. The three-channel RGB color image can be rendered from different angles to generate new color images, and then the new color images generated from different angles are taken as the model texture to generate a three-dimensional model.
In the existing 3D image generating method, when being rendered from a certain angle, there will be some holes in the new color image. Therefore, it is necessary to provide a 3D image generating method that can fill the holes.
In order to solve the problem in the related art that the color image generated by rendering has holes, the present application provides a 3D image generating method, a 3D image generating device and a computer device that can fill the holes, so that the holes in the color image generated by rendering are filled, and a 3D image is generated based on the color image without holes.
A first aspect of the present application provides a 3D image generating method, including:
A second aspect of the present application provides a computer device, including:
A third aspect of the present application provides a non-transitory storage medium storing program codes, when the program codes are invoked by a processor, a 3D image generating method comprising operations are realized:
Compared with the related art, the 3D image generating method provided by the present application separates a target 2D image to obtain an initial color image and an initial depth image, performs an associative processing on the initial color image and the initial depth image to obtain a first color image and a target depth image, determines a target pixel, which is a hole in the first color image according to a reference pixel in the target depth image, determines a hole filling value of the target pixel according to the reference pixel, completes the filling of holes in the first color image to obtain a target color image without holes, and interleaves the initial color image and the target color image to generate a target 3D image without holes.
The technical solutions in the embodiments of the present application will be clearly and completely described below. Obviously, the described embodiments are only some, and not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the claim of the present application.
The present application provides a 3D image generating method. The 3D image generating method provided by the present application is described below from the perspective of a 3D image generating device. The 3D image generating device can be a terminal device, such as a mobile phone, a tablet or the like, or another device such as a server or the like.
Referring to
In operation S01, a target 2D image is separated to obtain an initial color image and an initial depth image.
In this embodiment, the 3D image generating device separates a target 2D image, from which a target 3D image is to be generated, to obtain an initial color image and an initial depth image. The target 2D image is an RGBD image including two images. One of the two images is an ordinary RGB three-channel color image including color information of graphics, and the other is a depth image including depth information. The initial color image is an RGB three-channel color image including multiple pixels. Each pixel is represented by a coordinate value (x, y) and has a pixel value which represents RGB color information. The initial depth image is a depth image and includes a plurality of pixels. The pixels of the initial depth image have coordinate values corresponding to a target depth image. Each pixel of the initial depth image has a depth value representing depth information.
In operation S02, the initial color image and the initial depth image are performed with an associative processing to obtain a first color image and a target depth image, and the target depth image includes a plurality of reference pixels.
In this embodiment, the 3D image generating device performs associative processing on the initial color image and the initial depth image to obtain a first color image and a target depth image. The target depth image includes multiple reference pixels, and each reference pixel can be any pixel in the target depth image. Two methods of associative processing are detailed below.
The first method of associative processing will be described below with reference to
In operation S021, an initial point cloud corresponding to the first depth image is determined.
In this embodiment, after the initial depth image is obtained, the initial depth image is remapped to be a first depth image according to a formula:
After the first depth image is obtained, the first depth image is converted into an initial point cloud according to a formula:
In operation S022, coordinate values of each point in the initial point cloud is adjusted according to a preset relative displacement to obtain a target point cloud.
In this embodiment, the preset relative displacement is explained with reference to
Further, the preset relative displacement is added to the initial point cloud to obtain the target point cloud. In this embodiment, the target point cloud is determined according to a formula:
In operation S023, coordinate values of each point of the target point cloud are processed to obtain a reference image.
In this embodiment, the reference image is a depth image that matches a size of the initial depth image, and is initially assigned with a depth value A. Each point of the target point cloud is calculated by the 3D image generating device according to the following formulas to obtain the reference image:
The reference image is a depth image with the same size as the first depth image. A width of the reference image is same to the width of the first depth image, and a height of the reference image is same to the height of the first depth image. The initial depth value of the reference image is A. The initial depth value A can be 100000.0, 90000.0, or 110000.0 which is not specifically limited as long as the initial depth value A is greater than the depth value of the first depth image and less than the maximum floating-point value.
It should be noted that after the reference image is determined, the depth value of each pixel in the reference image can be optimized according to the following operations, such that the target 3D image, which is finally generated, is optimized.
The optimization of the pixels of the reference image will be described in detail below with reference to
The first reference pixel is determined, and the first reference pixel is a pixel of the reference image whose depth value is to be optimized. If a depth value of the first reference pixel is greater than depth values of the four pairs of adjacent pixels, the depth value of the first reference pixel is changed to be equal to an average of the depth values of the four pairs of adjacent pixels.
It can be understood that the first reference pixel can be any pixel in the reference image, and the optimization process is described by taking coordinate values of the first reference as (x, y). The coordinate values of the four pairs of adjacent pixels are a pair of adjacent pixels including an upper pixel and a lower pixel, a pair of adjacent pixels including a left pixel and a right pixel of the first reference pixel, and two pairs of diagonal pixels including a left-lower pixel, a right-upper pixel, a right-lower pixel and a left-upper pixel (as shown in
The optimization method of the first reference pixel will be described below with reference to
Generally, in responding to that the depth value of the first reference pixel meets conditions of Z(x, y)>Z(x−1, y) and Z(x, y)>Z(x+1, y), that is, in a condition that the depth value of the first reference pixel is greater than depth values of the left pixel and the right pixel,
In responding to that the depth value of the first reference pixel meets conditions of Z(x, y)>Z(x, y−1) and Z(x, y)>Z(x, y+1), that is, in a condition that the depth value of the first reference pixel is greater than depth values of the lower pixel and the upper pixel,
In responding to that the depth value of the first reference pixel meets conditions of Z(x, y)>Z(x−1, y−1) and Z(x, y)>Z(x+1, y+1), that is, in a condition that the depth value of the first reference pixel is greater than depth values of a left-lower pixel and a right-upper pixel, Zsum=Zsum+Z(x−1, y−1)+Z(x+1, y+1) and Ztol=Ztol+2 are applied.
In responding to that the depth value of the first reference pixel meets conditions of Z(x, y)>Z(x+1, y−1), and Z(x, y)>Z(x−1, y+1), that is, in a condition that the depth value of the first reference pixel is greater than depth values of a right-lower pixel and a left-upper pixel, Zsum=Zsum+Z(x+1, y−1)+Z(x−1, y+1) and Ztol=Ztol+2 are applied.
Finally, an average value is calculated according to a formula:
Z(x, y) is the depth value of the first reference pixel in the reference image, Z(x+1, y) is a depth value of a pixel with coordinate values (x+1, y) in the reference image, Z(x−1, y) is a depth value of a pixel with coordinate values (x−1, y) in the reference image, Z(x, y−1) is a depth value of a pixel with coordinate values (x, y−1) in the reference image, Z(x, y+1) is a depth value of a pixel with coordinate values (x, y+1) in the reference image, Z(x+1, y+1) is a depth value of a pixel with coordinate values (x+1, y+1) in the reference image, Z(x−1, y−1) is a depth value of a pixel with coordinate values (x−1, y−1) in the reference image, Z(x−1, y+1) is a depth value of a pixel with coordinate values (x−1, y+1) in the reference image, Z(x+1, y−1) is a depth value of a pixel with coordinate values (x+1, y−1) in the reference image.
It should be noted that the optimization method of the first reference pixel described above is utilized to determine whether the depth value of the first reference pixel is greater than the depth values of its four pairs of adjacent pixels, obtain the average value of the four pairs of adjacent pixels when the depth value of the first reference pixel is greater than the depth values of the four pairs of adjacent pixels, and updates the depth value of the first reference pixel with the average value.
In operation S024, the pixels in the initial color image and the pixels in the initial depth image are processed according to the depth values of the pixels in the reference image to obtain the first color image and the target depth image.
In this embodiment, the first color image is determined according to the following formula:
In a condition that (Z(x, y)+1)>FltErr is met, ((Z(x, y)+1)>FltErr) is 1, then the pixel with coordinate values (IP.x, IP.y) in the first color image is assigned with the pixel value of the pixel with coordinate values (x, y) in the initial depth image.
In a condition that (Z(x, y)+1)>FltErr is not met, ((Z(x, y)+1)>FltErr) is 0, then the pixel value of the pixel with coordinate values (IP.x, IP.y) in the first color image is assigned with 0.
The target depth image is determined according to the following formula:
In this method, associative processing are performed on the initial color image and the initial depth image through the initial point cloud, the target point cloud and the reference image, and resulted pixel values of the pixels in the first color image are associative with the depth values of the pixels in the target depth image.
The second associative processing method is explained below. The second associative processing method includes the following operations.
Referring to
In this embodiment, the preset depth of field is a preset parallax, which is a certain number in units of pixel. The x-axis is parallel to the width of the 3D image, and the y-axis is parallel to the height of the 3D image. For example, the preset depth of field of the target 3D image on the x-axis is 10 to 100 pixel units, then nx0 is 10 pixel units and nx1 is 100 pixel units. The preset depth of field can be 0 pixel unit. For example, if the target 3D image has no parallax on the y-axis and the preset depth of field is 0 pixel unit, ny0 is 0 pixel unit and ny1 is 0 pixel unit.
In operation C2, a ratio of the preset depth of field to a depth range of the initial depth image is determined according to formulas:
In operation C3, Pos_x and Pos_y are determined according to formulas:
In operation C4, the first color image and the target depth image are determined according to formulas:
This method carries out the associative processing of the initial color image and the initial depth map through Pos_x and Pos_y, and associates an offset of the first color image relative to the initial color image with the depth value of the first depth image. When the depth value of the initial depth image is larger, an offset of the pixel with coordinate values (Pos_x, Pos_y) in the first depth image relative to the pixel with coordinate values (x, y) in the initial depth image is larger too. The pixel values of the pixels in the first color image obtained by this method are associated with the depth values of the pixels in the target depth image. The target depth image includes a plurality of reference pixels.
In operation S03, target pixels are determined according to the depth values of the reference pixels.
In this embodiment, after the first color image and the target depth image are determined, the 3D image generating device determines whether a pixel of the first color image is a hole based on a depth value of a reference pixel. Coordinate values of the pixel of the target color image is the same as coordinate values of the reference pixel. Pixels that are holes in the target color image are determined as target pixels.
The determining of a target pixel in the target color image is detailed below.
In operation S031, in a condition that Id2(x, y)≤0 is met, the pixel with coordinate values (x, y) in the first color image is determined as the target pixel which is a hole, where Id2 represents the target depth image, Id2(x, y) is a depth value of a reference pixel with coordinate values (x, y) in the target depth image. That is, in a condition that Id2(x, y)≤0 is met, the pixel value of the pixel with coordinate values (x, y) in the first color image is 0, and for the color value is zero, the pixel is a hole. That is, in operation S031, in a condition that a depth value of a reference pixel with coordinate values (x, y) is less than or equal to zero, a pixel with coordinate values (x, y) in the first color image is determined as a target pixel which is a hole.
In operation S04, a hole filling value of the target pixel is determined according to the reference pixel.
In an embodiment, after the target pixel, which is a hole, in the first color image is determined, the 3D image generating device determines the hole filling value of the target value according to the coordinate values and a pixel value of the reference pixel, and fills the hole of the first color image according to the hole filling value to generate the target color image.
How to determine the hole filling value of the target pixel is described below, which includes the following operations.
Referring to
In this embodiment, the preset paths can be set according to the actual situation. For example, the preset paths can be 16, 6, or 5, which are not specifically limited. The preset paths can be determined based on the generating of the target 3D image.
16 preset paths are taken as examples to detail the traversal method.
The preset paths are represented by Dirs, and there are 16 preset search directions for traversal, that is, Dirs=(−1, 1), (0, 1), (1, 1), (1, 0), (−1, 2), (1, 2), (2, 1), (2, −1), (−2, 3), (−1, 3), (1, 3), (2, 3), (3, 2), (3, 1), (3, −1), (3, −2). Referring to
In operation B2, the preset paths are traversed based on coordinate values of the reference pixels, and a first target pixel and a second target pixel that meet a preset condition are determined.
The operations of traversing the reference pixels will be described below with reference to
Generally, negative direction traversal is performed according to formulas:
The negative direction traversal is performed until Id2(FromX, FromY)>0 is met or one of FromX and FromY exceeds the boundary of the target depth image.
[i] in Dirs[i][0] and Dirs[i][1] represents the preset path to be traversed, and [0] means that a value of Dirs[i][0] is equal to a left one of coordinate values of the preset path. [1] means that a value of Dirs[i][1] is equal to a right one of the coordinate values of the preset path. For example, the preset path is Dirs=(−2, 3), when coordinate values (−2, 3) is used as the preset direction for the negative direction traversal (as shown in
Positive direction traversal is performed according to formulas:
The positive direction traversal is performed until Id2(ToX, ToY)>0 is met or one of ToX and ToY exceeds the boundary of the target depth image.
[i] in Dirs[i][0] and Dirs[i][1] represents the preset path to be traversed, and [0] means that the value of Dirs[i][0] is equal to a left one of coordinate values of the preset path. [1] means that a value of Dirs[i][1] is equal to a right one of the coordinate values of the preset path. For example, the preset path is Dirs=(−2, 3), when coordinate values (−2, 3) is used as the preset direction for the positive direction traversal (as shown in
Whether FromX, FromY, ToX and ToY exceed the boundary of the target depth image is determined. In a condition that one of them exceeds the boundary, a formula as follows is applied:
In a condition that FromX, FromY, ToX and ToY do not exceed the boundary of the target depth image, a formula as follows is applied:
FLOAT_MAX is the maximum floating-point value.
After all 16 preset paths are traversed, values of FromX, FromY, ToX and ToY, which result in the minimum value of FltDis, are determined, and a combination of (FromX, FromY) are taken as the coordinate values of the first target pixel of the target depth image, and a combination of (ToX, ToY) are taken as the coordinate values of the second target pixel of the target depth image.
It should be noted that the negative direction traversal and the positive direction traversal are employed to determine the values of FromX, FromY, ToX and ToY of traversing the preset paths. However, the executing of the negative direction traversal and the positive direction traversal is not limited to a fixed order. The negative direction traversal can be executed first or the positive direction traversal can be executed first which is not specifically limited here.
In operation B3, the hole filling value of the target pixel is determined according to the coordinate values of the first target pixel and the coordinate values of the second target pixel.
In this embodiment, referring to
Id2(FromX, FromY) is the depth value of the first target pixel, and Id2(ToX, ToY) is the depth value of the second target pixel.
The hole filling value is determined according to a formula:
The hole filling value is assigned to the target pixel to fill the hole in the target color image, and the target color image without holes is obtained.
In operation S05, the initial color image and the target color image are interleaved to generate the target 3D image.
In this embodiment, the 3D image generating device interleaves the initial color image and the target color image without holes to generate the target 3D image.
Compared with the related art, the 3D image generating method provided by the present application separates a target 2D image to obtain an initial color image and an initial depth image, performs an associative processing on the initial color image and the initial depth image to obtain a first color image and a target depth image, determines a target pixel, which is a hole in the first color image according to a reference pixel in the target depth image, determines a hole filling value of the target pixel according to the reference pixel, completes the filling of holes in the first color image to obtain a target color image without holes, and interleaves the initial color image and the target color image to generate a target 3D image without holes.
The present application is described above from the perspective of the 3D image generating method, and the present application is described below from the perspective of the 3D image generating device.
Referring to
In an embodiment, the second determining unit 604 is further configured to:
In an embodiment, the second determining unit 604 is further configured to:
In an embodiment, the first determining unit 603 is further configured to:
In an embodiment, the processing unit 602 is further configured to:
In an embodiment, the processing unit 602 is further configured to:
In an embodiment, the processing unit 602 is further configured to:
In an embodiment, the processing unit 602 is further configured to:
Referring to
The computer device provided by the embodiment of the present application can execute the above-mentioned embodiments of the 3D image generating method. The implementation principles and technical effects are similar to the above and will not be repeated here.
Embodiments of the present application also provide a computer-readable medium that stores computer-executable instructions. The computer-executable instructions enable a processor to execute the 3D image generating method described in the above embodiments. The implementation principles and technical effects are similar to the above and will not be described again here.
Persons of ordinary skill in the art can understand that all or part of the operations of the embodiments of the above method can be implemented by hardware related to program instructions. The aforementioned program instructions can be stored in a computer-readable storage medium. When the program instructions are executed, the operations including the embodiments of the above-mentioned method are executed. The aforementioned storage media can be a ROM, a RAM, a magnetic disk, an optical disks or another medium that can store program codes.
The above are only some of the embodiments of the present application, and are not intended to limit the scope of the present application. Any equivalent structure or equivalent process transformation made based on the description and drawings of the present application, and any direct or indirect utilization in another related technical field are all equally included in the scope of the present application.
Number | Date | Country | Kind |
---|---|---|---|
202210724367.2 | Jun 2022 | CN | national |
The present application is a continuation application of International Application No. PCT/CN2023/101651, filed on Jun. 21, 2023, which claims priority to Chinese Patent Application No. 202210724367.2, filed on Jun. 23, 2022. The disclosures of the aforementioned applications are incorporated in the present application by reference in their entirety.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2023/101651 | Jun 2023 | WO |
Child | 18987044 | US |