IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
Threshold.cs
Go to the documentation of this file.
1using System.Runtime.InteropServices;
7
9{
10 namespace Detail
11 {
20 public abstract class ThresholdT<T> where T : struct, IComparable<T>
21 {
29 public ThresholdT(IntervalT<T> interval)
30 {
31 Interval = interval;
32 }
33
38 public IntervalT<T> Interval { get; }
39
65 public Region Process(Image image)
66 {
67 var region = new Region();
68 var sizeOfInterval = Marshal.SizeOf(typeof(Backend.Types.peak_icv_interval_u));
69
70 var intervalBackend = Activator.CreateInstance(TypeTraits.GetCTypeOfInterval<IntervalT<T>>(),
72
73 var handle = GCHandle.Alloc(intervalBackend, GCHandleType.Pinned);
74 IntPtr ptr = handle.AddrOfPinnedObject();
75
76 try
77 {
78 DllHelper.ExecuteAndMapReturnCodes(() =>
79 CInterface.peak_icv_Threshold_Process(image._handle,
80 ptr,
81 (nuint) sizeOfInterval, out region._handle));
82 }
83 finally
84 {
85 handle.Free();
86 }
87
88 return region;
89 }
90 }
91 }
92
98 public class Threshold : ThresholdT<int>
99 {
107 public Threshold(Interval interval) : base(interval)
108 {
109 }
110
125 public static Interval GetRange(Image image)
126 {
127 var intervalBackend = new Backend.Types.peak_icv_interval();
128 var sizeOfInterval = Marshal.SizeOf(typeof(Backend.Types.peak_icv_interval));
129
130 unsafe
131 {
132 Backend.Types.peak_icv_interval* ptr = &intervalBackend;
133 DllHelper.ExecuteAndMapReturnCodes(() =>
134 CInterface.peak_icv_Threshold_GetRange(image._handle, (IntPtr) ptr, (nuint) sizeOfInterval));
135 }
136
137 return new Interval(intervalBackend.minimum, intervalBackend.maximum);
138 }
140
146 public class ThresholdF : ThresholdT<float>
147 {
155 public ThresholdF(IntervalF interval) : base(interval)
156 {
157 }
158
173 public static IntervalF GetRange(Image image)
174 {
175 var intervalBackend = new Backend.Types.peak_icv_interval_f();
176 var sizeOfInterval = Marshal.SizeOf(typeof(Backend.Types.peak_icv_interval_f));
177
178 unsafe
179 {
180 Backend.Types.peak_icv_interval_f* ptr = &intervalBackend;
181 DllHelper.ExecuteAndMapReturnCodes(() =>
182 CInterface.peak_icv_Threshold_GetRange(image._handle, (IntPtr) ptr, (nuint) sizeOfInterval));
183 }
184
185 return new IntervalF(intervalBackend.minimum, intervalBackend.maximum);
186 }
188
189 internal static class CInterface
190 {
191 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
192 public static extern Backend.Types.peak_icv_status peak_icv_Threshold_Process(Image.Handle inputImage,
193 IntPtr interval, nuint sizeOfInterval, out Region.Handle outputRegion);
194
195 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
196 public static extern Backend.Types.peak_icv_status peak_icv_Threshold_GetRange(Image.Handle inputImage,
197 IntPtr interval, nuint sizeOfInterval);
198 }
199}
Represents an interval consisting of a lower and upper boundary value.
Definition Interval.cs:21
T Maximum
Gets the upper boundary of the interval.
Definition Interval.cs:50
T Minimum
Gets the lower boundary of the interval.
Definition Interval.cs:45
Represents an interval with floating-point boundaries.
Definition Interval.cs:157
Represents an interval with signed integer boundaries.
Definition Interval.cs:117
Region Process(Image image)
Applies a threshold on a given single-channel image of type integer and returns a region with selecte...
Definition Threshold.cs:65
ThresholdT(IntervalT< T > interval)
Creates an instance of class ThresholdT.
Definition Threshold.cs:29
Class for thresholding an image of type float.
Definition Threshold.cs:161
ThresholdF(IntervalF interval)
Creates an instance of class Threshold for thresholding images of type float.
Definition Threshold.cs:169
static IntervalF GetRange(Image image)
Queries the minimum and maximum representable pixel values for the specified image’s pixel format.
Definition Threshold.cs:187
Class for thresholding an image of type integer.
Definition Threshold.cs:113
Threshold(Interval interval)
Creates an instance of class Threshold for thresholding images of type integer.
Definition Threshold.cs:121
static Interval GetRange(Image image)
Queries the minimum and maximum representable pixel values for the specified image’s pixel format.
Definition Threshold.cs:139
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
Represents a region defined by a set of points in the image plane.
Definition Region.cs:43