C#裁剪图像基于单色?

时间:2015-07-04 01:38:15

标签: c# image-processing

有没有办法通过去除均匀颜色的边框来裁剪图像?

编辑:基于类似的主题,我尝试使用AForge.NET包 - 提取最大的blob,它的工作。

2

我尝试过使用所有Blob提取函数,而我得到的只是通道提取,我需要在执行绿色通道提取后执行此操作。我甚至尝试过提取黑色以防万一。这也很有用。

这是我尝试过的代码。

private void openToolStripMenuItem_Click(object sender, EventArgs e)// File-Open - Import image and show in PictureBox1
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open Image";
            dlg.Filter = "bmp files (*.bmp)|*.bmp";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                ClearCurrentImage();

                pictureBox1.Image = System.Drawing.Image.FromFile(dlg.FileName);
                ////------ AForge.NET sequence------//
                //// create filter
                //SaturationCorrection filter = new SaturationCorrection(-0.5f);
                //// apply the filter
                //filter.ApplyInPlace(image);
                ////------ AForge.NET sequence------//

                // Pass original image to the channel extract filter
                Bitmap image = new Bitmap(pictureBox1.Image);
                //Create filters
                ExtractChannel GreenChannel = new ExtractChannel(RGB.G);
                //ExtractBiggestBlob BlobGreenChannel = new ExtractBiggestBlob();
                //RotateBilinear RotateFilter = new RotateBilinear(30, true);
                Shrink Blackfilter = new Shrink(Color.Black);
                // ---------------- Apply filter ------------------//
                Bitmap ChannelImage = GreenChannel.Apply(image);
                //Bitmap BlobChannelImage = BlobGreenChannel.Apply(image);
                //Bitmap RBCImage = RotateFilter.Apply(BlobGreenChannel.Apply(GreenChannel.Apply(image)));
                //Bitmap BlobChannelImage = BlobGreenChannel.Apply(GreenChannel.Apply(image));
                //Bitmap BRBCImage = Blackfilter.Apply(RotateFilter.Apply(BlobGreenChannel.Apply(GreenChannel.Apply(image))));
                Bitmap BlackImage = Blackfilter.Apply(GreenChannel.Apply(image));
                pictureBox2.Image = BlackImage;
            }
            dlg.Dispose();
        }

我想通过裁剪掉所有黑色背景,将图像放在最小的矩形中。我怎样才能做到这一点?

0 个答案:

没有答案