예제 #1
0
        private void AddBlobPanel(int row, Rectangle rectangle)
        {
            BlobPanel blobPanel = new BlobPanel();
            blobPanel.RowIndex = row;
            //blobPanel.Location = new Point(rectangle.X - 2, rectangle.Y - 2);
            //blobPanel.Size = new Size(rectangle.Width + 4, rectangle.Height + 4);
            rectangle.Inflate(3,3);
            blobPanel.Location = new Point(rectangle.X, rectangle.Y);
            blobPanel.Size = new Size(rectangle.Width, rectangle.Height);
            blobPanel.SelectedChanged += blobPanel_SelectedChanged;
            blobPanel.DeleteRequest += blobPanel_DeleteRequest;

            pictureBox1.Controls.Add(blobPanel);
        }
예제 #2
0
        /// <summary>
        /// Write the blob image to a text file.
        /// </summary>
        private void ExportBlob(StreamWriter sw, int key, BlobPanel blob)
        {
            // Get the blob image.
            Bitmap newImage = CropBlob(blob, pictureBox1.Image);
            WriteImageToFile(sw, key, newImage);

            // Write a rotated version.
            newImage = CropBlob(blob, pictureBox1.Image, 10);
            WriteImageToFile(sw, key, newImage);

            // Write another rotated version (to the other dir).
            newImage = CropBlob(blob, pictureBox1.Image, -10);
            WriteImageToFile(sw, key, newImage);
        }
예제 #3
0
        private Vector GetBlobPixels(BlobPanel blob)
        {
            // Get the blob image.
            Bitmap newImage = CropBlob(blob, pictureBox1.Image);

            // Create the vector (Add the bias term).
            Vector xs = new DenseVector(newImage.Width * newImage.Height + 1);
            xs[0] = 1;

            // Loop thru the image pixels and add them to the vector.
            for (int i = 0; i < newImage.Height; i++)
            {
                for (int j = 0; j < newImage.Width; j++)
                {
                    Color pixel = newImage.GetPixel(i, j);
                    xs[1 + i*newImage.Width + j] = pixel.R;
                }
            }

            return xs;
        }
예제 #4
0
        /// <summary>
        /// Crop the blob from the image
        /// </summary>
        private Bitmap CropBlob(BlobPanel blob, System.Drawing.Image source, int rotationAngel = 0)
        {
            // Create the target image, this is a squared image.
            int size = Math.Max(blob.Height, blob.Width);
            Bitmap newImage = new Bitmap(size, size, PixelFormat.Format24bppRgb);

            // Get the graphics object of the image.
            Graphics g = Graphics.FromImage(newImage);

            // Create the background color to use (the image we create is larger than the blob (as we squared it)
            // so this would be the color of the excess areas.
            Color bColor = Color.FromArgb((int)txtExtractedBackColor.Value, (int)txtExtractedBackColor.Value, (int)txtExtractedBackColor.Value);

            // Fill back color.
            g.FillRectangle(new SolidBrush(bColor), 0, 0, size, size);

            // Now we clip the blob from the PictureBox image.
            g.DrawImage(source, new Rectangle(0, 0, blob.Width, blob.Height), blob.Left, blob.Top, blob.Width, blob.Height, GraphicsUnit.Pixel);
            g.Dispose();

            if (rotationAngel != 0)
            {
                RotateBilinear filter = new RotateBilinear(rotationAngel, true);
                filter.FillColor = bColor;
                // apply the filter
                newImage = filter.Apply(newImage);
            }

            // Resize the image.
            ResizeBilinear resizefilter = new ResizeBilinear((int)txtExportSize.Value, (int)txtExportSize.Value);
            newImage = resizefilter.Apply(newImage);

            return newImage;
        }