Beispiel #1
0
        /// <summary>
        ///   Converts an image from one representation to another.
        /// </summary>
        ///
        /// <param name="input">The input image to be converted.</param>
        /// <param name="output">The converted image.</param>
        ///
        public void Convert(UnmanagedImage input, out float[][] output)
        {
            int width     = input.Width;
            int height    = input.Height;
            int pixelSize = input.PixelSize;
            int offset    = input.Offset;

            output = new float[width * height][];

            float min = (float)Min;
            float max = (float)Max;

            unsafe
            {
                byte *src = (byte *)input.ImageData.ToPointer();
                int   dst = 0;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, dst++)
                    {
                        float[] pixel = output[dst] = new float[pixelSize];
                        for (int i = pixel.Length - 1; i >= 0; i--, src++)
                        {
                            pixel[i] = Vector.Scale(*src, (byte)0, (byte)255, min, max);
                        }
                    }
                    src += offset;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///   Converts an image from one representation to another. When
        ///   converting to byte, the <see cref="Max"/> and <see cref="Min"/>
        ///   are ignored.
        /// </summary>
        ///
        /// <param name="input">The input image to be converted.</param>
        /// <param name="output">The converted image.</param>
        ///
        public void Convert(UnmanagedImage input, out float[][][] output)
        {
            int width     = input.Width;
            int height    = input.Height;
            int pixelSize = input.PixelSize;
            int offset    = input.Offset;

            output = Jagged.Zeros <float>(height, width, pixelSize);

            if (Channel != 0)
            {
                throw new InvalidOperationException("The Channel property will be ignored when converting to a rank-3 tensor.");
            }

            unsafe
            {
                byte *src = (byte *)input.ImageData.ToPointer();

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        for (int d = 0; d < pixelSize; d++, src++)
                        {
                            output[y][x][d] = (float)Vector.Scale(*src, (byte)0, (byte)255, Min, Max);
                        }
                    }
                    src += offset;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        ///   Converts an image from one representation to another.
        /// </summary>
        ///
        /// <param name="input">The input image to be converted.</param>
        /// <param name="output">The converted image.</param>
        ///
        public void Convert(UnmanagedImage input, out float[][] output)
        {
            int width     = input.Width;
            int height    = input.Height;
            int pixelSize = input.PixelSize;
            int offset    = input.Offset;

            output = Jagged.Create <float>(height, width);

            float min = (float)Min;
            float max = (float)Max;

            unsafe
            {
                byte *src = (byte *)input.ImageData.ToPointer() + Channel;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, src += pixelSize)
                    {
                        output[y][x] = Vector.Scale(*src, (byte)0, (byte)255, min, max);
                    }
                    src += offset;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        ///   Converts an image from one representation to another.
        /// </summary>
        ///
        /// <param name="input">The input image to be converted.</param>
        /// <param name="output">The converted image.</param>
        ///
        public void Convert(UnmanagedImage input, out float[,] output)
        {
            int width     = input.Width;
            int height    = input.Height;
            int pixelSize = input.PixelSize;
            int offset    = input.Offset;

            output = new float[height, width];

            float min = (float)Min;
            float max = (float)Max;

            unsafe
            {
                fixed(float *ptrData = output)
                {
                    float *dst = ptrData;
                    byte * src = (byte *)input.ImageData.ToPointer() + Channel;

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++, src += pixelSize, dst++)
                        {
                            *dst = Vector.Scale(*src, (byte)0, (byte)255, min, max);
                        }
                        src += offset;
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        ///   Converts an image from one representation to another.
        /// </summary>
        ///
        /// <param name="input">The input image to be converted.</param>
        /// <param name="output">The converted image.</param>
        ///
        public void Convert(UnmanagedImage input, out float[] output)
        {
            int width     = input.Width;
            int height    = input.Height;
            int pixelSize = input.PixelSize;
            int offset    = input.Offset;

            output = new float[width * height];

            float min = (float)Min;
            float max = (float)Max;

            unsafe
            {
                if (input.PixelFormat == PixelFormat.Format16bppGrayScale)
                {
                    short *src = (short *)input.ImageData.ToPointer();
                    int    dst = 0;

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++, dst++, src++)
                        {
                            output[dst] = Vector.Scale(*src, 0, 65535, min, max);
                        }

                        src += offset;
                    }
                }
                else
                {
                    byte *src = (byte *)input.ImageData.ToPointer() + Channel;
                    int   dst = 0;

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++, dst++, src += pixelSize)
                        {
                            output[dst] = Vector.Scale(*src, (byte)0, (byte)255, min, max);
                        }

                        src += offset;
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        ///   Converts an image from one representation to another. When
        ///   converting to byte, the <see cref="Max"/> and <see cref="Min"/>
        ///   are ignored.
        /// </summary>
        ///
        /// <param name="input">The input image to be converted.</param>
        /// <param name="output">The converted image.</param>
        ///
        public void Convert(UnmanagedImage input, out Complex[,] output)
        {
            int width     = input.Width;
            int height    = input.Height;
            int pixelSize = input.PixelSize;
            int offset    = input.Offset;

            output = new Complex[input.Height, input.Width];

            unsafe
            {
                byte *src = (byte *)input.ImageData.ToPointer() + Channel;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, src += pixelSize)
                    {
                        output[y, x] = Vector.Scale(*src, (byte)0, (byte)255, Min, Max);
                    }
                    src += offset;
                }
            }
        }