Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Image.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <memory>
31 #include <vector>
32 
34 #include "Open3D/Utility/Console.h"
35 
36 namespace open3d {
37 
38 namespace camera {
39 class PinholeCameraIntrinsic;
40 }
41 
42 namespace geometry {
43 
44 class Image;
45 
47 typedef std::vector<std::shared_ptr<Image>> ImagePyramid;
48 
49 class Image : public Geometry2D {
50 public:
52  Equal,
53  Weighted,
54  };
55 
56  enum class FilterType {
57  Gaussian3,
58  Gaussian5,
59  Gaussian7,
60  Sobel3Dx,
61  Sobel3Dy
62  };
63 
64 public:
66  ~Image() override {}
67 
68 public:
69  Image &Clear() override;
70  bool IsEmpty() const override;
71  Eigen::Vector2d GetMinBound() const override;
72  Eigen::Vector2d GetMaxBound() const override;
73  bool TestImageBoundary(double u, double v, double inner_margin = 0.0) const;
74 
75 public:
76  virtual bool HasData() const {
77  return width_ > 0 && height_ > 0 &&
78  data_.size() == size_t(height_ * BytesPerLine());
79  }
80 
82  int height,
83  int num_of_channels,
84  int bytes_per_channel) {
85  width_ = width;
86  height_ = height;
87  num_of_channels_ = num_of_channels;
88  bytes_per_channel_ = bytes_per_channel;
89  AllocateDataBuffer();
90  return *this;
91  }
92 
93  int BytesPerLine() const {
94  return width_ * num_of_channels_ * bytes_per_channel_;
95  }
96 
102  std::pair<bool, double> FloatValueAt(double u, double v) const;
103 
111  static std::shared_ptr<Image>
112  CreateDepthToCameraDistanceMultiplierFloatImage(
113  const camera::PinholeCameraIntrinsic &intrinsic);
114 
116  std::shared_ptr<Image> CreateFloatImage(
118  Image::ColorToIntensityConversionType::Weighted) const;
119 
121  template <typename T>
122  T *PointerAt(int u, int v) const;
123 
125  template <typename T>
126  T *PointerAt(int u, int v, int ch) const;
127 
128  std::shared_ptr<Image> ConvertDepthToFloatImage(
129  double depth_scale = 1000.0, double depth_trunc = 3.0) const;
130 
131  std::shared_ptr<Image> Flip() const;
132 
134  std::shared_ptr<Image> Filter(Image::FilterType type) const;
135 
137  std::shared_ptr<Image> Filter(const std::vector<double> &dx,
138  const std::vector<double> &dy) const;
139 
140  std::shared_ptr<Image> FilterHorizontal(
141  const std::vector<double> &kernel) const;
142 
144  std::shared_ptr<Image> Downsample() const;
145 
147  std::shared_ptr<Image> Dilate(int half_kernel_size = 1) const;
148 
151  Image &LinearTransform(double scale = 1.0, double offset = 0.0);
152 
156  Image &ClipIntensity(double min = 0.0, double max = 1.0);
157 
161  template <typename T>
162  std::shared_ptr<Image> CreateImageFromFloatImage() const;
163 
165  static ImagePyramid FilterPyramid(const ImagePyramid &input,
166  Image::FilterType type);
167 
169  ImagePyramid CreatePyramid(size_t num_of_levels,
170  bool with_gaussian_filter = true) const;
171 
173  std::shared_ptr<Image> CreateDepthBoundaryMask(
174  double depth_threshold_for_discontinuity_check = 0.1,
175  int half_dilation_kernel_size_for_discontinuity_map = 3) const;
176 
177 protected:
179  data_.resize(width_ * height_ * num_of_channels_ * bytes_per_channel_);
180  }
181 
182 public:
183  int width_ = 0;
184  int height_ = 0;
185  int num_of_channels_ = 0;
186  int bytes_per_channel_ = 0;
187  std::vector<uint8_t> data_;
188 };
189 
190 } // namespace geometry
191 } // namespace open3d
std::vector< std::shared_ptr< Image > > ImagePyramid
Typedef and functions for ImagePyramid.
Definition: Image.h:44
Definition: Geometry.h:32
int offset
Definition: FilePCD.cpp:60
Definition: PinholeCameraIntrinsic.h:42
Image & Prepare(int width, int height, int num_of_channels, int bytes_per_channel)
Definition: Image.h:81
~Image() override
Definition: Image.h:66
Definition: Geometry2D.h:36
Image()
Definition: Image.h:65
virtual bool HasData() const
Definition: Image.h:76
void AllocateDataBuffer()
Definition: Image.h:178
char type
Definition: FilePCD.cpp:56
std::vector< uint8_t > data_
Definition: Image.h:187
FilterType
Definition: Image.h:56
Definition: PinholeCameraIntrinsic.cpp:34
int BytesPerLine() const
Definition: Image.h:93
GeometryType
Definition: Geometry.h:34
int height
Definition: FilePCD.cpp:68
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:720
Definition: Image.h:49
ColorToIntensityConversionType
Definition: Image.h:51
int width
Definition: FilePCD.cpp:67