1
0

UltrasoundImageDenoiseProcesse.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UltrasoundImageDenoiseCSLib
  4. {
  5. /// <summary>
  6. /// 超声图像降噪处理算法
  7. /// </summary>
  8. public class UltrasoundImageDenoiseProcesse
  9. {
  10. [DllImport(@"ImgDenoiseProcesse.dll", CallingConvention = CallingConvention.Cdecl)]
  11. [return: MarshalAs(UnmanagedType.I1)]
  12. private static extern bool UltrasoundImageFilter(byte[] srcImgData, byte[] dstImgData, int imgwidth, int imgheight, int channels, int radius, int threshold);
  13. /// <summary>
  14. /// 处理一幅图片
  15. /// </summary>
  16. /// <param name="srcImg">待处理的图片</param>
  17. /// <param name="dstImg">处理后的图片</param>
  18. /// <returns>处理是否成功</returns>
  19. public bool ProcesseUltrasoundImage(RawImage srcImg, RawImage dstImg, int radius, int threshold)
  20. {
  21. if (srcImg == null)
  22. {
  23. throw new NullReferenceException("SrcImage is null...");
  24. }
  25. if (dstImg == null)
  26. {
  27. throw new NullReferenceException("DstImage is null...");
  28. }
  29. if (srcImg.DataBuffer == null || srcImg.Width <= 0 || srcImg.Height <= 0 || srcImg.Channel <= 0)
  30. {
  31. throw new ArgumentException("srcImg.DataBuffer == null or srcImg.Width <= 0 or srcImg.Height <= 0 or srcImg.Channel <= 0 is false...", "SrcImage");
  32. }
  33. if (srcImg.DataBuffer.Length != srcImg.Width * srcImg.Height * srcImg.Channel)
  34. {
  35. throw new ArgumentException("srcImg.DataBuffer.Length != srcImg.Width * srcImg.Height * srcImg.Channel", "SrcImage");
  36. }
  37. if (dstImg.DataBuffer == null || dstImg.Width <= 0 || dstImg.Height <= 0 || dstImg.Channel <= 0)
  38. {
  39. throw new ArgumentException("dstImg.DataBuffer == null or dstImg.Width <= 0 or dstImg.Height <= 0 or dstImg.Channel <= 0 is false...", "DstImg");
  40. }
  41. if (dstImg.DataBuffer.Length != dstImg.Width * srcImg.Height * srcImg.Channel)
  42. {
  43. throw new ArgumentException("dstImg.DataBuffer.Length != dstImg.Width * srcImg.Height * srcImg.Channel", "DstImg");
  44. }
  45. if (dstImg.DataBuffer.Length != srcImg.DataBuffer.Length)
  46. {
  47. throw new ArgumentException("dstImg.DataBuffer.Length != srcImg.DataBuffer.Length");
  48. }
  49. bool result = UltrasoundImageFilter(srcImg.DataBuffer, dstImg.DataBuffer, srcImg.Width, srcImg.Height, srcImg.Channel, radius, threshold);
  50. return result;
  51. }
  52. }
  53. }