Open3D (C++ API)  0.18.0+252c867
Image.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <memory>
12 #include <vector>
13 
15 #include "open3d/utility/Logging.h"
16 
17 namespace open3d {
18 
19 namespace camera {
20 class PinholeCameraIntrinsic;
21 }
22 
23 namespace geometry {
24 
25 class Image;
26 
28 typedef std::vector<std::shared_ptr<Image>> ImagePyramid;
29 
34 class Image : public Geometry2D {
35 public:
45  Equal,
47  Weighted,
48  };
49 
53  enum class FilterType {
55  Gaussian3,
57  Gaussian5,
59  Gaussian7,
61  Sobel3Dx,
63  Sobel3Dy
64  };
65 
66 public:
69  ~Image() override {}
70 
71 public:
72  Image &Clear() override;
73  bool IsEmpty() const override;
74  Eigen::Vector2d GetMinBound() const override;
75  Eigen::Vector2d GetMaxBound() const override;
76 
85  bool TestImageBoundary(double u, double v, double inner_margin = 0.0) const;
86 
87 public:
89  virtual bool HasData() const {
90  return width_ > 0 && height_ > 0 &&
91  data_.size() == size_t(height_ * BytesPerLine());
92  }
93 
96  int height,
97  int num_of_channels,
98  int bytes_per_channel) {
99  width_ = width;
100  height_ = height;
101  num_of_channels_ = num_of_channels;
102  bytes_per_channel_ = bytes_per_channel;
104  return *this;
105  }
106 
108  int BytesPerLine() const {
110  }
111 
117  std::pair<bool, double> FloatValueAt(double u, double v) const;
118 
126  static std::shared_ptr<Image>
128  const camera::PinholeCameraIntrinsic &intrinsic);
129 
131  std::shared_ptr<Image> CreateFloatImage(
134 
136  template <typename T>
137  T *PointerAt(int u, int v) const;
138 
140  template <typename T>
141  T *PointerAt(int u, int v, int ch) const;
142 
145  template <class T>
146  T *PointerAs() const {
147  if (sizeof(T) != bytes_per_channel_) {
148  utility::LogError("sizeof(T) != byte_per_channel_: {} != {}.",
149  sizeof(T), bytes_per_channel_);
150  }
151  return (T *)(data_.data());
152  }
153 
154  std::shared_ptr<Image> ConvertDepthToFloatImage(
155  double depth_scale = 1000.0, double depth_trunc = 3.0) const;
156 
157  std::shared_ptr<Image> Transpose() const;
158 
160  std::shared_ptr<Image> FlipHorizontal() const;
162  std::shared_ptr<Image> FlipVertical() const;
163 
165  std::shared_ptr<Image> Filter(Image::FilterType type) const;
166 
168  std::shared_ptr<Image> Filter(const std::vector<double> &dx,
169  const std::vector<double> &dy) const;
170 
171  std::shared_ptr<Image> FilterHorizontal(
172  const std::vector<double> &kernel) const;
173 
175  std::shared_ptr<Image> Downsample() const;
176 
178  std::shared_ptr<Image> Dilate(int half_kernel_size = 1) const;
179 
182  Image &LinearTransform(double scale = 1.0, double offset = 0.0);
183 
188  Image &ClipIntensity(double min = 0.0, double max = 1.0);
189 
193  template <typename T>
194  std::shared_ptr<Image> CreateImageFromFloatImage() const;
195 
197  static ImagePyramid FilterPyramid(const ImagePyramid &input,
199 
201  ImagePyramid CreatePyramid(size_t num_of_levels,
202  bool with_gaussian_filter = true) const;
203 
205  std::shared_ptr<Image> CreateDepthBoundaryMask(
206  double depth_threshold_for_discontinuity_check = 0.1,
207  int half_dilation_kernel_size_for_discontinuity_map = 3) const;
208 
209 protected:
212  }
213 
214 public:
216  int width_ = 0;
218  int height_ = 0;
224  std::vector<uint8_t> data_;
225 };
226 
227 } // namespace geometry
228 } // namespace open3d
#define LogError(...)
Definition: Logging.h:48
Contains the pinhole camera intrinsic parameters.
Definition: PinholeCameraIntrinsic.h:32
The base geometry class for 2D geometries.
Definition: Geometry2D.h:22
The base geometry class.
Definition: Geometry.h:18
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:23
The Image class stores image with customizable width, height, num of channels and bytes per channel.
Definition: Image.h:34
bool TestImageBoundary(double u, double v, double inner_margin=0.0) const
Test if coordinate (u, v) is located in the inner_marge of the image.
Definition: Image.cpp:43
Image & Clear() override
Clear all elements in the geometry.
Definition: Image.cpp:26
std::shared_ptr< Image > Downsample() const
Function to 2x image downsample using simple 2x2 averaging.
Definition: Image.cpp:131
std::shared_ptr< Image > FilterHorizontal(const std::vector< double > &kernel) const
Definition: Image.cpp:160
T * PointerAt(int u, int v) const
Function to access the raw data of a single-channel Image.
Definition: Image.cpp:69
virtual bool HasData() const
Returns true if the Image has valid data.
Definition: Image.h:89
std::shared_ptr< Image > FlipHorizontal() const
Function to flip image horizontally (from left to right).
Definition: Image.cpp:294
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: Image.cpp:35
int bytes_per_channel_
Number of bytes per channel.
Definition: Image.h:222
std::shared_ptr< Image > FlipVertical() const
Function to flip image vertically (upside down).
Definition: Image.cpp:279
T * PointerAs() const
Definition: Image.h:146
ImagePyramid CreatePyramid(size_t num_of_levels, bool with_gaussian_filter=true) const
Function to create image pyramid.
Definition: ImageFactory.cpp:125
Eigen::Vector2d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: Image.cpp:39
std::shared_ptr< Image > Transpose() const
Definition: Image.cpp:250
FilterType
Specifies the Image filter type.
Definition: Image.h:53
@ Gaussian3
Gaussian filter of size 3 x 3.
@ Gaussian5
Gaussian filter of size 5 x 5.
@ Sobel3Dx
Sobel filter along X-axis.
@ Sobel3Dy
Sobel filter along Y-axis.
@ Gaussian7
Gaussian filter of size 7 x 7.
Image & Prepare(int width, int height, int num_of_channels, int bytes_per_channel)
Prepare Image properties and allocate Image buffer.
Definition: Image.h:95
std::vector< uint8_t > data_
Image storage buffer.
Definition: Image.h:224
std::shared_ptr< Image > CreateImageFromFloatImage() const
Definition: ImageFactory.cpp:104
void AllocateDataBuffer()
Definition: Image.h:210
std::shared_ptr< Image > Filter(Image::FilterType type) const
Function to filter image with pre-defined filtering type.
Definition: Image.cpp:197
ColorToIntensityConversionType
Specifies whether R, G, B channels have the same weight when converting to intensity....
Definition: Image.h:43
@ Weighted
Weighted R, G, B channels: I = 0.299 * R + 0.587 * G + 0.114 * B.
@ Equal
R, G, B channels have equal weights.
std::shared_ptr< Image > ConvertDepthToFloatImage(double depth_scale=1000.0, double depth_trunc=3.0) const
Definition: Image.cpp:89
std::shared_ptr< Image > CreateFloatImage(Image::ColorToIntensityConversionType type=Image::ColorToIntensityConversionType::Weighted) const
Return a gray scaled float type image.
Definition: ImageFactory.cpp:44
int width_
Width of the image.
Definition: Image.h:216
~Image() override
Definition: Image.h:69
Image & LinearTransform(double scale=1.0, double offset=0.0)
Definition: Image.cpp:118
std::shared_ptr< Image > CreateDepthBoundaryMask(double depth_threshold_for_discontinuity_check=0.1, int half_dilation_kernel_size_for_discontinuity_map=3) const
Function to create a depthmap boundary mask from depth image.
Definition: Image.cpp:354
static std::shared_ptr< Image > CreateDepthToCameraDistanceMultiplierFloatImage(const camera::PinholeCameraIntrinsic &intrinsic)
Definition: ImageFactory.cpp:14
Image & ClipIntensity(double min=0.0, double max=1.0)
Definition: Image.cpp:104
int num_of_channels_
Number of channels in the image.
Definition: Image.h:220
std::pair< bool, double > FloatValueAt(double u, double v) const
Definition: Image.cpp:50
std::shared_ptr< Image > Dilate(int half_kernel_size=1) const
Function to dilate 8bit mask map.
Definition: Image.cpp:320
int height_
Height of the image.
Definition: Image.h:218
Image()
Default Constructor.
Definition: Image.h:68
int BytesPerLine() const
Returns data size per line (row, or the width) in bytes.
Definition: Image.h:108
static ImagePyramid FilterPyramid(const ImagePyramid &input, Image::FilterType type)
Function to filter image pyramid.
Definition: Image.cpp:226
Eigen::Vector2d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: Image.cpp:37
int width
Definition: FilePCD.cpp:52
int height
Definition: FilePCD.cpp:53
int offset
Definition: FilePCD.cpp:45
char type
Definition: FilePCD.cpp:41
std::vector< std::shared_ptr< Image > > ImagePyramid
Typedef and functions for ImagePyramid.
Definition: Image.h:25
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t int32_t int32_t k4a_color_control_mode_t default_mode value const const k4a_calibration_t calibration char size_t
Definition: K4aPlugin.cpp:719
Definition: PinholeCameraIntrinsic.cpp:16