예제 #1
0
        /// <summary>
        /// Extracts a channel as a Grayscale image.  Uses the <see cref="M:IArrayHandler.ExtractChannel"/> method.
        /// </summary>
        /// <param name="handler">The image upon which to operate</param>
        /// <param name="channel">The channel to extract</param>
        /// <returns>An image representation of the channel</returns>
        public static unsafe GrayscaleImage ExtractChannelAsImage(this IArrayHandler <float> handler, int channel)
        {
            float[,] buffer = handler.ExtractChannel(channel);
            int rows    = handler.Rows;
            int columns = handler.Columns;

            float[, ,] data = new float[rows, columns, 1];
            fixed(float *channelSrc = buffer, dataSrc = data)
            {
                float *channelPtr = channelSrc;
                float *dataPtr    = dataSrc;
                int    count      = rows * columns;

                while (count-- > 0)
                {
                    *dataPtr++ = *channelPtr++;
                }
            }

            GrayscaleImage gray = new GrayscaleImage();

            gray.SetData(data);
            return(gray);
        }