Example #1
0
        /// <summary>
        /// Convert image to color space of known stain.
        /// </summary>
        /// <param name="source">Source image.</param>
        /// <param name="stain">Known stain.</param>
        /// <param name="channel">Channel of stain. Takes int 0-2.</param>
        /// <returns>Color deconvoluted image.</returns>
        public static Bitmap ColorDeconvolution(Bitmap source, ColorDeconvolution.KnownStain stain, int channel)
        {
            using (var image = source.Clone() as Bitmap)
            {
                BitmapProcessor    bitmapProcessor    = new BitmapProcessor(source);
                ColorDeconvolution colorDeconvolution = new ColorDeconvolution();
                GrayscaleProcessor gpDeconvoluted     = null;
                if (channel == 0)
                {
                    gpDeconvoluted = colorDeconvolution.Get1stStain(bitmapProcessor, stain);
                }
                else if (channel == 1)
                {
                    gpDeconvoluted = colorDeconvolution.Get2ndStain(bitmapProcessor, stain);
                }
                else if (channel == 2)
                {
                    gpDeconvoluted = colorDeconvolution.Get3rdStain(bitmapProcessor, stain);
                }
                else
                {
                    return(null);
                }

                Bitmap result = gpDeconvoluted.Bitmap.Clone() as Bitmap;
                gpDeconvoluted.Dispose();
                return(result);
            }
        }
Example #2
0
        /// <summary>
        /// Get color channel of a known stain.
        /// </summary>
        /// <param name="image">input image</param>
        /// <param name="stain">known stain</param>
        /// <param name="channel">channel of the known stain</param>
        /// <returns>color channel</returns>
        public static UMat GetColorDeconvolutedChannelAsUMat(Bitmap image, ColorDeconvolution.KnownStain stain, int channel)
        {
            Bitmap copy   = (Bitmap)image.Clone();
            Bitmap bitmap = null;
            UMat   umat   = null;

            try
            {
                bitmap = ColorDeconvolution(copy, stain, channel);
                umat   = new Image <Gray, byte>(bitmap).ToUMat();
            } catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            } finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }

            return(umat);
        }