IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
image.py
Go to the documentation of this file.
1# @package image
2
3from __future__ import annotations
4
5import ctypes
6from typing import Any, cast, List
7import math
8
9import numpy as np
10from ids_peak_ipl import ids_peak_ipl
11
12from ids_peak_common.datatypes.geometry.size import Size
13from ids_peak_common.datatypes.iimageview import IImageView
14from ids_peak_common.datatypes.metadata import Metadata
15from ids_peak_common.datatypes.pixelformat import PixelFormat, Channel
16
17from ids_peak_icv import lib_loader
19 peak_common_size,
20 peak_icv_image_handle,
21 peak_icv_image_info,
22 peak_icv_capture_information,
23 peak_icv_binning_factor,
24)
26 execute_and_map_return_codes,
27 check_init_for_classes_with_classmethods_only,
28 metadata_to_capture_information,
29 metadata_from_capture_information,
30 add_metadata_from_capture_information_to_metadata, create_array, transform
31)
32from ids_peak_icv.exceptions import OutOfRangeException, NotSupportedException
33
34from typing import TYPE_CHECKING
35
36if TYPE_CHECKING:
37 from ids_peak_icv.datatypes.region import Region
38
39
40class Image:
41 """!
42 @brief
43 Image Class for working with algorithms.
44
45 @since ids_peak_icv 1.0
46 @ingroup ids_peak_icv_python_types
47 """
48
49 _data: np.ndarray
50
51 @classmethod
52 def create_from_pixel_format_and_size(cls, pixel_format: PixelFormat, size: Size) -> Image:
53 """!
54 @brief
55 Creates an instance of Image using a size.Size and a pixel format
56
57 @param size: Image size in pixels
58 @param pixel_format: Pixel format of the image
59 @return Returns an image instance.
60
61 @since ids_peak_icv 1.0
62 """
63
64 image_handle = peak_icv_image_handle()
65 image_size = peak_common_size(size.width, size.height)
66
67 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Create,
68 ctypes.pointer(image_handle),
69 ctypes.c_int(pixel_format.value),
70 image_size)
71
72 return Image(_handle=image_handle)
73
74 @classmethod
75 def create_from_ids_peak_ipl_image(cls, ids_peak_ipl_image: ids_peak_ipl.Image) -> Image:
76 """!
77 @brief
78 Creates an instance of Image using a ids_peak_ipl image.
79
80 @param ids_peak_ipl_image: ids_peak_ipl image
81 @return Created an image instance.
82
83 @since ids_peak_icv 1.0
84 """
85 numpy_data = (np.array(ids_peak_ipl_image.DataView(), dtype=np.uint8) if
86 ids_peak_ipl_image.PixelFormat().IsPacked() else ids_peak_ipl_image.get_numpy())
87 image_info = peak_icv_image_info(
88 pixel_format=ids_peak_ipl_image.PixelFormat().PixelFormatName(),
89 size=peak_common_size(ids_peak_ipl_image.Width(), ids_peak_ipl_image.Height()),
90 buffer_size=ids_peak_ipl_image.ByteCount(),
91 buffer=numpy_data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
92 )
93 image_handle = peak_icv_image_handle()
94
95 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_CreateFromImageInfo,
96 ctypes.pointer(image_handle),
97 image_info,
98 ctypes.sizeof(image_info))
99 c_capture_information = peak_icv_capture_information(binning_factor=peak_icv_binning_factor(x=1, y=1),
100 time_stamp=ids_peak_ipl_image.Timestamp())
101 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_SetCaptureInformation, image_handle,
102 c_capture_information, ctypes.sizeof(c_capture_information))
103
104 return cls(_handle=image_handle, _ids_peak_ipl_image=ids_peak_ipl_image)
105
106 @classmethod
107 def create_from_np_array(cls, pixel_format: PixelFormat, size: Size, data: np.ndarray) -> Image:
108 """!
109 @brief
110 Creates an instance of Image using a PixelFormat, size.Size and numpy image buffer.
111
112 @param pixel_format: Pixel format of the image
113 @param size: Image size in pixels
114 @param data: Numpy array holding the buffer data
115
116 @return Created an image instance.
117
118 @exception OutOfRangeException: If the input array is 2D and the expected number of channels is not 1,
119 or if it is 3D and the channel count does not match, or if it has a number of dimensions other than 2 or 3.
120
121 @since ids_peak_icv 1.0
122 """
123
124 if pixel_format.is_packed:
126 "Creating an image from a packed format is not supported")
127
128 return cls._create_from_np_array(pixel_format, size, data)
129
130 @classmethod
131 def _create_from_np_array(cls, pixel_format: PixelFormat, size: Size, data: np.ndarray) -> Image:
132
133 if data.ndim == 2:
134 if pixel_format.number_of_channels != 1:
135 raise OutOfRangeException("Number of channels has to be 1")
136 elif data.ndim == 3:
137 if data.shape[2] != pixel_format.number_of_channels:
139 "Number of channels must be {}".format(pixel_format.number_of_channels))
140 elif data.ndim == 1:
141 pass
142 else:
143 raise OutOfRangeException("Numpy array has wrong dimension")
144
145 image_handle = peak_icv_image_handle()
146 image_info = peak_icv_image_info(
147 pixel_format=pixel_format.value,
148 size=peak_common_size(size.width, size.height),
149 buffer_size=data.size * data.itemsize,
150 buffer=data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
151 )
152
153 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_CreateFromImageInfo,
154 ctypes.pointer(image_handle),
155 image_info,
156 ctypes.sizeof(image_info))
157
158 return cls(_handle=image_handle, _data=data)
159
160 @classmethod
161 def create_from_file(cls, image_path: str, forced_pixel_format: PixelFormat | None = None) -> Image:
162 """!
163 @brief
164 Creates an Image from a file path.
165
166 This method loads an image from the given file path.
167
168 If a PixelFormat is provided via ``forced_pixel_format``,
169 the method attempts to interpret the file using that format.
170 If interpretation fails, an exception is raised.
171 Explicit conversion between image formats must be handled manually by the user.
172
173 The following image formats are supported:
174
175 - Bitmap (BMP)
176 - Joint Photographic Experts Group (JPEG)
177 - Portable Network Graphics (PNG)
178 - @htmlonly Tag Image File Format (TIFF)@endhtmlonly
179 (Only if ``forced_pixel_format`` is specified)
180 - Raw Binary Format (RAW)
181
182 ### Supported image and pixel formats
183
184 #### BMP:
185 @supportedPixelformats{ImageLoad_BMP}
186 #### JPEG:
187 @supportedPixelformats{ImageLoad_JPEG}
188 #### PNG:
189 @supportedPixelformats{ImageLoad_PNG}
190 #### RAW:
191 If ``forced_pixel_format`` is ``None`` any raw image can be loaded.
192
193 If ``forced_pixel_format`` is specified, only the following formats are supported
194 and must match the format used when saving:
195 @supportedPixelformats{ImageLoad_RAW_WithPixelFormat}
196
197 See the @ref concept_type_pixel_format for a detailed description of the pixel formats.
198
199 @param image_path: File path on disk, pointing to an image.
200 @param forced_pixel_format: Pixel format the loaded image is forced to use.
201 @return The loaded Image as a new instance
202
203 @since ids_peak_icv 1.0
204 """
205
206 c_image_path = image_path.encode('utf-8')
207 c_handle = peak_icv_image_handle()
208
209 if forced_pixel_format is None:
210 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_CreateFromFile,
211 ctypes.pointer(c_handle), ctypes.c_char_p(c_image_path))
212 else:
213 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_CreateFromFileWithPixelFormat,
214 ctypes.pointer(c_handle), ctypes.c_char_p(c_image_path),
215 ctypes.c_int(forced_pixel_format.value))
216 return cls(_handle=c_handle)
217
218 @classmethod
219 def create_from_image_view(cls, image_view: IImageView) -> Image:
220 """!
221 @brief
222 Creates an instance of Image using an IImageView interface.
223
224 @param image_view: An object implementing the IImageView interface,
225 which can be constructed from a buffer provided by a camera.
226 @return A new `Image` instance created from the given image view.
227
228 @since ids_peak_icv 1.0
229 """
230
231 image = cls._create_from_np_array(image_view.pixel_format, image_view.size, image_view.to_numpy_array())
232 image.metadata = image_view.metadata
233 return image
234
235 def __init__(self, *args: Any, **kwargs: Any) -> None:
236 """!
237 @brief
238 In order to create an Image, please refer to the classmethods.
239
240 @since ids_peak_icv 1.0
241 """
242 self._handle_handle = check_init_for_classes_with_classmethods_only(self.__class__.__name__,
243 peak_icv_image_handle, *args, **kwargs)
244
245 if len(kwargs):
246 self._handle_handle = kwargs["_handle"]
247
248 image_info = peak_icv_image_info()
249 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_GetInfo,
250 self._handle_handle, ctypes.pointer(image_info), ctypes.sizeof(image_info))
251
252 self._metadata: Metadata | None = None
253
254 self._pixel_format = PixelFormat(image_info.pixel_format)
255 self._size = Size(image_info.size.width, image_info.size.height)
256
257 num_channels = self._pixel_format.number_of_channels
258 _shape = [int(self._size.height), int(self._size.width)]
259 if num_channels > 1:
260 _shape.append(num_channels)
261
262 self._ids_peak_ipl_image = kwargs["_ids_peak_ipl_image"] if "_ids_peak_ipl_image" in kwargs else None
263
264 if "_data" in kwargs:
265 self._data = kwargs["_data"]
266 self._raw_data = None
267 else:
268 packed_or_yuv = (self._pixel_format.is_packed or
269 self._pixel_format.has_channel(Channel.CHROMA_U))
270
271 # Create a numpy array from the ctypes buffer with dtype uint8
272 self._raw_data = np.ctypeslib.as_array(image_info.buffer, shape=(
274 self._pixel_format.allocated_bits_per_pixel,
275 packed_or_yuv),))
276
277 if packed_or_yuv:
278 self._data = self._raw_data.view(dtype=np.uint8)
279 else:
280 self._data = self._raw_data.view(dtype=self._pixel_format.numpy_dtype)
281 self._data = self._data.reshape(_shape)
282
283 def __del__(self) -> None:
284 """!
285 @brief
286 Destructor for Image class.
287 """
288 if hasattr(self, '_handle'):
289 lib_loader.dll().peak_icv_Image_Destroy(self._handle_handle)
290
291 def save(self, output_file_path: str) -> None:
292 """!
293 @brief
294 Saves the image to a file.
295
296 The file format is determined
297 by the specified file extension of the file name.
298
299 Supported image formats (with required file extensions):
300 - PNG (.png) – Portable Network Graphics
301 - BMP (.bmp) – Bitmap
302 - JPEG (.jpeg) – Joint Photographic Experts Group
303 - TIFF (.tiff) – \htmlonly Tag Image File Format\endhtmlonly
304 - RAW (.raw) – Raw Binary Format
305
306 Compression settings:
307 - JPEG: 75% quality
308 - PNG: 100% quality
309
310 ### Supported image and pixel formats
311
312 #### BMP:
313 @supportedPixelformats{ImageSave_BMP}
314
315 #### JPEG:
316 @supportedPixelformats{ImageSave_JPEG}
317
318 #### PNG:
319 @supportedPixelformats{ImageSave_PNG}
320
321 @note When saving *BGR* formats to PNG, they are written as *RGB*.
322
323 #### TIFF:
324 @supportedPixelformats{ImageSave_TIFF}
325
326 @note
327 When saving floating‑point images to TIFF:
328 Not all image viewers support displaying TIFF files
329 that store floating‑point pixel data.
330 The saved TIFF file is intended primarily as a data container
331 that allows this library to reliably write
332 and later re‑read the data.
333
334 #### RAW:
335 @supportedPixelformats{ImageSave_RAW}
336
337 See the @ref concept_type_pixel_format for a detailed description of the pixel formats.
338
339 @param output_file_path: The path of the file to store the image to disk.
340
341 @since ids_peak_icv 1.0
342 """
343 c_output_file_path = output_file_path.encode('utf-8')
344 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_SaveToFile, self._handle_handle,
345 ctypes.c_char_p(c_output_file_path))
346
347 @property
348 def size(self) -> Size:
349 """!
350 @brief
351 Provides the size.Size of the image.
352
353 @return Image size in pixels
354
355 @since ids_peak_icv 1.0
356 """
357 return self._size
358
359 @property
360 def width(self) -> int:
361 """!
362 @brief
363 Provides the width of the image.
364
365 @return Image width in pixels
366
367 @since ids_peak_icv 1.0
368 """
369 return int(self.size.width)
370
371 @property
372 def height(self) -> int:
373 """!
374 @brief
375 Provides the height of the image.
376
377 @return Image height in pixels
378
379 @since ids_peak_icv 1.0
380 """
381 return int(self.size.height)
382
383 def to_numpy_array(self, copy: bool = True) -> np.ndarray:
384 """!
385 @brief
386 Provides a numpy representation of the image.
387
388 Note that the image is copied by default and the caller must not take care of the original Instance being still
389 available.
390
391 @param copy: True: The image is copied, False: The image only references the internal memory.
392 @return Image data as a numpy array. Shape is [height, width] for single channel images.
393 Shape is [height, width, number of channels] for multichannel images.
394
395 @since ids_peak_icv 1.0
396 """
397
398 if copy:
399 return cast(np.ndarray, self._data.copy())
400
401 return self._data
402
403 def convert_pixel_format(self, pixel_format: PixelFormat) -> Image:
404 """!
405 @brief
406 Converts the image to a different pixel format.
407
408 If the input image has the same pixel format as the specified pixel format parameter,
409 the image will be copied.
410
411 **Restrictions**:
412 - Conversion to Bayer formats is only supported from a bayer format with the same pattern,
413 e.g. from BayerRG10p to BayerRG10 or BayerRG8.
414 - Conversion to packed formats is not supported.
415 - Conversions from RGB or BGR formats to RGBa or BGRa formats is not supported.
416 - RGBa and BGRa formats support only conversions into different bit depths of the same channel layout
417 or to Mono formats.
418 - Confidence and Coord3D formats can only be converted to other bit depths of the same format type.
419
420 @note
421 For a full list of supported conversions see \ref concept_supported_pixel_format_conversion.
422
423 @param pixel_format: The target pixel format.
424
425 @return A new Image with the target pixel format.
426
427 @since ids_peak_icv 1.0
428 """
429
430 output_image_handle = peak_icv_image_handle()
431 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Create,
432 ctypes.pointer(output_image_handle),
433 ctypes.c_int(pixel_format.value),
434 peak_common_size(self._size.width, self._size.height))
435
436 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_ConvertPixelFormat,
437 self._handle_handle, ctypes.c_int(pixel_format.value),
438 output_image_handle)
439
440 return Image(_handle=output_image_handle)
441
442 def convert_pixel_format_with_factor(self, pixel_format: PixelFormat, factor: float) -> Image:
443 """!
444 @brief
445 Converts an image into another pixel format with a factor multiplied to every pixel.
446
447 Supported conversions:
448 From PixelFormat::Coord3D_C8 or PixelFormat::Coord3D_C16 to PixelFormat::Coord3D_C32f
449
450 @param pixel_format: The target pixel format.
451 @param factor: The multiplication factor.
452 @return A new instance of Image with the target pixel format.
453
454 @since ids_peak_icv 1.1
455 """
456
457 output_image_handle = peak_icv_image_handle()
458 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Create,
459 ctypes.pointer(output_image_handle),
460 ctypes.c_int(pixel_format.value),
461 peak_common_size(self._size.width, self._size.height))
462
463 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_ConvertPixelFormatWithFactor,
464 self._handle_handle, ctypes.c_int(pixel_format.value), ctypes.c_double(factor),
465 output_image_handle)
466
467 return Image(_handle=output_image_handle)
468
469 @property
470 def region(self) -> Region:
471 """!
472 @brief
473 Retrieves the region.Region associated with the specified image_handle.
474 @return The image region.
475
476 @since ids_peak_icv 1.0
477 """
478 from ids_peak_icv.datatypes.region import Region
479
480 region = Region()
481 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_GetRegion, self._handle_handle,
482 ctypes.pointer(region._handle))
483 return region
484
485 @region.setter
486 def region(self, region: Region) -> None:
487 """!
488 @brief
489 Updates the region.Region on the image.
490
491 Sets a region of interest (ROI) for the specified image handle,
492 which defines a sub-area of the image where operations or analyses are focused.
493 Any points in the region that fall outside the bounds of the image are automatically discarded (clipped).
494
495 @param region: The region to be set.
496
497 @since ids_peak_icv 1.0
498 """
499 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_SetRegion, self._handle_handle,
500 region._handle)
501
502 def reset_region(self) -> None:
503 """!
504 @brief
505 Resets the region.Region on the image to the complete image.
506
507 @since ids_peak_icv 1.0
508 """
509 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_ResetRegion, self._handle_handle)
510
511 @property
512 def metadata(self) -> Metadata:
513 """!
514 @brief
515 Retrieves the metadata.Metadata of an image which contains information about
516 the image capture settings.
517
518 @return The metadata of the image.
519
520 @since ids_peak_icv 1.0
521 """
522
523 if self._metadata is not None:
524 return self._metadata
525
526 c_capture_information = peak_icv_capture_information()
527 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_GetCaptureInformation, self._handle_handle,
528 ctypes.pointer(c_capture_information), ctypes.sizeof(c_capture_information))
529
530 self._metadata = metadata_from_capture_information(c_capture_information)
531 return self._metadata
532
533 @metadata.setter
534 def metadata(self, metadata: Metadata) -> None:
535 """!
536 @brief
537 Updates the metadata.Metadata of an image which is used to store and
538 manage capture settings.
539
540 @param metadata: The metadata to be updated.
541
542 @since ids_peak_icv 1.0
543 """
544 c_capture_information = metadata_to_capture_information(metadata, size=self._size)
545
546 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_SetCaptureInformation, self._handle_handle,
547 c_capture_information, ctypes.sizeof(c_capture_information))
548 self._metadata = add_metadata_from_capture_information_to_metadata(metadata, c_capture_information)
549
550 def subtract(self, subtrahend: Image) -> Image:
551 """!
552 @brief
553 Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting image.
554
555 This function performs a pixelwise subtraction of the given subtrahend image from the current image.
556 The resulting image is returned as a new `Image` object.
557 The operation requires that both images have the same pixel format and dimensions.
558
559 @param subtrahend: The image to subtract from the current image.
560 @return The resulting image after pixelwise subtraction.
561
562 @since ids_peak_icv 1.0
563 """
564 difference = Image.create_from_pixel_format_and_size(self._pixel_format, self.size)
565 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Subtract, self._handle_handle,
566 subtrahend._handle, difference._handle)
567 return difference
568
569 def deinterleave(self) -> List[Image]:
570 """!
571 @brief
572 Splits an image with an interleaved pixel format into individual images.
573
574 The function separates e.g. multiple exposures or gains embedded in the combined HDR raw image
575 and provides them as independent images,
576 each with the correctly associated exposure information.
577
578 @supportedPixelformats{ImageDeinterleave}
579
580 @return A list of images, where each element represents one of the deinterleaved images.
581
582 @since ids_peak_icv 1.3
583 """
584 c_num_output_images = ctypes.c_size_t()
585 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Deinterleave_GetOutputImageCount,
586 ctypes.c_int(self.pixel_format.value),
587 ctypes.pointer(c_num_output_images))
588
589 c_pixel_format = ctypes.c_int()
590 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Deinterleave_GetOutputPixelFormat,
591 ctypes.c_int(self.pixel_format.value),
592 ctypes.pointer(c_pixel_format))
593
594 c_input_image_size = peak_common_size(self.size.width, self.size.height)
595 c_output_image_size = peak_common_size()
596 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Deinterleave_GetOutputImageSize,
597 ctypes.c_int(self.pixel_format.value), c_input_image_size,
598 ctypes.pointer(c_output_image_size))
599
600 output_images = []
601 for i in range(c_num_output_images.value):
602 output_images.append(
603 Image.create_from_pixel_format_and_size(PixelFormat(c_pixel_format.value),
604 Size(c_output_image_size.width, c_output_image_size.height)))
605 output_image_handles = create_array(ctypes.c_void_p, len(output_images))
606 transform(output_images, output_image_handles, lambda image: image._handle)
607
608 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Deinterleave,
609 self._handle_handle, ctypes.pointer(output_image_handles),
610 ctypes.c_size_t(len(output_image_handles)))
611
612 return output_images
613
614 def __sub__(self, subtrahend: Image) -> Image:
615 """!
616 @brief
617 Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting image.
618
619 This function performs a pixelwise subtraction of the given subtrahend image from the current image.
620 The resulting image is returned as a new `Image` object.
621 The operation requires that both images have the same pixel format and dimensions.
622
623 @param subtrahend: The image to subtract from the current image.
624 @return The resulting image after pixelwise subtraction.
625
626 @since ids_peak_icv 1.0
627 """
628 return self.subtract(subtrahend)
629
630 def __eq__(self, other: object) -> bool:
631 if not isinstance(other, Image):
632 return False
633 if self._handle_handle == other._handle:
634 return True
635 if self.size != other.size:
636 return False
637 if self._pixel_format != other._pixel_format:
638 return False
639 if self.regionregion != other.region:
640 return False
641
642 is_equal = ctypes.c_bool()
643 execute_and_map_return_codes(lib_loader.dll().peak_icv_Image_Compare, self._handle_handle, other._handle,
644 ctypes.pointer(is_equal))
645
646 return is_equal.value
647
648 @property
649 def pixel_format(self) -> PixelFormat:
650 return self._pixel_format
651
652
653def _get_byte_size(size: Size, bits_per_pixel: int, packed_or_yuv: bool) -> int:
654 """!
655 @brief
656 Calculate the byte size of an image buffer for a given size and pixel format.
657
658 @param size: The image dimensions (width, height) in pixels.
659 @param bits_per_pixel: The number of storage bits per pixel for the pixel format.
660 @param packed_or_yuv: If True, assumes packed or yuv format (truncate bits to full bytes).
661 If False, assumes other format (round up to nearest byte).
662 @return The byte size of the buffer.
663 """
664 total_bits = int(size.width) * int(size.height) * bits_per_pixel
665 if packed_or_yuv:
666 return math.ceil(total_bits / 8)
667 else:
668 return (total_bits + 7) // 8
669
670
671def _check_and_get_icv_image(image_var: Any) -> Any:
672 if isinstance(image_var, ids_peak_ipl.Image):
673 return Image.create_from_ids_peak_ipl_image(image_var)
674
675 return image_var
676
677
678def _check_icv_image(image_var: Any) -> Any:
679 if not isinstance(image_var, Image):
681 "Parameter images has to be a numpy array of ids_peak_icv images.")
682
683 return image_var
Image Class for working with algorithms.
Definition image.py:40
Region region(self)
Retrieves the region.Region associated with the specified image_handle.
Definition image.py:470
Image create_from_ids_peak_ipl_image(cls, ids_peak_ipl.Image ids_peak_ipl_image)
Creates an instance of Image using a ids_peak_ipl image.
Definition image.py:75
Image create_from_np_array(cls, PixelFormat pixel_format, Size size, np.ndarray data)
Creates an instance of Image using a PixelFormat, size.Size and numpy image buffer.
Definition image.py:107
None region(self, Region region)
Updates the region.Region on the image.
Definition image.py:486
Image __sub__(self, Image subtrahend)
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Definition image.py:614
None __init__(self, *Any args, **Any kwargs)
In order to create an Image, please refer to the classmethods.
Definition image.py:235
None save(self, str output_file_path)
Saves the image to a file.
Definition image.py:291
Image create_from_pixel_format_and_size(cls, PixelFormat pixel_format, Size size)
Creates an instance of Image using a size.Size and a pixel format.
Definition image.py:52
bool __eq__(self, object other)
Definition image.py:630
None reset_region(self)
Resets the region.Region on the image to the complete image.
Definition image.py:502
Image convert_pixel_format_with_factor(self, PixelFormat pixel_format, float factor)
Converts an image into another pixel format with a factor multiplied to every pixel.
Definition image.py:442
PixelFormat pixel_format(self)
Definition image.py:649
None __del__(self)
Destructor for Image class.
Definition image.py:283
List[Image] deinterleave(self)
Splits an image with an interleaved pixel format into individual images.
Definition image.py:569
Metadata metadata(self)
Retrieves the metadata.Metadata of an image which contains information about the image capture settin...
Definition image.py:512
int height(self)
Provides the height of the image.
Definition image.py:372
Image _create_from_np_array(cls, PixelFormat pixel_format, Size size, np.ndarray data)
Definition image.py:131
Image convert_pixel_format(self, PixelFormat pixel_format)
Converts the image to a different pixel format.
Definition image.py:403
Size size(self)
Provides the size.Size of the image.
Definition image.py:348
Image subtract(self, Image subtrahend)
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Definition image.py:550
Image create_from_file(cls, str image_path, PixelFormat|None forced_pixel_format=None)
Creates an Image from a file path.
Definition image.py:161
Image create_from_image_view(cls, IImageView image_view)
Creates an instance of Image using an IImageView interface.
Definition image.py:219
np.ndarray to_numpy_array(self, bool copy=True)
Provides a numpy representation of the image.
Definition image.py:383
int width(self)
Provides the width of the image.
Definition image.py:360
Represents a region consisting of a set of points in the image plane.
Definition region.py:29
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Definition exceptions.py:60
Occurs when a provided value falls outside the allowed valid range.
Definition exceptions.py:87
int _get_byte_size(Size size, int bits_per_pixel, bool packed_or_yuv)
Calculate the byte size of an image buffer for a given size and pixel format.
Definition image.py:653
Any _check_and_get_icv_image(Any image_var)
Definition image.py:671
Any _check_icv_image(Any image_var)
Definition image.py:678