IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
peak_icv_image.hpp
Go to the documentation of this file.
1
11#pragma once
12
13
19#include <memory>
20
21#ifdef WITH_peak_ipl
22# include <peak_ipl/types/peak_ipl_image.hpp>
23#endif
24
26
27struct peak_icv_image_info;
28struct peak_icv_image;
29using peak_icv_image_handle = peak_icv_image*;
30
31namespace peak
32{
33namespace icv
34{
35
36class ImageWriter;
37
45class Image : private detail::IBackendAccessible<Image>
46{
47public:
48#ifdef WITH_peak_ipl
58 Image(const peak::ipl::Image& image); // NOLINT
59#endif
60
70 explicit Image(const peak::common::IImageView& imageView);
71
99 explicit Image(const std::string& path);
100
136 explicit Image(const std::string& path, peak::common::PixelFormat name);
137
148 Image(peak::common::PixelFormat pixelFormat, uint8_t* buffer, size_t bufferSize, const peak::common::Size& imageSize);
149
158 Image(peak::common::PixelFormat pixelFormat, const peak::common::Size& imageSize);
159
165 Image(const Image& other);
166
172 Image(Image&& other) noexcept;
173
179 Image& operator=(const Image& other);
180
186 Image& operator=(Image&& other) noexcept;
187
193 ~Image() override;
194
200 bool operator==(const Image& rhs) const;
201
209 PEAK_COMMON_NO_DISCARD Image Copy() const;
210
218 PEAK_COMMON_NO_DISCARD peak::common::Size GetSize() const;
219
227 PEAK_COMMON_NO_DISCARD uint8_t* GetData() const;
228
236 PEAK_COMMON_NO_DISCARD size_t GetSizeInBytes() const;
237
248 PEAK_COMMON_NO_DISCARD size_t GetBytesPerLine() const;
249
250
258 PEAK_COMMON_NO_DISCARD peak::common::PixelFormat GetPixelFormat() const;
259
267 PEAK_COMMON_NO_DISCARD Region GetRegion() const;
268
280 void SetRegion(const Region& region) const;
281
287 void ResetRegion() const;
288
299 template <typename DataType>
300 PEAK_COMMON_NO_DISCARD DataType* At(size_t x, size_t y) const
301 {
302 return reinterpret_cast<DataType*>(m_buffer + (x + y * m_size.GetWidth()) * m_pixelFormatInfo.GetAllocatedBitsPerPixel() / 8);
303 }
304
330 PEAK_COMMON_NO_DISCARD peak::icv::Image ConvertPixelFormat(peak::common::PixelFormat pixelFormat) const;
331
346 PEAK_COMMON_NO_DISCARD peak::icv::Image ConvertPixelFormatWithFactor(
347 peak::common::PixelFormat pixelFormat, const double factor) const;
348
362 PEAK_COMMON_NO_DISCARD std::vector<Image> Deinterleave() const;
363
371 void SetMetadata(const peak::common::Metadata& metadata);
372
380 PEAK_COMMON_NO_DISCARD peak::common::Metadata GetMetadata() const;
381
395 PEAK_COMMON_NO_DISCARD Image Subtract(const Image& subtrahend) const;
396
410 PEAK_COMMON_NO_DISCARD Image operator-(const Image& subtrahend) const;
411
421 PEAK_COMMON_NO_DISCARD Image Crop(const peak::common::Rectangle& rect) const;
422
442 PEAK_COMMON_NO_DISCARD Image Scale(
443 const peak::common::Size& targetImageSize, const Interpolation& interpolation = Interpolation::NearestNeighbor) const;
444
445#ifdef WITH_peak_ipl
453 operator peak::ipl::Image() const; // NOLINT
454#endif
455
456protected:
464 PEAK_COMMON_NO_DISCARD detail::handle_of_t<Image> GetHandle() const override;
465
466private:
467 friend peak::common::detail::BackendAccessor<Image>;
468 friend ImageWriter;
469
470 explicit Image(peak_icv_image_handle imageHandle);
471 Image(peak_icv_image_handle handle, peak_icv_image_info info);
472
473 static peak::common::Metadata AddCaptureInformationDataToMetadata(
474 peak_icv_capture_information captureInformationC, peak::common::Metadata metadata);
475
476 static peak_icv_image_handle CreateFromFile(const std::string& path);
477 static peak_icv_image_handle CreateFromFile(const std::string& path, peak::common::PixelFormat name);
478 static peak_icv_image_info CreateFromHandle(peak_icv_image_handle handle);
479 static peak_icv_image_handle CreateFromSize(peak::common::PixelFormat pixelFormat, const peak::common::Size& size);
480 static peak_icv_image_handle CreateFromBuffer(
481 peak::common::PixelFormat pixelFormat, const peak::common::Size& size, const uint8_t* buffer, size_t bufferSize);
482 static peak_icv_image_handle CreateFromImageView(const peak::common::IImageView& imageView);
483
484#ifdef WITH_peak_ipl
485 PEAK_COMMON_NO_DISCARD peak::ipl::Image GetIPLImage() const;
486#endif
487
488 peak_icv_image_handle m_imageHandle{};
489 peak::common::Size m_size;
490 uint8_t* m_buffer;
491 peak::common::PixelFormatInfo m_pixelFormatInfo;
492 mutable std::unique_ptr<peak::common::Metadata> m_metaData; // mutable because we cache it in getter function
493
494#ifdef WITH_peak_ipl
495 mutable peak::ipl::Image m_image;
496#endif
497};
498} /* namespace icv */
499} /* namespace peak */
500
Interface for viewing image pixel data from arbitrary sources.
Type-safe container for image acquisition metadata.
Provides information and utility functions for pixel formats.
size_t GetAllocatedBitsPerPixel() const
Returns the number of allocated bits per pixel.
A generic rectangle defined by a point and a size.
Represents a two-dimensional size with non-negative width and height.
constexpr T GetWidth() const
Returns the width.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
peak::common::Size GetSize() const
Provides the size of the image in pixels.
void ResetRegion() const
Resets the region on the image to the complete image.
Image operator-(const Image &subtrahend) const
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Image & operator=(const Image &other)
uint8_t * GetData() const
Provides a pointer to the image data buffer.
Image Subtract(const Image &subtrahend) const
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Region GetRegion() const
Provides the region of the image.
Image(const peak::common::IImageView &imageView)
Constructs an Image from an IImageView Instance.
peak::common::PixelFormat GetPixelFormat() const
Provides the pixel format of the image.
Image Crop(const peak::common::Rectangle &rect) const
Crops the image to the given rectangle.
peak::common::Metadata GetMetadata() const
Returns the Metadata of an image which contains information about the image capture information.
peak::icv::Image ConvertPixelFormat(peak::common::PixelFormat pixelFormat) const
Converts the image to a different pixel format.
void SetMetadata(const peak::common::Metadata &metadata)
Updates the Metadata of an image which is used to store and manage capture information.
Image Copy() const
Creates a deep copy of the current Image.
peak::icv::Image ConvertPixelFormatWithFactor(peak::common::PixelFormat pixelFormat, const double factor) const
Converts an image into another pixel format with a factor multiplied to every pixel.
Image Scale(const peak::common::Size &targetImageSize, const Interpolation &interpolation=Interpolation::NearestNeighbor) const
Returns an image scaled to the given image size.
size_t GetSizeInBytes() const
Provides the size of the image data in bytes.
std::vector< Image > Deinterleave() const
Splits an image with an interleaved pixel format into individual images.
bool operator==(const Image &rhs) const
DataType * At(size_t x, size_t y) const
Provides a pointer to the data at the specified coordinates.
size_t GetBytesPerLine() const
Computes the number of bytes required to store one line of pixel data (no padding).
void SetRegion(const Region &region) const
Updates the region on the image.
Provides functionality to write images to files in various supported formats.
Represents a region defined by a set of points in the image plane.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Interpolation
Enumeration of interpolation methods used in image transformations.
peak::common::detail::c_type_of_t< Type > * handle_of_t
Enum holding the possible pixel format names.
peak_icv_image * peak_icv_image_handle