Ejemplo n.º 1
0
 /// <summary>
 /// Extraxct wsi in full size. [Might possibly fail due to memory access violations]
 /// </summary>
 /// <param name="filename">filename of wsi</param>
 /// <returns>image as bitmap</returns>
 public static Bitmap ExtractImageFromWSIFullSize(string filename)
 {
     using (VMscope.InteropCore.ImageStreaming.IStreamingImage image = VMscope.VirtualSlideAccess.Sdk.GetImage(filename))
     {
         Console.WriteLine("Width: " + image.Size.Height + " | Width: " + image.Size.Width + " | Level: " + image.Levels);
         Bitmap bmp1 = image.GetImagePart(0, 0, image.Size.Width, image.Size.Height, image.Size.Width / 2, image.Size.Height / 2);
         //Bitmap bmp1 = image.GetGlassSlideImage();
         Console.WriteLine("Width: " + bmp1.Height + " | Width: " + bmp1.Width);
         return(bmp1);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Extract image from wsi with given resolution level.
        /// </summary>
        /// <param name="filename">wsi filename</param>
        /// <param name="resolution">resolution level (2^level)</param>
        /// <returns>whole wsi image downsampled</returns>
        public static Image <Bgr, byte> ExtractImageFromWSI(string filename, int resolution)
        {
            using (VMscope.InteropCore.ImageStreaming.IStreamingImage image = VMscope.VirtualSlideAccess.Sdk.GetImage(filename))
            {
                int    layerFactor = (int)(Math.Pow(2.0, (double)resolution));
                Bitmap bmp         = image.GetImagePart(0, 0, image.Size.Width, image.Size.Height, (int)(image.Size.Width / layerFactor), (int)(image.Size.Height / layerFactor));

                Image <Bgr, byte> m = new Image <Bgr, byte>(bmp);
                bmp.Dispose();
                return(m);
            }
        }
Ejemplo n.º 3
0
        private string SaveROIAsPNG(WSIHistoObject histoObject, int resolution)
        {
            string path = null;

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                using (VMscope.InteropCore.ImageStreaming.IStreamingImage image = VMscope.VirtualSlideAccess.Sdk.GetImage(histoObject.wsiImagePath))
                {
                    int layerFactor = (int)(Math.Pow(2.0, resolution));
                    // is bitmap loaded correctly?
                    using (Bitmap bmp = image.GetImagePart(histoObject.objRectangle.X, histoObject.objRectangle.Y, histoObject.objRectangle.Width, histoObject.objRectangle.Height, (int)(histoObject.objRectangle.Width / layerFactor), (int)(histoObject.objRectangle.Height / layerFactor)))
                    {
                        /*using(BitmapViewer viewer = new BitmapViewer(bmp))
                         * {
                         *  viewer.ShowDialog();
                         * }*/

                        // flip image so it fits the thumbnail
                        for (int k = 0; k < histoObject.NrOfRotations % 4; k++)
                        {
                            bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        }
                        if (histoObject.HorizontalFlip)
                        {
                            bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        }
                        // write image to file
                        path = Path.Combine(ApplicationContext.OutputPath, textBox1.Text, (histoObject.labelTitle.Text + ".png"));
                        bmp.Save(path, ImageFormat.Png);

                        Console.WriteLine("saved image " + histoObject.labelTitle.Text);
                        bmp.Dispose();
                    }
                    image.Dispose();
                }

                return(path);
            } catch (Exception ex)
            {
                Console.WriteLine(ex);
                MessageBox.Show(ex.Message);
                return(path);
            } finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            string path = e.Node.Name;

            if (path != null)
            {
                using (VMscope.InteropCore.ImageStreaming.IStreamingImage image = VMscope.VirtualSlideAccess.Sdk.GetImage(path))
                {
                    double ratioWidth  = (double)image.Size.Width / (double)image.Size.Height;
                    double ratioHeight = (double)image.Size.Height / (double)image.Size.Width;
                    int    newWidth    = image.Size.Width > image.Size.Height ? pictureBox1.Width : (int)(ratioWidth * pictureBox1.Width);
                    int    newHeight   = image.Size.Width > image.Size.Height ? (int)(ratioHeight * pictureBox1.Height) : pictureBox1.Height;
                    Bitmap bmp         = image.GetImagePart(0, 0, image.Size.Width, image.Size.Height, newWidth, newHeight);

                    pictureBox1.Image = bmp;
                }
            }
        }