IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
pixelformat.py
Go to the documentation of this file.
1from __future__ import annotations
2
3from enum import Enum
4from typing import Tuple, Union, NamedTuple, cast
5
6from ids_peak_common._internal.constants import FLOAT32_MAX, FLOAT32_MIN
8from ids_peak_common.exceptions import NotSupportedException
9
10
11class Channel(Enum):
12 """!
13 @brief
14 Channels
15
16 @ingroup ids_peak_common_python_types
17 """
18
19 INTENSITY = 0,
20 """!
21 @brief
22 Luminance or grayscale intensity channel. Common in single-channel images.
23 """
24
25 RED = 1,
26 """!
27 @brief
28 Red color channel. May appear in various layouts (e.g., RGB, ARGB).
29 """
30
31 GREEN = 2,
32 """!
33 @brief
34 Green color channel. Commonly part of multichannel color formats.
35 """
36
37 BLUE = 3,
38 """!
39 @brief
40 Blue color channel. Present in formats like BGR, RGBA, etc.
41 """
42
43 ALPHA = 4,
44 """!
45 @brief
46 Alpha (opacity or transparency) channel. Often used for blending and masking.
47 """
48
49 X = 5,
50 """!
51 @brief
52 Represents the X coordinate channel (e.g., in point clouds).
53 """
54
55 Y = 6,
56 """!
57 @brief
58 Represents the Y coordinate channel (e.g., in point clouds).
59 """
60
61 Z = 7,
62 """!
63 @brief
64 Represents the Z coordinate channel (e.g., in point clouds).
65 """
66
67 BAYER = 8,
68 """!
69 @brief
70 Raw Bayer pattern data from image sensors (e.g., BGGR, RGGB).
71 """
72
73 CHROMA_U = 9,
74 """!
75 @brief
76 Chrominance U channel (Cb). Represents the blue-difference chroma component in YUV/YCbCr color spaces.
77 """
78
79 CHROMA_V = 10
80 """!
81 @brief
82 Chrominance V channel (Cr). Represents the red-difference chroma component in YUV/YCbCr color spaces.
83 """
84
85
86class _PixelFormatMetadata(NamedTuple):
87 string_value: str
88 channels: tuple[Channel, ...]
89 storage_bits_per_channel: int
90 allocated_bits_per_pixel: int
91 numpy_dtype: str
92 is_packed: bool
93 unpacked_format: PixelFormat
94
95
96class PixelFormat(Enum):
97 """!
98 @brief
99 Enum listing all supported pixel formats and their internal IDs.
100
101 Each enumerator represents a specific pixel layout and bit depth,
102 used for interpreting raw image data correctly.
103
104 This class also offers methods to query characteristics of specific
105 pixel formats, such as value ranges, storage sizes, and channel configurations.
106
107 @ingroup ids_peak_common_python_types
108 """
109
110 BAYER_GR_8 = 0x01080008
111 BAYER_GR_10 = 0x0110000C
112 BAYER_GR_12 = 0x01100010
113
114 BAYER_RG_8 = 0x01080009
115 BAYER_RG_10 = 0x0110000D
116 BAYER_RG_12 = 0x01100011
117
118 BAYER_GB_8 = 0x0108000A
119 BAYER_GB_10 = 0x0110000E
120 BAYER_GB_12 = 0x01100012
121
122 BAYER_BG_8 = 0x0108000B
123 BAYER_BG_10 = 0x0110000F
124 BAYER_BG_12 = 0x01100013
125
126 MONO_8 = 0x01080001
127 MONO_10 = 0x01100003
128 MONO_12 = 0x01100005
129 MONO_16 = 0x01100007
130
131 CONFIDENCE_8 = 0x010800C6
132 CONFIDENCE_16 = 0x011000C7
133
134 COORD3D_C8 = 0x010800B1
135 COORD3D_C16 = 0x011000B8
136 COORD3D_C32F = 0x012000BF
137
138 COORD3D_ABC32F = 0x026000C0
139
140 YUV420_8_YY_UV_SEMIPLANAR_IDS = 0x420C0001
141 YUV420_8_YY_VU_SEMIPLANAR_IDS = 0x420C0002
142
143 YUV422_8_UYVY = 0x0210001F
144
145 RGB_8 = 0x02180014
146 RGB_10 = 0x02300018
147 RGB_12 = 0x0230001A
148
149 BGR_8 = 0x02180015
150 BGR_10 = 0x02300019
151 BGR_12 = 0x0230001B
152
153 RGBA_8 = 0x02200016
154 RGBA_10 = 0x0240005F
155 RGBA_12 = 0x02400061
156
157 BGRA_8 = 0x02200017
158 BGRA_10 = 0x0240004C
159 BGRA_12 = 0x0240004E
160
161 BAYER_BG_10_PACKED = 0x010A0052
162 BAYER_BG_12_PACKED = 0x010C0053
163
164 BAYER_GB_10_PACKED = 0x010A0054
165 BAYER_GB_12_PACKED = 0x010C0055
166
167 BAYER_GR_10_PACKED = 0x010A0056
168 BAYER_GR_12_PACKED = 0x010C0057
169
170 BAYER_RG_10_PACKED = 0x010A0058
171 BAYER_RG_12_PACKED = 0x010C0059
172
173 MONO_10_PACKED = 0x010A0046
174 MONO_12_PACKED = 0x010C0047
175
176 RGB_10_PACKED_32 = 0x0220001D
177 BGR_10_PACKED_32 = 0x0220001E
178
179 BAYER_RG_10_GROUPED_40_IDS = 0x40000001
180 BAYER_GB_10_GROUPED_40_IDS = 0x40000002
181 BAYER_GR_10_GROUPED_40_IDS = 0x40000003
182 BAYER_BG_10_GROUPED_40_IDS = 0x40000004
183
184 BAYER_RG_12_GROUPED_24_IDS = 0x40000011
185 BAYER_GB_12_GROUPED_24_IDS = 0x40000012
186 BAYER_GR_12_GROUPED_24_IDS = 0x40000013
187 BAYER_BG_12_GROUPED_24_IDS = 0x40000014
188
189 MONO_10_GROUPED_40_IDS = 0x4000000f
190 MONO_12_GROUPED_24_IDS = 0x4000001f
191
192 @staticmethod
193 def create_from_string_value(string_value: str) -> PixelFormat:
194 for pixelformat in _pixel_format_metadata:
195 if pixelformat.string_value == string_value:
196 return pixelformat
197
198 raise NotSupportedException(f"The given pixelformat is not supported. Given: {string_value}")
199
200 def __str__(self) -> str:
201 """!
202 @brief
203 Return a human-readable string of the PixelFormat object.
204 """
205 return self.name
206
207 def __repr__(self) -> str:
208 """!
209 @brief
210 Return an unambiguous string of the PixelFormat object.
211 """
212 return f"PixelFormat.{self.name}(value={hex(self._value_)}, string_value={self.string_value!r})"
213
214 @property
215 def minimum_value_per_channel(self) -> Union[int, float]:
216 """!
217 @brief
218 Returns the minimum possible value per channel for the pixel format.
219 """
220 if not self.is_floatis_float:
221 return 0
222 else:
223 return FLOAT32_MIN
224
225 @property
226 def maximum_value_per_channel(self) -> Union[int, float]:
227 """!
228 @brief
229 Returns the maximum possible value per channel for the pixel format.
230 """
231 if not self.is_floatis_float:
232 return int(2 ** self.storage_bits_per_channel - 1)
233 else:
234 return FLOAT32_MAX
235
236 @property
237 def storage_bits_per_channel(self) -> int:
238 """!
239 @brief
240 Returns the number of bits used per channel for storage.
241 """
242 return self._metadata.storage_bits_per_channel
243
244 @property
245 def storage_bits_per_pixel(self) -> int:
246 """!
247 @brief
248 Returns the total number of bits used per pixel for storage.
249 """
250 return self._metadata.storage_bits_per_channel * self.number_of_channels
251
252 @property
253 def string_value(self) -> str:
254 """!
255 @brief
256 Returns the human-readable name of the pixel format.
257 """
258 return self._metadata.string_value
259
260 @property
261 def channels(self) -> Tuple[Channel, ...]:
262 """!
263 @brief
264 Returns the list of channels in the pixel format.
265 """
266 return self._metadata.channels
267
268 @property
269 def allocated_bits_per_pixel(self) -> int:
270 """!
271 @brief
272 Returns the number of allocated bits per pixel.
273 """
274 return self._metadata.allocated_bits_per_pixel
275
276 @property
277 def numpy_dtype(self) -> str:
278 """!
279 @brief
280 Returns the numpy dtype string for this pixel format.
281 """
282 return self._metadata.numpy_dtype
283
284 @property
285 def has_intensity_channel(self) -> bool:
286 """!
287 @brief
288 Returns True if the pixel format has an intensity channel.
289 """
290 return Channel.INTENSITY in self.channelschannels
291
292 @property
293 def number_of_channels(self) -> int:
294 """!
295 @brief
296 Returns the total number of channels in the pixel format.
297 """
298 return len(self.channelschannels)
299
300 @property
301 def is_single_channel(self) -> bool:
302 """!
303 @brief
304 Returns True if the pixel format has only a single channel.
305 """
306 return len(self.channelschannels) == 1
307
308 @property
309 def is_packed(self) -> bool:
310 """!
311 @brief
312 Returns True if the pixel format is packed.
313 """
314 return self._metadata.is_packed
315
316 @property
317 def unpacked_format(self) -> PixelFormat:
318 """!
319 @brief
320 Returns the unpacked pixel format for a packed pixel format.
321 If the pixel format is already unpacked,
322 the same format is returned.
323 """
324 return self._metadata.unpacked_format
325
326 def get_channel_index(self, channel: Channel) -> int:
327 """!
328 @brief
329 Returns the index of a specific channel within the pixel format.
330 """
331 return self.channelschannels.index(channel)
332
333 def has_channel(self, channel: Channel) -> bool:
334 """!
335 @brief
336 Returns True if the pixel format has a specific channel.
337 """
338 return channel in self.channelschannels
339
340 def get_size_in_bytes(self, size: Size) -> int:
341 """!
342 @brief
343 Calculates the memory size in bytes for a given image size.
344 """
345 area = size.width * size.height
346 return int((area * self.allocated_bits_per_pixel + 7) // 8)
347
348 @property
349 def _metadata(self) -> _PixelFormatMetadata:
350 return cast(_PixelFormatMetadata, _pixel_format_metadata.get(self))
351
352 @property
353 def is_float(self) -> bool:
354 return self._metadata.numpy_dtype == "float32"
355
356
357_pixel_format_metadata = {
358 PixelFormat.BAYER_GR_8: _PixelFormatMetadata(
359 string_value="BayerGR8",
360 channels=(Channel.BAYER,),
361 storage_bits_per_channel=8,
362 allocated_bits_per_pixel=8,
363 numpy_dtype="uint8",
364 is_packed=False,
365 unpacked_format=PixelFormat.BAYER_GR_8
366 ),
367
368 PixelFormat.BAYER_GR_10: _PixelFormatMetadata(
369 string_value="BayerGR10",
370 channels=(Channel.BAYER,),
371 storage_bits_per_channel=10,
372 allocated_bits_per_pixel=16,
373 numpy_dtype="uint16",
374 is_packed=False,
375 unpacked_format=PixelFormat.BAYER_GR_10
376 ),
377
378 PixelFormat.BAYER_GR_12: _PixelFormatMetadata(
379 string_value="BayerGR12",
380 channels=(Channel.BAYER,),
381 storage_bits_per_channel=12,
382 allocated_bits_per_pixel=16,
383 numpy_dtype="uint16",
384 is_packed=False,
385 unpacked_format=PixelFormat.BAYER_GR_12
386 ),
387
388 PixelFormat.BAYER_RG_8: _PixelFormatMetadata(
389 string_value="BayerRG8",
390 channels=(Channel.BAYER,),
391 storage_bits_per_channel=8,
392 allocated_bits_per_pixel=8,
393 numpy_dtype="uint8",
394 is_packed=False,
395 unpacked_format=PixelFormat.BAYER_RG_8
396 ),
397
398 PixelFormat.BAYER_RG_10: _PixelFormatMetadata(
399 string_value="BayerRG10",
400 channels=(Channel.BAYER,),
401 storage_bits_per_channel=10,
402 allocated_bits_per_pixel=16,
403 numpy_dtype="uint16",
404 is_packed=False,
405 unpacked_format=PixelFormat.BAYER_RG_10
406 ),
407
408 PixelFormat.BAYER_RG_12: _PixelFormatMetadata(
409 string_value="BayerRG12",
410 channels=(Channel.BAYER,),
411 storage_bits_per_channel=12,
412 allocated_bits_per_pixel=16,
413 numpy_dtype="uint16",
414 is_packed=False,
415 unpacked_format=PixelFormat.BAYER_RG_12
416 ),
417
418 PixelFormat.BAYER_GB_8: _PixelFormatMetadata(
419 string_value="BayerGB8",
420 channels=(Channel.BAYER,),
421 storage_bits_per_channel=8,
422 allocated_bits_per_pixel=8,
423 numpy_dtype="uint8",
424 is_packed=False,
425 unpacked_format=PixelFormat.BAYER_GB_8
426 ),
427
428 PixelFormat.BAYER_GB_10: _PixelFormatMetadata(
429 string_value="BayerGB10",
430 channels=(Channel.BAYER,),
431 storage_bits_per_channel=10,
432 allocated_bits_per_pixel=16,
433 numpy_dtype="uint16",
434 is_packed=False,
435 unpacked_format=PixelFormat.BAYER_GB_10
436 ),
437
438 PixelFormat.BAYER_GB_12: _PixelFormatMetadata(
439 string_value="BayerGB12",
440 channels=(Channel.BAYER,),
441 storage_bits_per_channel=12,
442 allocated_bits_per_pixel=16,
443 numpy_dtype="uint16",
444 is_packed=False,
445 unpacked_format=PixelFormat.BAYER_GB_12
446 ),
447
448 PixelFormat.BAYER_BG_8: _PixelFormatMetadata(
449 string_value="BayerBG8",
450 channels=(Channel.BAYER,),
451 storage_bits_per_channel=8,
452 allocated_bits_per_pixel=8,
453 numpy_dtype="uint8",
454 is_packed=False,
455 unpacked_format=PixelFormat.BAYER_BG_8
456 ),
457
458 PixelFormat.BAYER_BG_10: _PixelFormatMetadata(
459 string_value="BayerBG10",
460 channels=(Channel.BAYER,),
461 storage_bits_per_channel=10,
462 allocated_bits_per_pixel=16,
463 numpy_dtype="uint16",
464 is_packed=False,
465 unpacked_format=PixelFormat.BAYER_BG_10
466 ),
467
468 PixelFormat.BAYER_BG_12: _PixelFormatMetadata(
469 string_value="BayerBG12",
470 channels=(Channel.BAYER,),
471 storage_bits_per_channel=12,
472 allocated_bits_per_pixel=16,
473 numpy_dtype="uint16",
474 is_packed=False,
475 unpacked_format=PixelFormat.BAYER_BG_12
476 ),
477
478 PixelFormat.MONO_8: _PixelFormatMetadata(
479 string_value="Mono8",
480 channels=(Channel.INTENSITY,),
481 storage_bits_per_channel=8,
482 allocated_bits_per_pixel=8,
483 numpy_dtype="uint8",
484 is_packed=False,
485 unpacked_format=PixelFormat.MONO_8
486 ),
487
488 PixelFormat.MONO_10: _PixelFormatMetadata(
489 string_value="Mono10",
490 channels=(Channel.INTENSITY,),
491 storage_bits_per_channel=10,
492 allocated_bits_per_pixel=16,
493 numpy_dtype="uint16",
494 is_packed=False,
495 unpacked_format=PixelFormat.MONO_10
496 ),
497
498 PixelFormat.MONO_12: _PixelFormatMetadata(
499 string_value="Mono12",
500 channels=(Channel.INTENSITY,),
501 storage_bits_per_channel=12,
502 allocated_bits_per_pixel=16,
503 numpy_dtype="uint16",
504 is_packed=False,
505 unpacked_format=PixelFormat.MONO_12
506 ),
507
508 PixelFormat.MONO_16: _PixelFormatMetadata(
509 string_value="Mono16",
510 channels=(Channel.INTENSITY,),
511 storage_bits_per_channel=16,
512 allocated_bits_per_pixel=16,
513 numpy_dtype="uint16",
514 is_packed=False,
515 unpacked_format=PixelFormat.MONO_16
516 ),
517
518 PixelFormat.CONFIDENCE_8: _PixelFormatMetadata(
519 string_value="Confidence8",
520 channels=(Channel.INTENSITY,),
521 storage_bits_per_channel=8,
522 allocated_bits_per_pixel=8,
523 numpy_dtype="uint8",
524 is_packed=False,
525 unpacked_format=PixelFormat.CONFIDENCE_8
526 ),
527
528 PixelFormat.CONFIDENCE_16: _PixelFormatMetadata(
529 string_value="Confidence16",
530 channels=(Channel.INTENSITY,),
531 storage_bits_per_channel=16,
532 allocated_bits_per_pixel=16,
533 numpy_dtype="uint16",
534 is_packed=False,
535 unpacked_format=PixelFormat.CONFIDENCE_16
536 ),
537
538 PixelFormat.COORD3D_C8: _PixelFormatMetadata(
539 string_value="Coord3D_C8",
540 channels=(Channel.INTENSITY,),
541 storage_bits_per_channel=8,
542 allocated_bits_per_pixel=8,
543 numpy_dtype="uint8",
544 is_packed=False,
545 unpacked_format=PixelFormat.COORD3D_C8
546 ),
547
548 PixelFormat.COORD3D_C16: _PixelFormatMetadata(
549 string_value="Coord3D_C16",
550 channels=(Channel.INTENSITY,),
551 storage_bits_per_channel=16,
552 allocated_bits_per_pixel=16,
553 numpy_dtype="uint16",
554 is_packed=False,
555 unpacked_format=PixelFormat.COORD3D_C16
556 ),
557
558 PixelFormat.COORD3D_C32F: _PixelFormatMetadata(
559 string_value="Coord3D_C32f",
560 channels=(Channel.INTENSITY,),
561 storage_bits_per_channel=32,
562 allocated_bits_per_pixel=32,
563 numpy_dtype="float32",
564 is_packed=False,
565 unpacked_format=PixelFormat.COORD3D_C32F
566 ),
567
568 PixelFormat.COORD3D_ABC32F: _PixelFormatMetadata(
569 string_value="Coord3D_ABC32f",
570 channels=(Channel.X, Channel.Y, Channel.Z),
571 storage_bits_per_channel=32,
572 allocated_bits_per_pixel=96,
573 numpy_dtype="float32",
574 is_packed=False,
575 unpacked_format=PixelFormat.COORD3D_ABC32F
576 ),
577
578 PixelFormat.YUV420_8_YY_UV_SEMIPLANAR_IDS: _PixelFormatMetadata(
579 string_value="YUV420_8_YY_UV_SemiplanarIDS",
580 channels=(Channel.INTENSITY, Channel.CHROMA_U, Channel.CHROMA_V),
581 storage_bits_per_channel=8,
582 allocated_bits_per_pixel=12,
583 numpy_dtype="uint8",
584 is_packed=False,
585 unpacked_format=PixelFormat.YUV420_8_YY_UV_SEMIPLANAR_IDS
586 ),
587
588 PixelFormat.YUV420_8_YY_VU_SEMIPLANAR_IDS: _PixelFormatMetadata(
589 string_value="YUV420_8_YY_VU_SemiplanarIDS",
590 channels=(Channel.INTENSITY, Channel.CHROMA_V, Channel.CHROMA_U),
591 storage_bits_per_channel=8,
592 allocated_bits_per_pixel=12,
593 numpy_dtype="uint8",
594 is_packed=False,
595 unpacked_format=PixelFormat.YUV420_8_YY_VU_SEMIPLANAR_IDS
596 ),
597
598 PixelFormat.YUV422_8_UYVY: _PixelFormatMetadata(
599 string_value="YUV422_8_UYVY",
600 channels=(Channel.INTENSITY, Channel.CHROMA_U, Channel.CHROMA_V),
601 storage_bits_per_channel=8,
602 allocated_bits_per_pixel=16,
603 numpy_dtype="uint8",
604 is_packed=False,
605 unpacked_format=PixelFormat.YUV422_8_UYVY
606 ),
607
608 PixelFormat.RGB_8: _PixelFormatMetadata(
609 string_value="RGB8",
610 channels=(Channel.RED, Channel.GREEN, Channel.BLUE),
611 storage_bits_per_channel=8,
612 allocated_bits_per_pixel=24,
613 numpy_dtype="uint8",
614 is_packed=False,
615 unpacked_format=PixelFormat.RGB_8
616 ),
617
618 PixelFormat.RGB_10: _PixelFormatMetadata(
619 string_value="RGB10",
620 channels=(Channel.RED, Channel.GREEN, Channel.BLUE),
621 storage_bits_per_channel=10,
622 allocated_bits_per_pixel=48,
623 numpy_dtype="uint16",
624 is_packed=False,
625 unpacked_format=PixelFormat.RGB_10
626 ),
627
628 PixelFormat.RGB_12: _PixelFormatMetadata(
629 string_value="RGB12",
630 channels=(Channel.RED, Channel.GREEN, Channel.BLUE),
631 storage_bits_per_channel=12,
632 allocated_bits_per_pixel=48,
633 numpy_dtype="uint16",
634 is_packed=False,
635 unpacked_format=PixelFormat.RGB_12
636 ),
637
638 PixelFormat.BGR_8: _PixelFormatMetadata(
639 string_value="BGR8",
640 channels=(Channel.BLUE, Channel.GREEN, Channel.RED),
641 storage_bits_per_channel=8,
642 allocated_bits_per_pixel=24,
643 numpy_dtype="uint8",
644 is_packed=False,
645 unpacked_format=PixelFormat.BGR_8
646 ),
647
648 PixelFormat.BGR_10: _PixelFormatMetadata(
649 string_value="BGR10",
650 channels=(Channel.BLUE, Channel.GREEN, Channel.RED),
651 storage_bits_per_channel=10,
652 allocated_bits_per_pixel=48,
653 numpy_dtype="uint16",
654 is_packed=False,
655 unpacked_format=PixelFormat.BGR_10
656 ),
657
658 PixelFormat.BGR_12: _PixelFormatMetadata(
659 string_value="BGR12",
660 channels=(Channel.BLUE, Channel.GREEN, Channel.RED),
661 storage_bits_per_channel=12,
662 allocated_bits_per_pixel=48,
663 numpy_dtype="uint16",
664 is_packed=False,
665 unpacked_format=PixelFormat.BGR_12
666 ),
667
668 PixelFormat.RGBA_8: _PixelFormatMetadata(
669 string_value="RGBa8",
670 channels=(Channel.RED, Channel.GREEN, Channel.BLUE, Channel.ALPHA),
671 storage_bits_per_channel=8,
672 allocated_bits_per_pixel=32,
673 numpy_dtype="uint8",
674 is_packed=False,
675 unpacked_format=PixelFormat.RGBA_8
676 ),
677
678 PixelFormat.RGBA_10: _PixelFormatMetadata(
679 string_value="RGBa10",
680 channels=(Channel.RED, Channel.GREEN, Channel.BLUE, Channel.ALPHA),
681 storage_bits_per_channel=10,
682 allocated_bits_per_pixel=64,
683 numpy_dtype="uint16",
684 is_packed=False,
685 unpacked_format=PixelFormat.RGBA_10
686 ),
687
688 PixelFormat.RGBA_12: _PixelFormatMetadata(
689 string_value="RGBa12",
690 channels=(Channel.RED, Channel.GREEN, Channel.BLUE, Channel.ALPHA),
691 storage_bits_per_channel=12,
692 allocated_bits_per_pixel=64,
693 numpy_dtype="uint16",
694 is_packed=False,
695 unpacked_format=PixelFormat.RGBA_12
696 ),
697
698 PixelFormat.BGRA_8: _PixelFormatMetadata(
699 string_value="BGRa8",
700 channels=(Channel.BLUE, Channel.GREEN, Channel.RED, Channel.ALPHA),
701 storage_bits_per_channel=8,
702 allocated_bits_per_pixel=32,
703 numpy_dtype="uint8",
704 is_packed=False,
705 unpacked_format=PixelFormat.BGRA_8
706 ),
707
708 PixelFormat.BGRA_10: _PixelFormatMetadata(
709 string_value="BGRa10",
710 channels=(Channel.BLUE, Channel.GREEN, Channel.RED, Channel.ALPHA),
711 storage_bits_per_channel=10,
712 allocated_bits_per_pixel=64,
713 numpy_dtype="uint16",
714 is_packed=False,
715 unpacked_format=PixelFormat.BGRA_10
716 ),
717
718 PixelFormat.BGRA_12: _PixelFormatMetadata(
719 string_value="BGRa12",
720 channels=(Channel.BLUE, Channel.GREEN, Channel.RED, Channel.ALPHA),
721 storage_bits_per_channel=12,
722 allocated_bits_per_pixel=64,
723 numpy_dtype="uint16",
724 is_packed=False,
725 unpacked_format=PixelFormat.BGRA_12
726 ),
727
728 PixelFormat.BAYER_BG_10_PACKED: _PixelFormatMetadata(
729 string_value="BayerBG10p",
730 channels=(Channel.BAYER,),
731 storage_bits_per_channel=10,
732 allocated_bits_per_pixel=10,
733 numpy_dtype="uint16",
734 is_packed=True,
735 unpacked_format=PixelFormat.BAYER_BG_10
736 ),
737
738 PixelFormat.BAYER_BG_12_PACKED: _PixelFormatMetadata(
739 string_value="BayerBG12p",
740 channels=(Channel.BAYER,),
741 storage_bits_per_channel=12,
742 allocated_bits_per_pixel=12,
743 numpy_dtype="uint16",
744 is_packed=True,
745 unpacked_format=PixelFormat.BAYER_BG_12
746 ),
747
748 PixelFormat.BAYER_GB_10_PACKED: _PixelFormatMetadata(
749 string_value="BayerGB10p",
750 channels=(Channel.BAYER,),
751 storage_bits_per_channel=10,
752 allocated_bits_per_pixel=10,
753 numpy_dtype="uint16",
754 is_packed=True,
755 unpacked_format=PixelFormat.BAYER_GB_10
756 ),
757
758 PixelFormat.BAYER_GB_12_PACKED: _PixelFormatMetadata(
759 string_value="BayerGB12p",
760 channels=(Channel.BAYER,),
761 storage_bits_per_channel=12,
762 allocated_bits_per_pixel=12,
763 numpy_dtype="uint16",
764 is_packed=True,
765 unpacked_format=PixelFormat.BAYER_GB_12
766 ),
767
768 PixelFormat.BAYER_GR_10_PACKED: _PixelFormatMetadata(
769 string_value="BayerGR10p",
770 channels=(Channel.BAYER,),
771 storage_bits_per_channel=10,
772 allocated_bits_per_pixel=10,
773 numpy_dtype="uint16",
774 is_packed=True,
775 unpacked_format=PixelFormat.BAYER_GR_10
776 ),
777
778 PixelFormat.BAYER_GR_12_PACKED: _PixelFormatMetadata(
779 string_value="BayerGR12p",
780 channels=(Channel.BAYER,),
781 storage_bits_per_channel=12,
782 allocated_bits_per_pixel=12,
783 numpy_dtype="uint16",
784 is_packed=True,
785 unpacked_format=PixelFormat.BAYER_GR_12
786 ),
787
788 PixelFormat.BAYER_RG_10_PACKED: _PixelFormatMetadata(
789 string_value="BayerRG10p",
790 channels=(Channel.BAYER,),
791 storage_bits_per_channel=10,
792 allocated_bits_per_pixel=10,
793 numpy_dtype="uint16",
794 is_packed=True,
795 unpacked_format=PixelFormat.BAYER_RG_10
796 ),
797
798 PixelFormat.BAYER_RG_12_PACKED: _PixelFormatMetadata(
799 string_value="BayerRG12p",
800 channels=(Channel.BAYER,),
801 storage_bits_per_channel=12,
802 allocated_bits_per_pixel=12,
803 numpy_dtype="uint16",
804 is_packed=True,
805 unpacked_format=PixelFormat.BAYER_RG_12
806 ),
807
808 PixelFormat.MONO_10_PACKED: _PixelFormatMetadata(
809 string_value="Mono10p",
810 channels=(Channel.INTENSITY,),
811 storage_bits_per_channel=10,
812 allocated_bits_per_pixel=10,
813 numpy_dtype="uint16",
814 is_packed=True,
815 unpacked_format=PixelFormat.MONO_10
816 ),
817
818 PixelFormat.MONO_12_PACKED: _PixelFormatMetadata(
819 string_value="Mono12p",
820 channels=(Channel.INTENSITY,),
821 storage_bits_per_channel=12,
822 allocated_bits_per_pixel=12,
823 numpy_dtype="uint16",
824 is_packed=True,
825 unpacked_format=PixelFormat.MONO_12
826 ),
827
828 PixelFormat.RGB_10_PACKED_32: _PixelFormatMetadata(
829 string_value="RGB10p32",
830 channels=(Channel.RED, Channel.GREEN, Channel.BLUE),
831 storage_bits_per_channel=10,
832 allocated_bits_per_pixel=32,
833 numpy_dtype="uint32",
834 is_packed=True,
835 unpacked_format=PixelFormat.RGB_10
836 ),
837
838 PixelFormat.BGR_10_PACKED_32: _PixelFormatMetadata(
839 string_value="BGR10p32",
840 channels=(Channel.BLUE, Channel.GREEN, Channel.RED),
841 storage_bits_per_channel=10,
842 allocated_bits_per_pixel=32,
843 numpy_dtype="uint32",
844 is_packed=True,
845 unpacked_format=PixelFormat.BGR_10
846 ),
847
848 PixelFormat.BAYER_RG_10_GROUPED_40_IDS: _PixelFormatMetadata(
849 string_value="BayerRG10g40IDS",
850 channels=(Channel.BAYER,),
851 storage_bits_per_channel=10,
852 allocated_bits_per_pixel=10,
853 numpy_dtype="uint16",
854 is_packed=True,
855 unpacked_format=PixelFormat.BAYER_RG_10
856 ),
857
858 PixelFormat.BAYER_GB_10_GROUPED_40_IDS: _PixelFormatMetadata(
859 string_value="BayerGB10g40IDS",
860 channels=(Channel.BAYER,),
861 storage_bits_per_channel=10,
862 allocated_bits_per_pixel=10,
863 numpy_dtype="uint16",
864 is_packed=True,
865 unpacked_format=PixelFormat.BAYER_GB_10
866 ),
867
868 PixelFormat.BAYER_GR_10_GROUPED_40_IDS: _PixelFormatMetadata(
869 string_value="BayerGR10g40IDS",
870 channels=(Channel.BAYER,),
871 storage_bits_per_channel=10,
872 allocated_bits_per_pixel=10,
873 numpy_dtype="uint16",
874 is_packed=True,
875 unpacked_format=PixelFormat.BAYER_GR_10
876 ),
877
878 PixelFormat.BAYER_BG_10_GROUPED_40_IDS: _PixelFormatMetadata(
879 string_value="BayerBG10g40IDS",
880 channels=(Channel.BAYER,),
881 storage_bits_per_channel=10,
882 allocated_bits_per_pixel=10,
883 numpy_dtype="uint16",
884 is_packed=True,
885 unpacked_format=PixelFormat.BAYER_BG_10
886 ),
887
888 PixelFormat.BAYER_RG_12_GROUPED_24_IDS: _PixelFormatMetadata(
889 string_value="BayerRG12g24IDS",
890 channels=(Channel.BAYER,),
891 storage_bits_per_channel=12,
892 allocated_bits_per_pixel=12,
893 numpy_dtype="uint16",
894 is_packed=True,
895 unpacked_format=PixelFormat.BAYER_RG_12
896 ),
897
898 PixelFormat.BAYER_GB_12_GROUPED_24_IDS: _PixelFormatMetadata(
899 string_value="BayerGB12g24IDS",
900 channels=(Channel.BAYER,),
901 storage_bits_per_channel=12,
902 allocated_bits_per_pixel=12,
903 numpy_dtype="uint16",
904 is_packed=True,
905 unpacked_format=PixelFormat.BAYER_GB_12
906 ),
907
908 PixelFormat.BAYER_GR_12_GROUPED_24_IDS: _PixelFormatMetadata(
909 string_value="BayerGR12g24IDS",
910 channels=(Channel.BAYER,),
911 storage_bits_per_channel=12,
912 allocated_bits_per_pixel=12,
913 numpy_dtype="uint16",
914 is_packed=True,
915 unpacked_format=PixelFormat.BAYER_GR_12
916 ),
917
918 PixelFormat.BAYER_BG_12_GROUPED_24_IDS: _PixelFormatMetadata(
919 string_value="BayerBG12g24IDS",
920 channels=(Channel.BAYER,),
921 storage_bits_per_channel=12,
922 allocated_bits_per_pixel=12,
923 numpy_dtype="uint16",
924 is_packed=True,
925 unpacked_format=PixelFormat.BAYER_BG_12
926 ),
927
928 PixelFormat.MONO_10_GROUPED_40_IDS: _PixelFormatMetadata(
929 string_value="Mono10g40IDS",
930 channels=(Channel.INTENSITY,),
931 storage_bits_per_channel=10,
932 allocated_bits_per_pixel=10,
933 numpy_dtype="uint16",
934 is_packed=True,
935 unpacked_format=PixelFormat.MONO_10
936 ),
937
938 PixelFormat.MONO_12_GROUPED_24_IDS: _PixelFormatMetadata(
939 string_value="Mono12g24IDS",
940 channels=(Channel.INTENSITY,),
941 storage_bits_per_channel=12,
942 allocated_bits_per_pixel=12,
943 numpy_dtype="uint16",
944 is_packed=True,
945 unpacked_format=PixelFormat.MONO_12
946 )
947}
Enum listing all supported pixel formats and their internal IDs.
int allocated_bits_per_pixel(self)
Returns the number of allocated bits per pixel.
bool has_intensity_channel(self)
Returns True if the pixel format has an intensity channel.
str numpy_dtype(self)
Returns the numpy dtype string for this pixel format.
int get_size_in_bytes(self, Size size)
Calculates the memory size in bytes for a given image size.
Union[int, float] maximum_value_per_channel(self)
Returns the maximum possible value per channel for the pixel format.
PixelFormat create_from_string_value(str string_value)
Union[int, float] minimum_value_per_channel(self)
Returns the minimum possible value per channel for the pixel format.
int storage_bits_per_pixel(self)
Returns the total number of bits used per pixel for storage.
PixelFormat unpacked_format(self)
Returns the unpacked pixel format for a packed pixel format.
bool is_packed(self)
Returns True if the pixel format is packed.
str string_value(self)
Returns the human-readable name of the pixel format.
int storage_bits_per_channel(self)
Returns the number of bits used per channel for storage.
bool has_channel(self, Channel channel)
Returns True if the pixel format has a specific channel.
Tuple[Channel,...] channels(self)
Returns the list of channels in the pixel format.
str __str__(self)
Return a human-readable string of the PixelFormat object.
int number_of_channels(self)
Returns the total number of channels in the pixel format.
str __repr__(self)
Return an unambiguous string of the PixelFormat object.
bool is_single_channel(self)
Returns True if the pixel format has only a single channel.
int get_channel_index(self, Channel channel)
Returns the index of a specific channel within the pixel format.
Thrown when an unsupported operation or feature is used.