IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
threshold.py
Go to the documentation of this file.
1import ctypes
2from typing import Union
3
4from ids_peak_ipl import ids_peak_ipl
5
6from ids_peak_common.datatypes.interval import Interval
7
8from ids_peak_icv import lib_loader
9from ids_peak_icv.datatypes.region import Region
10from ids_peak_icv.backend.datatypes import peak_icv_region_handle, peak_icv_interval, peak_icv_interval_f
11from ids_peak_icv.backend.utils import execute_and_map_return_codes
12from ids_peak_icv.exceptions import ICVException
13from ids_peak_icv.datatypes.image import Image, _check_and_get_icv_image
14
15
17 """!
18 @brief
19 Class for thresholding an image.
20
21 @ingroup ids_peak_icv_python_thresholds
22 @since ids_peak_icv 1.1
23 """
24
25 def __init__(self, interval: Interval) -> None:
26 """!
27 @brief
28 Creates an instance of class Threshold.
29
30 @param interval: The interval to be used.
31
32 @since ids_peak_icv 1.1
33 """
34 self._interval = interval
35
36 @property
37 def interval(self) -> Interval:
38 """!
39 @brief
40 Returns the interval in which the threshold will be applied.
41
42 @since ids_peak_icv 1.1
43 """
44 return self._interval
45
46 @interval.setter
47 def interval(self, interval: Interval) -> None:
48 """!
49 @brief
50 Sets the thresholding interval.
51
52 @param interval: The interval to be used.
53
54 @exception OutOfRangeException: If the interval is out of range.
55
56 @since ids_peak_icv 1.1
57 """
58 self._interval = interval
59
60 def process(self, image: Union[Image, ids_peak_ipl.Image]) -> Region:
61 """!
62 @brief
63 Applies a threshold on a given single-channel image and returns a region with selected pixels
64 whose gray values are in the range Interval.minimum <= gray value <= Interval.maximum.
65
66 @param image: An image of type Mono8, Mono10, Mono12 or Coord3D.
67
68 @return Region: Returns a region with selected pixels.
69
70 @exception OutOfRangeException: If the interval is out of bounds for the pixel format.
71 @exception NotPossibleException: If the image is too big for processing.
72
73 @since ids_peak_icv 1.1
74 """
75
76 _image = _check_and_get_icv_image(image)
77
78 image_handle = _image._handle
79 region_handle = peak_icv_region_handle()
80
81 execute_and_map_return_codes(lib_loader.dll().peak_icv_Region_Create,
82 ctypes.pointer(region_handle))
83
84 try:
85 c_interval: peak_icv_interval | peak_icv_interval_f
86
87 if type(self._interval.minimum) is int:
88 c_interval = peak_icv_interval(self._interval.minimum, self._interval.maximum)
89 else:
90 c_interval = peak_icv_interval_f(self._interval.minimum, self._interval.maximum)
91
92 execute_and_map_return_codes(lib_loader.dll().peak_icv_Threshold_Process,
93 image_handle,
94 ctypes.pointer(c_interval),
95 ctypes.sizeof(c_interval),
96 ctypes.pointer(region_handle))
97 except ICVException as e:
98 lib_loader.dll().peak_icv_Region_Destroy(region_handle)
99 raise e
100
101 return Region(_handle=region_handle)
102
103 @staticmethod
104 def get_range(image: Union[Image, ids_peak_ipl.Image]) -> Interval:
105 """!
106 @brief
107 Queries the minimum and maximum value of a given image and provides it as an interval.
108
109 @param image: An image of type Mono8, Mono10, Mono12 or Coord3D.
110
111 @return Interval: Returns the maximum possible range of the given image.
112
113 @since ids_peak_icv 1.1
114 """
115
116 _image = _check_and_get_icv_image(image)
117
118 image_handle = _image._handle
119
120 c_interval: peak_icv_interval | peak_icv_interval_f
121
122 if _image._pixel_format.is_float:
123 c_interval = peak_icv_interval_f()
124 else:
125 c_interval = peak_icv_interval()
126
127 execute_and_map_return_codes(lib_loader.dll().peak_icv_Threshold_GetRange,
128 image_handle, ctypes.pointer(c_interval), ctypes.sizeof(c_interval))
129 return Interval(c_interval.minimum, c_interval.maximum)
Represents an interval with lower and upper boundaries.
Definition interval.py:7
Represents a region consisting of a set of points in the image plane.
Definition region.py:29
Class for thresholding an image.
Definition threshold.py:16
None __init__(self, Interval interval)
Creates an instance of class Threshold.
Definition threshold.py:25
Region process(self, Union[Image, ids_peak_ipl.Image] image)
Applies a threshold on a given single-channel image and returns a region with selected pixels whose g...
Definition threshold.py:60
Interval get_range(Union[Image, ids_peak_ipl.Image] image)
Queries the minimum and maximum value of a given image and provides it as an interval.
Definition threshold.py:104
Interval interval(self)
Returns the interval in which the threshold will be applied.
Definition threshold.py:37