Ejemplo n.º 1
0
        /// <summary>
        /// Performs image denoising using the Block-Matching and 3D-filtering algorithm
        /// (http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf) with several computational optimizations.Noise expected to be a gaussian white noise.
        /// </summary>
        /// <param name="src">Input 8-bit or 16-bit 1-channel image.</param>
        /// <param name="dst">Output image with the same size and type as src.</param>
        /// <param name="h">Parameter regulating filter strength. Big h value perfectly removes noise but also
        /// removes image details, smaller h value preserves details but also preserves some noise.</param>
        /// <param name="templateWindowSize">Size in pixels of the template patch that is used for block-matching. Should be power of 2.</param>
        /// <param name="searchWindowSize">Size in pixels of the window that is used to perform block-matching.
        ///  Affect performance linearly: greater searchWindowsSize - greater denoising time. Must be larger than templateWindowSize.</param>
        /// <param name="blockMatchingStep1">Block matching threshold for the first step of BM3D (hard thresholding),
        /// i.e.maximum distance for which two blocks are considered similar.Value expressed in euclidean distance.</param>
        /// <param name="blockMatchingStep2">Block matching threshold for the second step of BM3D (Wiener filtering),
        /// i.e.maximum distance for which two blocks are considered similar. Value expressed in euclidean distance.</param>
        /// <param name="groupSize">Maximum size of the 3D group for collaborative filtering.</param>
        /// <param name="slidingStep">Sliding step to process every next reference block.</param>
        /// <param name="beta">Kaiser window parameter that affects the sidelobe attenuation of the transform of the
        /// window.Kaiser window is used in order to reduce border effects.To prevent usage of the window, set beta to zero.</param>
        /// <param name="normType">Norm used to calculate distance between blocks. L2 is slower than L1 but yields more accurate results.</param>
        /// <param name="step">Step of BM3D to be executed. Allowed are only BM3D_STEP1 and BM3D_STEPALL.
        /// BM3D_STEP2 is not allowed as it requires basic estimate to be present.</param>
        /// <param name="transformType">Type of the orthogonal transform used in collaborative filtering step.
        /// Currently only Haar transform is supported.</param>
        public static void Bm3dDenoising(
            InputArray src,
            OutputArray dst,
            float h = 1,
            int templateWindowSize       = 4,
            int searchWindowSize         = 16,
            int blockMatchingStep1       = 2500,
            int blockMatchingStep2       = 400,
            int groupSize                = 8,
            int slidingStep              = 1,
            float beta                   = 2.0f,
            NormTypes normType           = NormTypes.L2,
            Bm3dSteps step               = Bm3dSteps.STEPALL,
            TransformTypes transformType = TransformTypes.HAAR)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.xphoto_bm3dDenoising2(
                    src.CvPtr, dst.CvPtr, h, templateWindowSize,
                    searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta,
                    (int)normType, (int)step, (int)transformType));

            GC.KeepAlive(src);
            dst.Fix();
        }
Ejemplo n.º 2
0
        static double ComputeNorm(double x, double y, double z, NormTypes norm)
        {
            switch (norm)
            {
            case NormTypes.C: return(Math.Max(Math.Abs(x), Math.Max(Math.Abs(y), Math.Abs(z))));

            case NormTypes.L1: return(Math.Abs(x) + Math.Abs(y) + Math.Abs(z));

            case NormTypes.L2: return(Math.Sqrt(x * x + y * y + z * z));

            case NormTypes.L2Sqr: return(x * x + y * y + z * z);

            default: throw new InvalidOperationException("The specified norm is not supported for this data type.");
            }
        }
Ejemplo n.º 3
0
        public override bool run()
        {
            bool ret = false;

            try
            {
                alpha    = (double)getValue("alpha");
                beta     = (double)getValue("beta");
                normType = (NormTypes)getValue("normType");
                dst      = src.Normalize(alpha, beta, normType, -1, null);
                ret      = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ret);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// scales and shifts array elements so that either the specified norm (alpha) 
 /// or the minimum (alpha) and maximum (beta) array values get the specified values
 /// </summary>
 /// <param name="src">The source array</param>
 /// <param name="dst">The destination array; will have the same size as src</param>
 /// <param name="alpha">The norm value to normalize to or the lower range boundary 
 /// in the case of range normalization</param>
 /// <param name="beta">The upper range boundary in the case of range normalization; 
 /// not used for norm normalization</param>
 /// <param name="normType">The normalization type</param>
 /// <param name="dtype">When the parameter is negative, 
 /// the destination array will have the same type as src, 
 /// otherwise it will have the same number of channels as src and the depth =CV_MAT_DEPTH(rtype)</param>
 /// <param name="mask">The optional operation mask</param>
 public static void Normalize( InputArray src, InputOutputArray dst, double alpha=1, double beta=0,
                      NormTypes normType=NormTypes.L2, int dtype=-1, InputArray mask=null)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.core_normalize(src.CvPtr, dst.CvPtr, alpha, beta, (int)normType, dtype, ToPtr(mask));
     GC.KeepAlive(src);
     dst.Fix();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// naive nearest neighbor finder
 /// </summary>
 /// <param name="src1"></param>
 /// <param name="src2"></param>
 /// <param name="dist"></param>
 /// <param name="dtype"></param>
 /// <param name="nidx"></param>
 /// <param name="normType"></param>
 /// <param name="k"></param>
 /// <param name="mask"></param>
 /// <param name="update"></param>
 /// <param name="crosscheck"></param>
 public static void BatchDistance(InputArray src1, InputArray src2,
                                  OutputArray dist, int dtype, OutputArray nidx,
                                  NormTypes normType = NormTypes.L2,
                                  int k = 0, InputArray mask = null,
                                  int update = 0, bool crosscheck = false)
 {
     if (src1 == null)
         throw new ArgumentNullException("src1");
     if (src2 == null)
         throw new ArgumentNullException("src2");
     if (dist == null)
         throw new ArgumentNullException("dist");
     if (nidx == null)
         throw new ArgumentNullException("nidx");
     src1.ThrowIfDisposed();
     src2.ThrowIfDisposed();
     dist.ThrowIfNotReady();
     nidx.ThrowIfNotReady();
     NativeMethods.core_batchDistance(src1.CvPtr, src2.CvPtr, dist.CvPtr, dtype, nidx.CvPtr,
         (int)normType, k, ToPtr(mask), update, crosscheck ? 1 : 0);
     GC.KeepAlive(src1);
     GC.KeepAlive(src2);
     dist.Fix();
     nidx.Fix();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// computes norm of selected part of the difference between two arrays
 /// </summary>
 /// <param name="src1">The first source array</param>
 /// <param name="src2">The second source array of the same size and the same type as src1</param>
 /// <param name="normType">Type of the norm</param>
 /// <param name="mask">The optional operation mask</param>
 /// <returns></returns>
 public static double Norm(InputArray src1, InputArray src2,
                           NormTypes normType = NormTypes.L2, InputArray mask = null)
 {
     if (src1 == null)
         throw new ArgumentNullException("src1");
     if (src2 == null)
         throw new ArgumentNullException("src2");
     src1.ThrowIfDisposed();
     src2.ThrowIfDisposed();
     var ret = NativeMethods.core_norm(src1.CvPtr, src2.CvPtr, (int)normType, ToPtr(mask));
     GC.KeepAlive(src1);
     GC.KeepAlive(src2);
     GC.KeepAlive(mask);
     return ret;
 }
Ejemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="normType"></param>
 /// <param name="crossCheck"></param>
 public BFMatcher(NormTypes normType = NormTypes.L2, bool crossCheck = false)
 {
     ptr = NativeMethods.features2d_BFMatcher_new((int)normType, crossCheck ? 1 : 0);
 }
Ejemplo n.º 8
0
 internal static extern IntPtr cv_features2d_BFMatcher_new(NormTypes normType, [MarshalAs(UnmanagedType.I1)] bool crossCheck);
Ejemplo n.º 9
0
 internal static extern double cvNorm(Arr arr1, Arr arr2, NormTypes norm_type, Arr mask);
Ejemplo n.º 10
0
 internal static extern void cvNormalize(Arr src, Arr dst, double a, double b, NormTypes norm_type, Arr mask);
Ejemplo n.º 11
0
 /// <summary>
 /// scales and shifts array elements so that either the specified norm (alpha) 
 /// or the minimum (alpha) and maximum (beta) array values get the specified values
 /// </summary>
 /// <param name="alpha">The norm value to normalize to or the lower range boundary 
 /// in the case of range normalization</param>
 /// <param name="beta">The upper range boundary in the case of range normalization; 
 /// not used for norm normalization</param>
 /// <param name="normType">The normalization type</param>
 /// <param name="dtype">When the parameter is negative, 
 /// the destination array will have the same type as src, 
 /// otherwise it will have the same number of channels as src and the depth =CV_MAT_DEPTH(rtype)</param>
 /// <param name="mask">The optional operation mask</param>
 /// <returns></returns>
 public Mat Normalize(double alpha = 1, double beta = 0,
     NormTypes normType = NormTypes.L2, int dtype = -1, InputArray mask = null)
 {
     var dst = new Mat();
     Cv2.Normalize(this, dst, alpha, beta, normType, dtype, mask);
     return dst;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// computes norm of the selected array part
 /// </summary>
 /// <param name="normType">Type of the norm</param>
 /// <param name="mask">The optional operation mask</param>
 /// <returns></returns>
 public double Norm(NormTypes normType = NormTypes.L2, InputArray mask = null)
 {
     return Cv2.Norm(this, normType, mask);
 }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="normType"></param>
 /// <param name="crossCheck"></param>
 public BFMatcher(NormTypes normType = NormTypes.L2, bool crossCheck = false)
 {
     NativeMethods.HandleException(
         NativeMethods.features2d_BFMatcher_new((int)normType, crossCheck ? 1 : 0, out ptr));
     detectorPtr = null;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BFMatcher"/> class.
        /// </summary>
        /// <param name="normType">The norm used for matching descriptors.</param>
        /// <param name="crossCheck">Specifies whether kNN matching should return only consistent pairs.</param>
        public BFMatcher(NormTypes normType = NormTypes.L2, bool crossCheck = false)
        {
            var handle = NativeMethods.cv_features2d_BFMatcher_new(normType, crossCheck);

            SetHandle(handle);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="normType"></param>
 /// <param name="crossCheck"></param>
 public BFMatcher(NormTypes normType = NormTypes.L2, bool crossCheck = false)
 {
     ptr = NativeMethods.features2d_BFMatcher_new((int) normType, crossCheck ? 1 : 0);
 }