ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
RGBDImageFactory.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <Logging.h>
9 
10 #include "RGBDImage.h"
11 
12 namespace cloudViewer {
13 namespace geometry {
14 using namespace cloudViewer;
15 
16 std::shared_ptr<RGBDImage> RGBDImage::CreateFromColorAndDepth(
17  const Image &color,
18  const Image &depth,
19  double depth_scale /* = 1000.0*/,
20  double depth_trunc /* = 3.0*/,
21  bool convert_rgb_to_intensity /* = true*/) {
22  std::shared_ptr<RGBDImage> rgbd_image = std::make_shared<RGBDImage>();
23  if (color.height_ != depth.height_ || color.width_ != depth.width_) {
25  "[CreateFromColorAndDepth] Unsupported image "
26  "format.");
27  }
28  rgbd_image->depth_ =
29  *depth.ConvertDepthToFloatImage(depth_scale, depth_trunc);
30  rgbd_image->color_ =
31  convert_rgb_to_intensity ? *color.CreateFloatImage() : color;
32  return rgbd_image;
33 }
34 
37 std::shared_ptr<RGBDImage> RGBDImage::CreateFromRedwoodFormat(
38  const Image &color,
39  const Image &depth,
40  bool convert_rgb_to_intensity /* = true*/) {
41  return CreateFromColorAndDepth(color, depth, 1000.0, 4.0,
42  convert_rgb_to_intensity);
43 }
44 
47 std::shared_ptr<RGBDImage> RGBDImage::CreateFromTUMFormat(
48  const Image &color,
49  const Image &depth,
50  bool convert_rgb_to_intensity /* = true*/) {
51  return CreateFromColorAndDepth(color, depth, 5000.0, 4.0,
52  convert_rgb_to_intensity);
53 }
54 
57 std::shared_ptr<RGBDImage> RGBDImage::CreateFromSUNFormat(
58  const Image &color,
59  const Image &depth,
60  bool convert_rgb_to_intensity /* = true*/) {
61  std::shared_ptr<RGBDImage> rgbd_image = std::make_shared<RGBDImage>();
62  if (color.height_ != depth.height_ || color.width_ != depth.width_) {
64  "[CreateRGBDImageFromSUNFormat] Unsupported image format.");
65  }
66  for (int v = 0; v < depth.height_; v++) {
67  for (int u = 0; u < depth.width_; u++) {
68  uint16_t &d = *depth.PointerAt<uint16_t>(u, v);
69  d = (d >> 3) | (d << 13);
70  }
71  }
72  // SUN depth map has long range depth. We set depth_trunc as 7.0
73  return CreateFromColorAndDepth(color, depth, 1000.0, 7.0,
74  convert_rgb_to_intensity);
75 }
76 
78 std::shared_ptr<RGBDImage> RGBDImage::CreateFromNYUFormat(
79  const Image &color,
80  const Image &depth,
81  bool convert_rgb_to_intensity /* = true*/) {
82  std::shared_ptr<RGBDImage> rgbd_image = std::make_shared<RGBDImage>();
83  if (color.height_ != depth.height_ || color.width_ != depth.width_) {
85  "[CreateRGBDImageFromNYUFormat] Unsupported image format.");
86  }
87  for (int v = 0; v < depth.height_; v++) {
88  for (int u = 0; u < depth.width_; u++) {
89  uint16_t *d = depth.PointerAt<uint16_t>(u, v);
90  uint8_t *p = (uint8_t *)d;
91  uint8_t x = *p;
92  *p = *(p + 1);
93  *(p + 1) = x;
94  double xx = 351.3 / (1092.5 - *d);
95  if (xx <= 0.0) {
96  *d = 0;
97  } else {
98  *d = (uint16_t)(floor(xx * 1000 + 0.5));
99  }
100  }
101  }
102  // NYU depth map has long range depth. We set depth_trunc as 7.0
103  return CreateFromColorAndDepth(color, depth, 1000.0, 7.0,
104  convert_rgb_to_intensity);
105 }
106 
107 } // namespace geometry
108 } // namespace cloudViewer
math::float4 color
The Image class stores image with customizable width, height, num of channels and bytes per channel.
Definition: Image.h:33
int height_
Height of the image.
Definition: Image.h:221
std::shared_ptr< Image > ConvertDepthToFloatImage(double depth_scale=1000.0, double depth_trunc=3.0) const
Definition: Image.cpp:97
int width_
Width of the image.
Definition: Image.h:219
T * PointerAt(int u, int v) const
Function to access the raw data of a single-channel Image.
Definition: Image.cpp:77
static std::shared_ptr< RGBDImage > CreateFromTUMFormat(const Image &color, const Image &depth, bool convert_rgb_to_intensity=true)
Factory function to create an RGBD Image from TUM dataset.
static std::shared_ptr< RGBDImage > CreateFromRedwoodFormat(const Image &color, const Image &depth, bool convert_rgb_to_intensity=true)
Factory function to create an RGBD Image from Redwood dataset.
static std::shared_ptr< RGBDImage > CreateFromSUNFormat(const Image &color, const Image &depth, bool convert_rgb_to_intensity=true)
Factory function to create an RGBD Image from SUN3D dataset.
static std::shared_ptr< RGBDImage > CreateFromNYUFormat(const Image &color, const Image &depth, bool convert_rgb_to_intensity=true)
Factory function to create an RGBD Image from NYU dataset.
static std::shared_ptr< RGBDImage > CreateFromColorAndDepth(const Image &color, const Image &depth, double depth_scale=1000.0, double depth_trunc=3.0, bool convert_rgb_to_intensity=true)
Factory function to create an RGBD Image from color and depth Images.
#define LogError(...)
Definition: Logging.h:60
normal_z x
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:75
Generic file read and write utility for python interface.