1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Runtime.InteropServices;
- namespace UltrasoundImageDenoiseCSLib
- {
- /// <summary>
- /// 超声图像降噪处理算法
- /// </summary>
- 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);
- /// <summary>
- /// 处理一幅图片
- /// </summary>
- /// <param name="srcImg">待处理的图片</param>
- /// <param name="dstImg">处理后的图片</param>
- /// <returns>处理是否成功</returns>
- 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;
- }
- }
- }
|