cvw::Image
Owning, type-safe image container parameterized by pixel format. More...
#include <image.hpp>
Public Types
| Name | |
|---|---|
| using typename format_type::value_type | value_type Scalar element type derived from the pixel format. |
Public Functions
| Name | |
|---|---|
| Image() =default Default-constructs an empty image. | |
| Image(int width, int height) Constructs an uninitialized image of the given dimensions. | |
| Image(int width, int height, value_type fill_value) Constructs an image filled with a uniform value. | |
| Image(cv::Mat image) Takes ownership of an existing cv::Mat. | |
| cv::Mat & | mat() Returns a mutable reference to the underlying cv::Mat. |
| const cv::Mat & | mat() const Returns a const reference to the underlying cv::Mat. |
| int | width() const Returns the image width in pixels. |
| int | height() const Returns the image height in pixels. |
| constexprint | channels() Returns the number of channels determined by the format. |
| size_t | size_bytes() const Returns the total number of bytes occupied by pixel data. |
| size_t | stride() const Returns the row stride in bytes. |
| bool | empty() const Checks whether the image contains no data. |
| value_type * | data() Returns a typed pointer to the beginning of pixel data. |
| constvalue_type * | data() const Returns a const typed pointer to the beginning of pixel data. |
| value_type & | at(int row, int col, int ch =0) Accesses a specific pixel channel by coordinates. |
| ImageView<format_type> | view() const Creates a read-only view over the image data. |
| ImageMutView<format_type> | mutable_view() const Creates a mutable view over the image data. |
| ImageView<constformat_type> | const_view() const Creates a const view over the image data. |
| template <is_pixel_format target_format> expected< Image<target_format>, ConversionalError > | convert_to() const Converts the image to a different pixel format. |
| Image(Image && ) =default Move-constructs from another Image. | |
| Image & | operator=(Image && ) =default Move-assigns from another Image. |
| Image(constImage & ) =delete Copy disabled. | |
| Image & | operator=(constImage & ) =delete Copy disabled. |
| Image | clone() const Creates a deep copy of the image. |
Detailed Description
template <is_pixel_format format_type>
class cvw::Image;Owning, type-safe image container parameterized by pixel format.
Template Parameters:
- format_type Pixel format tag satisfying is_pixel_format.
Since: 1.0.0
Note: Not thread-safe unless externally synchronized.
Manages pixel data through a cv::Mat backend. Supports move semantics only — copy is deleted to enforce single ownership. Provides zero-copy views, pixel access, and compile-time color conversion.
cvw::Image<cvw::BGR> img(640, 480);
auto gray = img.convert_to<cvw::Gray>();Public Types Documentation
using value_type
using cvw::Image<format_type>::value_type = typename format_type::value_type;Scalar element type derived from the pixel format.
Public Functions Documentation
function Image
Image() =defaultDefault-constructs an empty image.
Since: 1.0.0
The image holds no data until assigned.
function Image
Image(
int width,
int height
)Constructs an uninitialized image of the given dimensions.
Parameters:
Since: 1.0.0
function Image
Image(
int width,
int height,
value_type fill_value
)Constructs an image filled with a uniform value.
Parameters:
- width Image width in pixels. Must be positive.
- height Image height in pixels. Must be positive.
- fill_value Value to fill every channel of every pixel.
Since: 1.0.0
function Image
explicit Image(
cv::Mat image
)Takes ownership of an existing cv::Mat.
Parameters:
- image Source cv::Mat to transfer from.
Since: 1.0.0
The Mat is moved in; no pixel data is copied.
function mat
cv::Mat & mat()Returns a mutable reference to the underlying cv::Mat.
Return: Reference to the internal cv::Mat.
Since: 1.0.0
function mat
const cv::Mat & mat() constReturns a const reference to the underlying cv::Mat.
Return: Const reference to the internal cv::Mat.
Since: 1.0.0
function width
int width() constReturns the image width in pixels.
Return: Width in pixels.
Since: 1.0.0
function height
int height() constReturns the image height in pixels.
Return: Height in pixels.
Since: 1.0.0
function channels
inline constexprint channels()Returns the number of channels determined by the format.
Return: Channel count (compile-time constant).
Since: 1.0.0
function size_bytes
size_t size_bytes() constReturns the total number of bytes occupied by pixel data.
Return: Size in bytes.
Since: 1.0.0
function stride
size_t stride() constReturns the row stride in bytes.
Return: Stride in bytes.
Since: 1.0.0
function empty
bool empty() constChecks whether the image contains no data.
Return: True if the image is empty.
Since: 1.0.0
function data
value_type * data()Returns a typed pointer to the beginning of pixel data.
Return: Mutable pointer to the first pixel element.
Since: 1.0.0
function data
constvalue_type * data() constReturns a const typed pointer to the beginning of pixel data.
Return: Const pointer to the first pixel element.
Since: 1.0.0
function at
value_type & at(
int row,
int col,
int ch =0
)Accesses a specific pixel channel by coordinates.
Parameters:
- row Row index. Unit: pixels. Valid range: [0, height).
- col Column index. Unit: pixels. Valid range: [0, width).
- ch Channel index. Default: 0. Valid range: [0, channels).
Exceptions:
- None (bounds checking not performed).
Return: Mutable reference to the channel value.
Since: 1.0.0
Warning: No bounds checking; undefined behavior for out-of-range indices.
function view
ImageView<format_type> view() constCreates a read-only view over the image data.
Return: An ImageView pointing to the same pixel buffer.
Since: 1.0.0
The view does not own the data; the source Image must outlive it.
function mutable_view
ImageMutView<format_type> mutable_view() constCreates a mutable view over the image data.
Return: An ImageMutView pointing to the same pixel buffer.
Since: 1.0.0
The view does not own the data; the source Image must outlive it.
function const_view
ImageView<constformat_type> const_view() constCreates a const view over the image data.
Return: An ImageView with const-qualified format tag.
Since: 1.0.0
function convert_to
template <is_pixel_format target_format>
expected< Image<target_format>, ConversionalError > convert_to() constConverts the image to a different pixel format.
Exceptions:
- None.
Template Parameters:
- target_format Desired output pixel format.
Return: Expected containing the converted Image or a ConversionalError.
Since: 1.0.0
Note: Supported conversions are determined at compile time.
Performs color space conversion and/or type scaling at compile time. Returns an error if the conversion is not supported or the image is empty.
function Image
Image(
Image &&
) =defaultMove-constructs from another Image.
function operator=
Image & operator=(
Image &&
) =defaultMove-assigns from another Image.
function Image
Image(
constImage &
) =deleteCopy disabled.
function operator=
Image & operator=(
constImage &
) =deleteCopy disabled.
function clone
Image clone() constCreates a deep copy of the image.
Return: An independent Image with identical contents.
Since: 1.0.0
Allocates new storage and copies all pixel data.
Updated on 2026-05-17 at 13:22:38 +0000