Open3D (C++ API)  0.16.0
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-2021 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
35
36namespace open3d {
37
38namespace camera {
39class PinholeCameraIntrinsic;
40}
41
42namespace geometry {
43
44class Image;
45
47typedef std::vector<std::shared_ptr<Image>> ImagePyramid;
48
53class Image : public Geometry2D {
54public:
64 Equal,
66 Weighted,
67 };
68
72 enum class FilterType {
74 Gaussian3,
76 Gaussian5,
78 Gaussian7,
80 Sobel3Dx,
82 Sobel3Dy
83 };
84
85public:
88 ~Image() override {}
89
90public:
91 Image &Clear() override;
92 bool IsEmpty() const override;
93 Eigen::Vector2d GetMinBound() const override;
94 Eigen::Vector2d GetMaxBound() const override;
95
104 bool TestImageBoundary(double u, double v, double inner_margin = 0.0) const;
105
106public:
108 virtual bool HasData() const {
109 return width_ > 0 && height_ > 0 &&
110 data_.size() == size_t(height_ * BytesPerLine());
111 }
112
115 int height,
116 int num_of_channels,
117 int bytes_per_channel) {
118 width_ = width;
119 height_ = height;
120 num_of_channels_ = num_of_channels;
121 bytes_per_channel_ = bytes_per_channel;
123 return *this;
124 }
125
127 int BytesPerLine() const {
129 }
130
136 std::pair<bool, double> FloatValueAt(double u, double v) const;
137
145 static std::shared_ptr<Image>
147 const camera::PinholeCameraIntrinsic &intrinsic);
148
150 std::shared_ptr<Image> CreateFloatImage(
153
155 template <typename T>
156 T *PointerAt(int u, int v) const;
157
159 template <typename T>
160 T *PointerAt(int u, int v, int ch) const;
161
164 template <class T>
165 T *PointerAs() const {
166 if (sizeof(T) != bytes_per_channel_) {
167 utility::LogError("sizeof(T) != byte_per_channel_: {} != {}.",
168 sizeof(T), bytes_per_channel_);
169 }
170 return (T *)(data_.data());
171 }
172
173 std::shared_ptr<Image> ConvertDepthToFloatImage(
174 double depth_scale = 1000.0, double depth_trunc = 3.0) const;
175
176 std::shared_ptr<Image> Transpose() const;
177
179 std::shared_ptr<Image> FlipHorizontal() const;
181 std::shared_ptr<Image> FlipVertical() const;
182
184 std::shared_ptr<Image> Filter(Image::FilterType type) const;
185
187 std::shared_ptr<Image> Filter(const std::vector<double> &dx,
188 const std::vector<double> &dy) const;
189
190 std::shared_ptr<Image> FilterHorizontal(
191 const std::vector<double> &kernel) const;
192
194 std::shared_ptr<Image> Downsample() const;
195
197 std::shared_ptr<Image> Dilate(int half_kernel_size = 1) const;
198
201 Image &LinearTransform(double scale = 1.0, double offset = 0.0);
202
207 Image &ClipIntensity(double min = 0.0, double max = 1.0);
208
212 template <typename T>
213 std::shared_ptr<Image> CreateImageFromFloatImage() const;
214
216 static ImagePyramid FilterPyramid(const ImagePyramid &input,
218
220 ImagePyramid CreatePyramid(size_t num_of_levels,
221 bool with_gaussian_filter = true) const;
222
224 std::shared_ptr<Image> CreateDepthBoundaryMask(
225 double depth_threshold_for_discontinuity_check = 0.1,
226 int half_dilation_kernel_size_for_discontinuity_map = 3) const;
227
228protected:
231 }
232
233public:
235 int width_ = 0;
237 int height_ = 0;
243 std::vector<uint8_t> data_;
244};
245
246} // namespace geometry
247} // namespace open3d
#define LogError(...)
Definition: Logging.h:67
Contains the pinhole camera intrinsic parameters.
Definition: PinholeCameraIntrinsic.h:51
The base geometry class for 2D geometries.
Definition: Geometry2D.h:41
The base geometry class.
Definition: Geometry.h:37
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
The Image class stores image with customizable width, height, num of channels and bytes per channel.
Definition: Image.h:53
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:62
Image & Clear() override
Clear all elements in the geometry.
Definition: Image.cpp:45
std::shared_ptr< Image > Downsample() const
Function to 2x image downsample using simple 2x2 averaging.
Definition: Image.cpp:150
std::shared_ptr< Image > FilterHorizontal(const std::vector< double > &kernel) const
Definition: Image.cpp:179
T * PointerAt(int u, int v) const
Function to access the raw data of a single-channel Image.
Definition: Image.cpp:88
virtual bool HasData() const
Returns true if the Image has valid data.
Definition: Image.h:108
std::shared_ptr< Image > FlipHorizontal() const
Function to flip image horizontally (from left to right).
Definition: Image.cpp:313
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: Image.cpp:54
int bytes_per_channel_
Number of bytes per channel.
Definition: Image.h:241
std::shared_ptr< Image > FlipVertical() const
Function to flip image vertically (upside down).
Definition: Image.cpp:298
ImagePyramid CreatePyramid(size_t num_of_levels, bool with_gaussian_filter=true) const
Function to create image pyramid.
Definition: ImageFactory.cpp:144
Eigen::Vector2d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: Image.cpp:58
std::shared_ptr< Image > Transpose() const
Definition: Image.cpp:269
FilterType
Specifies the Image filter type.
Definition: Image.h:72
std::vector< uint8_t > data_
Image storage buffer.
Definition: Image.h:243
std::shared_ptr< Image > CreateImageFromFloatImage() const
Definition: ImageFactory.cpp:123
void AllocateDataBuffer()
Definition: Image.h:229
std::shared_ptr< Image > Filter(Image::FilterType type) const
Function to filter image with pre-defined filtering type.
Definition: Image.cpp:216
ColorToIntensityConversionType
Specifies whether R, G, B channels have the same weight when converting to intensity....
Definition: Image.h:62
@ Weighted
Weighted R, G, B channels: I = 0.299 * R + 0.587 * G + 0.114 * B.
std::shared_ptr< Image > ConvertDepthToFloatImage(double depth_scale=1000.0, double depth_trunc=3.0) const
Definition: Image.cpp:108
std::shared_ptr< Image > CreateFloatImage(Image::ColorToIntensityConversionType type=Image::ColorToIntensityConversionType::Weighted) const
Return a gray scaled float type image.
Definition: ImageFactory.cpp:63
int width_
Width of the image.
Definition: Image.h:235
~Image() override
Definition: Image.h:88
Image & LinearTransform(double scale=1.0, double offset=0.0)
Definition: Image.cpp:137
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:373
static std::shared_ptr< Image > CreateDepthToCameraDistanceMultiplierFloatImage(const camera::PinholeCameraIntrinsic &intrinsic)
Definition: ImageFactory.cpp:33
Image & ClipIntensity(double min=0.0, double max=1.0)
Definition: Image.cpp:123
int num_of_channels_
Number of channels in the image.
Definition: Image.h:239
std::pair< bool, double > FloatValueAt(double u, double v) const
Definition: Image.cpp:69
std::shared_ptr< Image > Dilate(int half_kernel_size=1) const
Function to dilate 8bit mask map.
Definition: Image.cpp:339
int height_
Height of the image.
Definition: Image.h:237
Image()
Default Constructor.
Definition: Image.h:87
int BytesPerLine() const
Returns data size per line (row, or the width) in bytes.
Definition: Image.h:127
Image & Prepare(int width, int height, int num_of_channels, int bytes_per_channel)
Prepare Image properties and allocate Image buffer.
Definition: Image.h:114
T * PointerAs() const
Definition: Image.h:165
static ImagePyramid FilterPyramid(const ImagePyramid &input, Image::FilterType type)
Function to filter image pyramid.
Definition: Image.cpp:245
Eigen::Vector2d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: Image.cpp:56
int width
Definition: FilePCD.cpp:71
int height
Definition: FilePCD.cpp:72
int offset
Definition: FilePCD.cpp:64
char type
Definition: FilePCD.cpp:60
std::vector< std::shared_ptr< Image > > ImagePyramid
Typedef and functions for ImagePyramid.
Definition: Image.h:47
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:738
Definition: PinholeCameraIntrinsic.cpp:35