Beispiel #1
0
        /// <summary>
        /// Read a filter bank image from a stream.
        /// </summary>
        /// <param name="stream">The stream containing the filter bank image</param>
        /// <returns>The filter bank image</returns>
        public static unsafe FilterBankImage Read(Stream stream)
        {
            FilterBankImage image = new FilterBankImage();

            BinaryReader input    = new BinaryReader(stream);
            int          rows     = input.ReadInt32();
            int          columns  = input.ReadInt32();
            int          channels = input.ReadInt32();

            image.SetDimensions(rows, columns, channels);
            fixed(float *dataSrc = image.RawArray)
            {
                float *dataPtr = dataSrc;

                for (int r = 0; r < image.Rows; r++)
                {
                    for (int c = 0; c < image.Columns; c++)
                    {
                        for (int i = 0; i < image.Channels; i++, dataPtr++)
                        {
                            *dataPtr = input.ReadSingle();
                        }
                    }
                }
            }

            return(image);
        }
Beispiel #2
0
        /// <summary>
        /// Create a new Filter Bank Image.  The input image is run through the provided filter banks and their responses are concatenated together to form the channels of the image.
        /// </summary>
        /// <param name="input">The input image</param>
        /// <param name="filterBanks">The filter banks to apply</param>
        /// <returns>The image</returns>
        public static unsafe FilterBankImage Create(IMultichannelImage <float> input, params FilterBank[] filterBanks)
        {
            FilterBankImage image = new FilterBankImage();

            image.SetDimensions(input.Rows, input.Columns, filterBanks.Sum(o => o.DescriptorLength));
            fixed(float *dataSrc = image.RawArray)
            {
                float *dataPtr = dataSrc;

                for (short r = 0; r < input.Rows; r++)
                {
                    for (short c = 0; c < input.Columns; c++)
                    {
                        ImageDataPoint <float> point = new ImageDataPoint <float>(input, r, c, 0);
                        foreach (var fb in filterBanks)
                        {
                            float[] values = fb.Compute(point);
                            for (int i = 0; i < values.Length; i++, dataPtr++)
                            {
                                *dataPtr = values[i];
                            }
                        }
                    }
                }
            }

            return(image);
        }