using System; using System.Runtime.InteropServices; namespace UltrasoundImageDenoiseCSLib { /// /// 超声图像降噪处理算法 /// public class UltrasoundImageDenoiseProcesse { [DllImport(@"ImgDenoiseProcesse.dll", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] private static extern bool UltrasoundImageFilter(byte[] srcImgData, byte[] dstImgData, int imgwidth, int imgheight, int channels, int radius, int threshold); /// /// 处理一幅图片 /// /// 待处理的图片 /// 处理后的图片 /// 处理是否成功 public bool ProcesseUltrasoundImage(RawImage srcImg, RawImage dstImg, int radius, int threshold) { if (srcImg == null) { throw new NullReferenceException("SrcImage is null..."); } if (dstImg == null) { throw new NullReferenceException("DstImage is null..."); } if (srcImg.DataBuffer == null || srcImg.Width <= 0 || srcImg.Height <= 0 || srcImg.Channel <= 0) { throw new ArgumentException("srcImg.DataBuffer == null or srcImg.Width <= 0 or srcImg.Height <= 0 or srcImg.Channel <= 0 is false...", "SrcImage"); } if (srcImg.DataBuffer.Length != srcImg.Width * srcImg.Height * srcImg.Channel) { throw new ArgumentException("srcImg.DataBuffer.Length != srcImg.Width * srcImg.Height * srcImg.Channel", "SrcImage"); } if (dstImg.DataBuffer == null || dstImg.Width <= 0 || dstImg.Height <= 0 || dstImg.Channel <= 0) { throw new ArgumentException("dstImg.DataBuffer == null or dstImg.Width <= 0 or dstImg.Height <= 0 or dstImg.Channel <= 0 is false...", "DstImg"); } if (dstImg.DataBuffer.Length != dstImg.Width * srcImg.Height * srcImg.Channel) { throw new ArgumentException("dstImg.DataBuffer.Length != dstImg.Width * srcImg.Height * srcImg.Channel", "DstImg"); } if (dstImg.DataBuffer.Length != srcImg.DataBuffer.Length) { throw new ArgumentException("dstImg.DataBuffer.Length != srcImg.DataBuffer.Length"); } bool result = UltrasoundImageFilter(srcImg.DataBuffer, dstImg.DataBuffer, srcImg.Width, srcImg.Height, srcImg.Channel, radius, threshold); return result; } } }