Open3D (C++ API)  0.11.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 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 <memory>
30 #include <vector>
31 
32 #include "open3d/core/Tensor.h"
34 
35 namespace open3d {
36 namespace t {
37 namespace geometry {
38 
43 class Image : public Geometry {
44 public:
61  Image(int64_t rows = 0,
62  int64_t cols = 0,
63  int64_t channels = 1,
65  const core::Device &device = core::Device("CPU:0"));
66 
72  Image(const core::Tensor &tensor);
73 
74  virtual ~Image() override {}
75 
76 public:
79  Image &Clear() override {
80  data_ = core::Tensor({0, 0, GetChannels()}, GetDtype(), GetDevice());
81  return *this;
82  }
83 
85  bool IsEmpty() const override {
86  return GetRows() * GetCols() * GetChannels() == 0;
87  }
88 
89 public:
91  int64_t GetRows() const { return data_.GetShape()[0]; }
92 
94  int64_t GetCols() const { return data_.GetShape()[1]; }
95 
97  int64_t GetChannels() const { return data_.GetShape()[2]; }
98 
100  core::Dtype GetDtype() const { return data_.GetDtype(); }
101 
103  core::Device GetDevice() const { return data_.GetDevice(); }
104 
109  core::Tensor At(int64_t r, int64_t c) const {
110  if (GetChannels() == 1) {
111  return data_[r][c][0];
112  } else {
113  return data_[r][c];
114  }
115  }
116 
118  core::Tensor At(int64_t r, int64_t c, int64_t ch) const {
119  return data_[r][c][ch];
120  }
121 
123  void *GetDataPtr() { return data_.GetDataPtr(); }
124 
126  const void *GetDataPtr() const { return data_.GetDataPtr(); }
127 
129  core::Tensor AsTensor() const { return data_; }
130 
131 protected:
135 };
136 
137 } // namespace geometry
138 } // namespace t
139 } // namespace open3d
int64_t GetChannels() const
Get the number of channels of the image.
Definition: Image.h:97
int64_t GetRows() const
Get the number of rows of the image.
Definition: Image.h:91
core::Tensor At(int64_t r, int64_t c, int64_t ch) const
Get pixel(s) in the image. Returns a tensor with shape {}.
Definition: Image.h:118
void * GetDataPtr()
Definition: Tensor.h:939
Definition: Dtype.h:39
bool IsEmpty() const override
Returns true if rows * cols * channels == 0.
Definition: Image.h:85
void * GetDataPtr()
Get raw buffer of the Image data.
Definition: Image.h:123
virtual ~Image() override
Definition: Image.h:74
Device GetDevice() const
Definition: Tensor.cpp:944
Dtype GetDtype() const
Definition: Tensor.h:943
The Image class stores image with customizable rols, cols, channels, dtype and device.
Definition: Image.h:43
core::Tensor data_
Definition: Image.h:134
core::Device GetDevice() const
Get device of the image.
Definition: Image.h:103
Definition: Device.h:39
int64_t GetCols() const
Get the number of columns of the image.
Definition: Image.h:94
core::Tensor At(int64_t r, int64_t c) const
Definition: Image.h:109
Image(int64_t rows=0, int64_t cols=0, int64_t channels=1, core::Dtype dtype=core::Dtype::Float32, const core::Device &device=core::Device("CPU:0"))
Constructor for image.
Definition: Image.cpp:38
static const Dtype Float32
Definition: Dtype.h:42
const void * GetDataPtr() const
Get raw buffer of the Image data.
Definition: Image.h:126
SizeVector GetShape() const
Definition: Tensor.h:923
The base geometry class.
Definition: Geometry.h:36
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:48
Image & Clear() override
Definition: Image.h:79
core::Dtype GetDtype() const
Get dtype of the image.
Definition: Image.h:100
core::Tensor AsTensor() const
Retuns the underlying Tensor of the Image.
Definition: Image.h:129