IDS peak ICV v1.1.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
356 void SetMetadata(const peak::common::Metadata& metadata);
357
365 PEAK_COMMON_NO_DISCARD peak::common::Metadata GetMetadata() const;
366
380 PEAK_COMMON_NO_DISCARD Image Subtract(const Image& subtrahend) const;
381
395 PEAK_COMMON_NO_DISCARD Image operator-(const Image& subtrahend) const;
396
406 PEAK_COMMON_NO_DISCARD Image Crop(const peak::common::Rectangle& rect) const;
407
427 PEAK_COMMON_NO_DISCARD Image Scale(
428 const peak::common::Size& targetImageSize, const Interpolation& interpolation = Interpolation::NearestNeighbor) const;
429
430#ifdef WITH_peak_ipl
438 operator peak::ipl::Image() const; // NOLINT
439#endif
440
441protected:
449 PEAK_COMMON_NO_DISCARD detail::handle_of_t<Image> GetHandle() const override;
450
451private:
452 friend peak::common::detail::BackendAccessor<Image>;
453 friend ImageWriter;
454
455 explicit Image(peak_icv_image_handle imageHandle);
456 Image(peak_icv_image_handle handle, peak_icv_image_info info);
457
458 static peak::common::Metadata AddCaptureInformationDataToMetadata(
459 peak_icv_capture_information captureInformationC, peak::common::Metadata metadata);
460
461 static peak_icv_image_handle CreateFromFile(const std::string& path);
462 static peak_icv_image_handle CreateFromFile(const std::string& path, peak::common::PixelFormat name);
463 static peak_icv_image_info CreateFromHandle(peak_icv_image_handle handle);
464 static peak_icv_image_handle CreateFromSize(peak::common::PixelFormat pixelFormat, const peak::common::Size& size);
465 static peak_icv_image_handle CreateFromBuffer(
466 peak::common::PixelFormat pixelFormat, const peak::common::Size& size, const uint8_t* buffer, size_t bufferSize);
467
468#ifdef WITH_peak_ipl
469 PEAK_COMMON_NO_DISCARD peak::ipl::Image GetIPLImage() const;
470#endif
471
472 peak_icv_image_handle m_imageHandle{};
473 peak::common::Size m_size;
474 uint8_t* m_buffer;
475 peak::common::PixelFormatInfo m_pixelFormatInfo;
476 mutable std::unique_ptr<peak::common::Metadata> m_metaData; // mutable because we cache it in getter function
477
478#ifdef WITH_peak_ipl
479 peak::ipl::Image m_image;
480#endif
481};
482} /* namespace icv */
483} /* namespace peak */
484
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.
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