Beispiel #1
0
        private void AddObjectsFromContours(Image <Bgr, Byte> image, List <Rectangle> contours, string wsi_path, int resolution_level)
        {
            // order bboxes from top to button / left to right (horizontal descending)
            if (this.horizontal == true && this.descending == true)
            {
                // sort by x coordinate
                contours.Sort((x, y) => x.Left.CompareTo(y.Left));
                // than sort by y coordinate
                contours.Sort((x, y) => x.Top.CompareTo(y.Top));
            }
            if (this.horizontal == true && this.descending == false)
            {
                contours.Sort((x, y) => x.Left.CompareTo(y.Left));
                contours.Sort((x, y) => y.Top.CompareTo(x.Top));
            }
            if (this.horizontal == false && this.descending == true)
            {
                contours.Sort((x, y) => y.Left.CompareTo(x.Left));
                contours.Sort((x, y) => x.Top.CompareTo(y.Top));
            }
            if (this.horizontal == true && this.descending == false)
            {
                contours.Sort((x, y) => y.Left.CompareTo(x.Left));
                contours.Sort((x, y) => y.Top.CompareTo(x.Top));
            }

            for (int j = 0; j < contours.Count; j++)
            {
                Rectangle      contour = contours[j];
                WSIHistoObject obj     = new WSIHistoObject();

                using (Image <Bgr, Byte> subimage = image.Copy(new Rectangle(contour.Left, contour.Top, contour.Width, contour.Height)))
                {
                    obj.PictureBox_SetImage(subimage.Bitmap, resolution_level);
                }

                int layerFactor = (int)(Math.Pow(2.0, (double)resolution_level));
                obj.objRectangle          = new Rectangle(contour.X * layerFactor, contour.Y * layerFactor, contour.Width * layerFactor, contour.Height * layerFactor);
                obj.wsiImagePath          = wsi_path;
                obj.labelTitle.Text       = System.IO.Path.GetFileNameWithoutExtension(wsi_path) + "_" + j.ToString();
                obj.AllowDrop             = true;
                obj.DragDrop             += new System.Windows.Forms.DragEventHandler(this.wsiHistoObject_DragDrop);
                obj.DragOver             += new System.Windows.Forms.DragEventHandler(this.wsiHistoObject_DragOver);
                obj.MouseDown            += new System.Windows.Forms.MouseEventHandler(this.wsiHistoObject_MouseDown);
                obj.labelTitle.DragDrop  += new System.Windows.Forms.DragEventHandler(this.wsiHistoObjectChild_DragDrop);
                obj.labelTitle.DragOver  += new System.Windows.Forms.DragEventHandler(this.wsiHistoObjectChild_DragOver);
                obj.labelTitle.MouseDown += new System.Windows.Forms.MouseEventHandler(this.wsiHistoObjectChild_MouseDown);
                obj.PictureBox_AddDragDropHandler(new System.Windows.Forms.DragEventHandler(this.wsiHistoObjectChild_DragDrop));
                obj.PictureBox_AddDragOverHandler(new System.Windows.Forms.DragEventHandler(this.wsiHistoObjectChild_DragOver));
                obj.PictureBox_AddMouseDownHandler(new System.Windows.Forms.MouseEventHandler(this.wsiHistoObjectChild_MouseDown));
                obj.buttonRemove.MouseDown += new System.Windows.Forms.MouseEventHandler(this.wsiHistoObject_ButtonRem_Click);

                objects.Add(obj);
                this.panel1.Controls.Add(obj);
            }
        }
Beispiel #2
0
        private void buttonCreateStack_Click(object sender, EventArgs e)
        {
            Directory.CreateDirectory(Path.Combine(ApplicationContext.OutputPath, textBox1.Text));
            for (int i = 0; i < objects.Count; i++)
            {
                WSIHistoObject obj = objects[i];
                SaveROIAsPNG(obj, (int)numericUpDown1.Value);
            }

            WriteStackV2((int)numericUpDown1.Value);
        }
Beispiel #3
0
        private void wsiHistoObject_ButtonRem_Click(object sender, MouseEventArgs e)
        {
            // remove object from form and objects list
            WSIHistoObject obj = (WSIHistoObject)((Button)sender).Parent;

            panel1.Controls.Remove(obj);
            objects.Remove(obj);
            EnableButtons();
            // repaint form so the control disappears
            this.Invalidate();
        }
Beispiel #4
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;
            }
        }
Beispiel #5
0
        private void wsiHistoObject_DragDrop(object sender, DragEventArgs e)
        {
            // get index of the target object
            int index = objects.IndexOf((WSIHistoObject)sender);

            if (index < 0)
            {
                index = objects.Count - 1;
            }
            WSIHistoObject data = (WSIHistoObject)e.Data.GetData(typeof(WSIHistoObject));

            // move source object to target position
            objects.Remove(data);
            objects.Insert(index, data);
            // repaint form so rearangement becomes visible
            this.Invalidate();
        }
Beispiel #6
0
        private void buttonProceed_Click(object sender, EventArgs e)
        {
            List <string> toRegistrate = new List <string>();

            Directory.CreateDirectory(Path.Combine(ApplicationContext.OutputPath, textBox1.Text));
            for (int i = 0; i < objects.Count; i++)
            {
                WSIHistoObject obj = objects[i];
                toRegistrate.Add(SaveROIAsPNG(obj, (int)numericUpDown1.Value));
            }

            WriteStackV2((int)numericUpDown1.Value);

            this.Hide();
            using (RegistrationForm form = new RegistrationForm(toRegistrate))
            {
                form.ShowDialog();
            }
            this.Close();
        }