Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public static void TransformImage(Array2DBase inputImage, Array2DBase outputImage, PointTransformBase pointTransform, InterpolationTypes interpolationTypes = InterpolationTypes.Quadratic)
        {
            if (inputImage == null)
            {
                throw new ArgumentNullException(nameof(inputImage));
            }
            if (outputImage == null)
            {
                throw new ArgumentNullException(nameof(outputImage));
            }
            if (pointTransform == null)
            {
                throw new ArgumentNullException(nameof(pointTransform));
            }
            if (inputImage == outputImage)
            {
                throw new ArgumentException();
            }

            inputImage.ThrowIfDisposed(nameof(inputImage));
            outputImage.ThrowIfDisposed(nameof(outputImage));

            var inType  = inputImage.ImageType.ToNativeArray2DType();
            var outType = outputImage.ImageType.ToNativeArray2DType();
            var ret     = NativeMethods.transform_image(inType,
                                                        inputImage.NativePtr,
                                                        outType,
                                                        outputImage.NativePtr,
                                                        pointTransform.GetNativePointMappingTypes(),
                                                        pointTransform.NativePtr,
                                                        interpolationTypes.ToNativeInterpolationTypes());

            switch (ret)
            {
            case NativeMethods.ErrorType.Array2DTypeTypeNotSupport:
                throw new ArgumentException("Output or input type is not supported.");
            }
        }
Exemplo n.º 4
0
        public static void ResizeImage <T>(Matrix <T> src, Matrix <T> dst, InterpolationTypes interpolationTypes = InterpolationTypes.Bilinear)
            where T : struct
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }

            src.ThrowIfDisposed(nameof(src));
            dst.ThrowIfDisposed(nameof(dst));

            var templateRows    = (uint)src.TemplateRows;
            var templateColumns = (uint)src.TemplateColumns;

            if (templateRows != dst.TemplateRows || templateColumns != dst.TemplateColumns)
            {
                throw new ArgumentException();
            }

            var inType = src.MatrixElementType.ToNativeMatrixElementType();
            var ret    = NativeMethods.resize_image_matrix(inType,
                                                           src.NativePtr,
                                                           templateRows,
                                                           templateColumns,
                                                           dst.NativePtr,
                                                           interpolationTypes.ToNativeInterpolationTypes());

            switch (ret)
            {
            case NativeMethods.ErrorType.MatrixElementTemplateSizeNotSupport:
                throw new ArgumentException($"{nameof(src.TemplateColumns)} or {nameof(src.TemplateRows)} is not supported.");

            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{src.MatrixElementType} is not supported.");
            }
        }
Exemplo n.º 5
0
        public static void RotateImage(Array2DBase inputImage, Array2DBase outputImage, double angle, InterpolationTypes interpolationTypes = InterpolationTypes.Quadratic)
        {
            if (inputImage == null)
            {
                throw new ArgumentNullException(nameof(inputImage));
            }
            if (outputImage == null)
            {
                throw new ArgumentNullException(nameof(outputImage));
            }
            if (inputImage == outputImage)
            {
                throw new ArgumentException();
            }

            inputImage.ThrowIfDisposed(nameof(inputImage));
            outputImage.ThrowIfDisposed(nameof(outputImage));

            var inType  = inputImage.ImageType.ToNativeArray2DType();
            var outType = outputImage.ImageType.ToNativeArray2DType();
            var ret     = NativeMethods.rotate_image2(inType, inputImage.NativePtr, outType, outputImage.NativePtr, angle, interpolationTypes.ToNativeInterpolationTypes());

            switch (ret)
            {
            case NativeMethods.ErrorType.Array2DTypeTypeNotSupport:
                throw new ArgumentException("Output or input type is not supported.");
            }
        }
Exemplo n.º 6
0
        public static void ResizeImage(Array2DBase inputImage, Array2DBase outputImage, InterpolationTypes interpolationTypes = InterpolationTypes.Bilinear)
        {
            if (inputImage == null)
            {
                throw new ArgumentNullException(nameof(inputImage));
            }
            if (outputImage == null)
            {
                throw new ArgumentNullException(nameof(outputImage));
            }
            if (inputImage == outputImage)
            {
                throw new ArgumentException();
            }

            inputImage.ThrowIfDisposed(nameof(inputImage));
            outputImage.ThrowIfDisposed(nameof(outputImage));

            var inType  = inputImage.ImageType.ToNativeArray2DType();
            var outType = outputImage.ImageType.ToNativeArray2DType();
            var ret     = Native.resize_image2(inType, inputImage.NativePtr, outType, outputImage.NativePtr, interpolationTypes.ToNativeInterpolationTypes());

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

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