13 #include <unordered_map>
37 Reset(rows, cols, channels, dtype, device);
48 }
else if (tensor.
NumDims() == 3) {
85 static const std::vector<core::Dtype> ipp_supported{
112 std::count(ipp_supported.begin(), ipp_supported.end(), dtype) > 0) {
123 "Input image channels must be 3 for RGBToGray, but got {}.",
141 std::count(npp_supported.begin(), npp_supported.end(),
145 std::count(ipp_supported.begin(), ipp_supported.end(),
150 "RGBToGray with data type {} on device {} is not implemented!",
157 if (sampling_rate == 1.0f) {
162 .Resize(sampling_rate, interp_type)
182 {
static_cast<int64_t
>(
GetRows() * sampling_rate),
187 std::count(npp_supported.begin(), npp_supported.end(),
191 std::count(ipp_supported.begin(), ipp_supported.end(),
196 "Resize with data type {} on device {} is not "
224 std::count(npp_supported.begin(), npp_supported.end(),
228 std::count(ipp_supported.begin(), ipp_supported.end(),
233 "Dilate with data type {} on device {} is not implemented!",
241 float dist_sigma)
const {
242 if (kernel_size < 3) {
260 std::count(npp_supported.begin(), npp_supported.end(),
263 value_sigma, dist_sigma);
265 std::count(ipp_supported.begin(), ipp_supported.end(),
268 value_sigma, dist_sigma);
271 "FilterBilateral with data type {} on device {} is not "
293 std::count(npp_supported.begin(), npp_supported.end(),
297 std::count(ipp_supported.begin(), ipp_supported.end(),
302 "Filter with data type {} on device {} is not "
310 if (kernel_size < 3 || kernel_size % 2 == 0) {
329 std::count(npp_supported.begin(), npp_supported.end(),
333 std::count(ipp_supported.begin(), ipp_supported.end(),
338 "FilterGaussian with data type {} on device {} is not "
346 if (!(kernel_size == 3 || kernel_size == 5)) {
364 Image dst_im_dx, dst_im_dy;
377 std::count(npp_supported.begin(), npp_supported.end(),
382 std::count(ipp_supported.begin(), ipp_supported.end(),
388 "FilterSobel with data type {} on device {} is not "
403 "Invalid shape, expected a 1 channel image, but got ({}, {}, "
413 diff_threshold, invalid_fill);
420 float clip_fill)
const {
423 "Invalid shape, expected a 1 channel image, but got ({}, {}, "
430 if (scale < 0 || min_value < 0 || max_value < 0) {
432 "Expected positive scale, min_value, and max_value, but got "
434 scale, min_value, max_value);
436 if (!(std::isnan(clip_fill) || std::isinf(clip_fill) || clip_fill == 0)) {
438 "The clip_fill value {} is not recommended. Please use Inf, "
445 max_value, clip_fill);
450 float invalid_fill) {
453 "Invalid shape, expected a 1 channel image, but got ({}, {}, "
470 "Invalid shape, expected a 3 channel image, but got ({}, {}, "
485 "Invalid shape, expected a 1 channel image, but got ({}, {}, "
492 if (scale < 0 || min_value < 0 || max_value < 0 || min_value >= max_value) {
494 "Expected positive scale, min_value, and max_value, but got "
496 scale, min_value, max_value);
507 static const std::unordered_map<int, core::Dtype> kBytesToDtypeMap = {
518 if (iter == kBytesToDtypeMap.end()) {
530 image_legacy.
data_.data(), num_bytes);
547 static_cast<int>(dtype.ByteSize()));
#define CUDA_CALL(cuda_function,...)
std::shared_ptr< core::Tensor > image
filament::Texture::InternalFormat format
#define IPP_CALL(ipp_function,...)
#define AssertTensorDtype(tensor,...)
#define AssertTensorDtypes(tensor,...)
#define AssertTensorShape(tensor,...)
static void MemcpyFromHost(void *dst_ptr, const Device &dst_device, const void *host_ptr, size_t num_bytes)
Same as Memcpy, but with host (CPU:0) as default src_device.
static void MemcpyToHost(void *host_ptr, const void *src_ptr, const Device &src_device, size_t num_bytes)
Same as Memcpy, but with host (CPU:0) as default dst_device.
std::string ToString() const
bool IsContiguous() const
static Tensor EmptyLike(const Tensor &other)
Device GetDevice() const override
Tensor ReinterpretCast(const core::Dtype &dtype) const
Tensor Reshape(const SizeVector &dst_shape) const
Tensor Clone() const
Copy Tensor to the same device.
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
SizeVector GetShape() const
The Image class stores image with customizable width, height, num of channels and bytes per channel.
virtual bool IsEmpty() const override
Image & Prepare(int width, int height, int num_of_channels, int bytes_per_channel)
Prepare Image properties and allocate Image buffer.
int num_of_channels_
Number of chanels in the image.
int height_
Height of the image.
int BytesPerLine() const
Returns data size per line (row, or the width) in bytes.
int bytes_per_channel_
Number of bytes per channel.
int width_
Width of the image.
std::vector< uint8_t > data_
Image storage buffer.
GeometryType
Specifies possible geometry types.
The Image class stores image with customizable rows, cols, channels, dtype and device.
Image Dilate(int kernel_size=3) const
Return a new image after performing morphological dilation.
Image ClipTransform(float scale, float min_value, float max_value, float clip_fill=0.0f) const
Return new image after scaling and clipping image values.
InterpType
Image interpolation algorithms.
@ Nearest
Nearest neighbors interpolation.
static constexpr bool HAVE_IPP
Do we use IPP for accelerating image processing operations?
Image PyrDown() const
Return a new downsampled image with pyramid downsampling.
std::string ToString() const
Text description.
Image PyrDownDepth(float diff_threshold, float invalid_fill=0.f) const
Edge and invalid value preserving downsampling by 2 specifically for depth images.
static Image FromLegacy(const cloudViewer::geometry::Image &image_legacy, const core::Device &Device=core::Device("CPU:0"))
Create from a legacy CloudViewer Image.
Image Resize(float sampling_rate=0.5f, InterpType interp_type=InterpType::Nearest) const
Return a new image after resizing with specified interpolation type.
Image & Reset(int64_t rows=0, int64_t cols=0, int64_t channels=1, core::Dtype dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Reinitialize image with new parameters.
cloudViewer::geometry::Image ToLegacy() const
Convert to legacy Image type.
Image ColorizeDepth(float scale, float min_value, float max_value)
Colorize an input depth image (with Dtype UInt16 or Float32).
Image CreateVertexMap(const core::Tensor &intrinsics, float invalid_fill=0.0f)
Create a vertex map from a depth image using unprojection.
Image(int64_t rows=0, int64_t cols=0, int64_t channels=1, core::Dtype dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Constructor for image.
core::Device GetDevice() const override
Get device of the image.
Image FilterGaussian(int kernel_size=3, float sigma=1.0f) const
Return a new image after Gaussian filtering.
Image RGBToGray() const
Converts a 3-channel RGB image to a new 1-channel Grayscale image.
Image To(const core::Device &device, bool copy=false) const
Transfer the image to a specified device.
Image CreateNormalMap(float invalid_fill=0.0f)
Create a normal map from a vertex map.
core::Dtype GetDtype() const
Get dtype of the image.
std::pair< Image, Image > FilterSobel(int kernel_size=3) const
Return a pair of new gradient images (dx, dy) after Sobel filtering.
core::Tensor AsTensor() const
Returns the underlying Tensor of the Image.
int64_t GetChannels() const
Get the number of channels of the image.
Image FilterBilateral(int kernel_size=3, float value_sigma=20.0f, float distance_sigma=10.0f) const
Return a new image after bilateral filtering.
int64_t GetCols() const
Get the number of columns of the image.
Image Filter(const core::Tensor &kernel) const
Return a new image after filtering with the given kernel.
int64_t GetRows() const
Get the number of rows of the image.
constexpr T value_or(V &&v) const &
constexpr bool has_value() const noexcept
SizeVector Concat(const SizeVector &l_shape, const SizeVector &r_shape)
Concatenate two shapes.
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
void To(const core::Tensor &src_im, core::Tensor &dst_im, double scale, double offset)
void Dilate(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size)
void FilterBilateral(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float value_sigma, float distance_sigma)
void Filter(const core::Tensor &src_im, core::Tensor &dst_im, const core::Tensor &kernel)
void Resize(const core::Tensor &src_im, core::Tensor &dst_im, Image::InterpType interp_type)
void RGBToGray(const core::Tensor &src_im, core::Tensor &dst_im)
void FilterGaussian(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float sigma)
void FilterSobel(const core::Tensor &src_im, core::Tensor &dst_im_dx, core::Tensor &dst_im_dy, int kernel_size)
void CreateVertexMap(const core::Tensor &src, core::Tensor &dst, const core::Tensor &intrinsics, float invalid_fill)
void ClipTransform(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value, float clip_fill)
void ColorizeDepth(const core::Tensor &src, core::Tensor &dst, float scale, float min_value, float max_value)
void PyrDownDepth(const core::Tensor &src, core::Tensor &dst, float diff_threshold, float invalid_fill)
void CreateNormalMap(const core::Tensor &src, core::Tensor &dst, float invalid_fill)
void To(const core::Tensor &src, core::Tensor &dst, double scale, double offset)
void FilterSobel(const core::Tensor &src_im, core::Tensor &dst_im_dx, core::Tensor &dst_im_dy, int kernel_size)
void Resize(const cloudViewer::core::Tensor &src_im, cloudViewer::core::Tensor &dst_im, t::geometry::Image::InterpType interp_type)
void Dilate(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size)
void FilterGaussian(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float sigma)
void RGBToGray(const core::Tensor &src_im, core::Tensor &dst_im)
void Filter(const cloudViewer::core::Tensor &src_im, cloudViewer::core::Tensor &dst_im, const cloudViewer::core::Tensor &kernel)
void FilterBilateral(const core::Tensor &src_im, core::Tensor &dst_im, int kernel_size, float value_sigma, float distance_sigma)
std::vector< std::pair< core::Dtype, int64_t > > dtype_channels_pairs
Generic file read and write utility for python interface.