IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
HotpixelCorrectionModule.cs
Go to the documentation of this file.
1using System.Runtime.InteropServices;
7using Microsoft.Win32.SafeHandles;
8
10
19public class HotpixelCorrectionModule : ModuleBase, IDisposable, IHasSafeHandle
20{
21 private const string _xKey = "X";
22 private const string _yKey = "Y";
23 private const string _hotpixelListKey = "HotpixelList";
24
25 private readonly Handle _handle;
26
31 {
32 var handle = new Handle();
33 DllHelper.ExecuteAndMapReturnCodes(() =>
34 CInterface.peak_icv_Preprocessing_HotpixelCorrection_Create(out handle));
35 _handle = handle;
36 }
37
39 public override string TypeId => "HotpixelCorrection";
40
44 public IEnumerable<Point> HotpixelList
45 {
46 get
47 {
48 nuint hotpixelCount = 0;
49
50 DllHelper.ExecuteAndMapReturnCodes(() =>
51 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(
52 _handle, out hotpixelCount));
53
54 var hotpixelList = new Backend.Types.peak_icv_point[hotpixelCount];
55 DllHelper.ExecuteAndMapReturnCodes(() =>
56 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetList(
57 _handle, hotpixelList, hotpixelCount));
58
59 return hotpixelList.Select(point => new Point(point.x, point.y));
60 }
61 set
62 {
63 Backend.Types.peak_icv_point[] hotpixelList =
64 value.Select(point => new Backend.Types.peak_icv_point(point.X, point.Y)).ToArray();
65 DllHelper.ExecuteAndMapReturnCodes(() =>
66 CInterface.peak_icv_Preprocessing_HotpixelCorrection_SetList(
67 _handle, hotpixelList, (nuint) hotpixelList.Count()));
68 }
69 }
70
79 {
80 get
81 {
82 var interval = new Backend.Types.peak_icv_interval_u();
83 DllHelper.ExecuteAndMapReturnCodes(() =>
84 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(
85 _handle, out interval));
86 return new IntervalU(interval.minimum, interval.maximum);
87 }
88 }
89
93 public void Dispose()
94 {
95 _handle.Dispose();
96 GC.SuppressFinalize(this);
97 }
98
99 SafeHandle IHasSafeHandle.Handle => _handle;
100
128 public override Image Process(Image inputImage)
129 {
130 if (!IsEnabled || !NeedsProcessing())
131 {
132 return inputImage;
133 }
134
135 DllHelper.ExecuteAndMapReturnCodes(() =>
136 CInterface.peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(
137 _handle, inputImage._handle));
138
139 return inputImage;
140
141 bool NeedsProcessing()
142 {
143 nuint hotpixelCount = 0;
144 DllHelper.ExecuteAndMapReturnCodes(() =>
145 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(
146 _handle, out hotpixelCount));
147
148 return hotpixelCount != 0;
149 }
150 }
151
179 public override object Process(object input)
180 {
181 return base.Process(input);
182 }
183
195 public override void Serialize(IArchive archive)
196 {
197 base.Serialize(archive);
198
199 Point[] hotpixelList = HotpixelList.ToArray();
200 var archivesList = new List<IArchive>(hotpixelList.Length);
201 foreach (Point pixel in hotpixelList)
202 {
203 IArchive pixelArchive = archive.CreateArchive();
204 pixelArchive.SetInt64(_xKey, pixel.X);
205 pixelArchive.SetInt64(_yKey, pixel.Y);
206 archivesList.Add(pixelArchive);
207 }
208
209 archive.SetArchiveArray(_hotpixelListKey, archivesList);
210 }
211
239 public override void Deserialize(IArchive archive)
240 {
241 base.Deserialize(archive);
242
243 IReadOnlyList<IArchive> archives = archive.GetArchiveArray(_hotpixelListKey);
244 var hotpixelList = new List<Point>(archives.Count);
245 foreach (IArchive? pixelArchive in archives)
246 {
247 var x = pixelArchive.GetInt64(_xKey);
248 var y = pixelArchive.GetInt64(_yKey);
249 hotpixelList.Add(new Point((int) x, (int) y));
250 }
251
252 HotpixelList = hotpixelList;
253 }
254
294 public void Detect(Image image, uint sensitivity = 3, float gainFactor = 1.0F)
295 {
296 DllHelper.ExecuteAndMapReturnCodes(() =>
297 CInterface.peak_icv_Preprocessing_HotpixelCorrection_Detect(
298 _handle, image._handle, sensitivity, gainFactor));
299 }
300
308 public override void ResetToDefault()
309 {
310 DllHelper.ExecuteAndMapReturnCodes(() =>
311 CInterface.peak_icv_Preprocessing_HotpixelCorrection_ResetList(
312 _handle));
313 }
314
315 internal sealed class Handle : SafeHandleZeroOrMinusOneIsInvalid
316 {
317 internal Handle() : base(true)
318 {
319 }
320
321 protected override bool ReleaseHandle()
322 {
323 return CInterface.peak_icv_Preprocessing_HotpixelCorrection_Destroy(handle) == 0;
324 }
325 }
326
327 private static class CInterface
328 {
329 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
330 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_Create(
331 out Handle handle);
332
333 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
334 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_Destroy(
335 IntPtr handle);
336
337 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
338 internal static extern Backend.Types.peak_icv_status
339 peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(
340 Handle handle, Image.Handle imageHandle);
341
342 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
343 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_ResetList(
344 Handle handle);
345
346 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
347 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_SetList(
348 Handle handle, Backend.Types.peak_icv_point[] list, nuint count);
349
350 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
351 internal static extern Backend.Types.peak_icv_status
352 peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(
353 Handle handle, out nuint count);
354
355 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
356 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_GetList(
357 Handle handle, [Out] Backend.Types.peak_icv_point[] list, nuint count);
358
359 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
360 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_Detect(
361 Handle handle, Image.Handle imageHandle, uint sensitivity, float gainFactor);
362
363 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
364 internal static extern Backend.Types.peak_icv_status
365 peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(
366 Handle handle, out Backend.Types.peak_icv_interval_u range);
367 }
368}
T Y
Gets the Y coordinate of the point.
Definition Point.cs:34
T X
Gets the X coordinate of the point.
Definition Point.cs:29
Represents a 2D point with integer coordinates.
Definition Point.cs:98
Represents an interval with unsigned integer boundaries.
Definition Interval.cs:137
Hotpixel correction is an image pipeline module for detecting and correcting hot pixels in camera ima...
override void Deserialize(IArchive archive)
Restores the object's state from the provided archive.
IEnumerable< Point > HotpixelList
The current list of known hot pixels.
override Image Process(Image inputImage)
Applies hot pixel correction to the input image in place and returns a reference to the modified imag...
void Detect(Image image, uint sensitivity=3, float gainFactor=1.0F)
Performs immediate hot pixel detection on the given image.
IntervalU SensitivityRange
Returns the valid range of sensitivities.
override object Process(object input)
Applies hot pixel correction to the input image in place and returns a reference to the modified imag...
void Dispose()
Releases all resources used by this class.
override string TypeId
The unique type identifier for this module implementation.This should be a unique string identifying ...
HotpixelCorrectionModule()
Creates an instance of class HotpixelCorrectionModule.
override void Serialize(IArchive archive)
Serializes the object's internal state into the provided archive.
Base class for all pipeline modules.
Definition ModuleBase.cs:13
virtual bool IsEnabled
Get whether this module is enabled.
Definition ModuleBase.cs:28
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
Represents a hierarchical, strongly-typed key-value archive.
Definition IArchive.cs:79
IArchive CreateArchive()
Creates a new, empty archive instance of the same concrete type.
IReadOnlyList< IArchive > GetArchiveArray(string key)
Retrieves an array of nested archives by key.
long GetInt64(string key)
Retrieves a 64-bit integer value by key.
void SetInt64(string key, long value)
Stores a 64-bit integer value under the specified key.