示例#1
0
        public static Matrix <T> ExtractImageChip <T>(MatrixBase image, ChipDetails chipLocation, InterpolationTypes type = InterpolationTypes.NearestNeighbor)
            where T : struct
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (chipLocation == null)
            {
                throw new ArgumentNullException(nameof(chipLocation));
            }

            image.ThrowIfDisposed();
            chipLocation.ThrowIfDisposed();

            if (!chipLocation.IsValid())
            {
                throw new ArgumentException($"{nameof(chipLocation)} is invalid item.");
            }

            var chip        = new Matrix <T>();
            var elementType = image.MatrixElementType.ToNativeMatrixElementType();
            var ret         = Native.extract_image_chip_matrix2(elementType,
                                                                image.NativePtr,
                                                                chipLocation.NativePtr,
                                                                chip.MatrixElementType.ToNativeMatrixElementType(),
                                                                type.ToNativeInterpolationTypes(),
                                                                chip.NativePtr);

            switch (ret)
            {
            case Native.ErrorType.InputElementTypeNotSupport:
                throw new ArgumentException($"{image.MatrixElementType} is not supported.");

            case Native.ErrorType.OutputElementTypeNotSupport:
                throw new ArgumentException($"{chip.MatrixElementType} is not supported.");
            }

            return(chip);
        }
示例#2
0
        public static Array2D <T> ExtractImageChip <T>(Array2DBase image, ChipDetails chipLocation, InterpolationTypes type = InterpolationTypes.Bilinear)
            where T : struct
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (chipLocation == null)
            {
                throw new ArgumentNullException(nameof(chipLocation));
            }

            image.ThrowIfDisposed();
            chipLocation.ThrowIfDisposed();

            if (!chipLocation.IsValid())
            {
                throw new ArgumentException($"{nameof(chipLocation)} is invalid item.");
            }

            var chip        = new Array2D <T>();
            var array2DType = image.ImageType.ToNativeArray2DType();
            var ret         = NativeMethods.extract_image_chip2(array2DType,
                                                                image.NativePtr,
                                                                chipLocation.NativePtr,
                                                                chip.ImageType.ToNativeArray2DType(),
                                                                type.ToNativeInterpolationTypes(),
                                                                chip.NativePtr);

            switch (ret)
            {
            case NativeMethods.ErrorType.Array2DTypeTypeNotSupport:
                throw new ArgumentException("Output or input type is not supported.");

            case NativeMethods.ErrorType.GeneralInvalidParameter:
                throw new ArgumentException($"{type} is not supported for {array2DType}.");
            }

            return(chip);
        }
示例#3
0
        public static Array2D <T> ExtractImageChips <T>(Array2DBase image, ChipDetails chipLocation)
            where T : struct
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (chipLocation == null)
            {
                throw new ArgumentNullException(nameof(chipLocation));
            }

            image.ThrowIfDisposed();
            chipLocation.ThrowIfDisposed();

            if (!chipLocation.IsValid())
            {
                throw new ArgumentException($"{nameof(chipLocation)} is invalid item.");
            }

            var chip        = new Array2D <T>();
            var array2DType = image.ImageType.ToNativeArray2DType();
            var ret         = Native.extract_image_chip(array2DType,
                                                        image.NativePtr,
                                                        chipLocation.NativePtr,
                                                        chip.ImageType.ToNativeArray2DType(),
                                                        chip.NativePtr);

            switch (ret)
            {
            case Native.ErrorType.InputArrayTypeNotSupport:
                throw new ArgumentException($"{image.ImageType} is not supported.");

            case Native.ErrorType.OutputArrayTypeNotSupport:
                throw new ArgumentException($"{chip.ImageType} is not supported.");
            }

            return(chip);
        }