如何在 c# 中使用欧几里得颜色过滤?我在 => 过滤器中有错误。CenterColor = Color.FromArgb(215, 30, 30);



图像处理过滤器过滤像素,其颜色在具有指定中心和半径的RGB球体内/外-它保留具有指定球体内/外颜色的像素,并使用指定颜色填充其余像素

using System;
using System.Collections.Generic;
using System.ComponentModel; 
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Design;
using AForge.Imaging.Filters;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    Bitmap img, img2;
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Clearing previously selected image from picture box
            pictureBox1.Image = null;
            openFileDialog1.FileName = "";
            openFileDialog1.Title = "Images";
            openFileDialog1.Filter = "All Images|*.jpg; *.bmp; *.png";
            openFileDialog1.ShowDialog();
            if (openFileDialog1.FileName.ToString() != "")
            {
                pictureBox1.ImageLocation = openFileDialog1.FileName.ToString();
            }
            img = new Bitmap(openFileDialog1.FileName.ToString());
        }
        catch (Exception ex)
        {
            MessageBox.Show("Browse the image...");
        }
    }
    private void button2_Click(object sender, EventArgs e)
    {
        // create filter
        EuclideanColorFiltering filter = new EuclideanColorFiltering();
        // set center colol and radius
        filter.CenterColor = Color.FromArgb(215, 30, 30);
        filter.Radius = 100;
        // apply the filter
        filter.ApplyInPlace(img);

        pictureBox2.Image = img;
    }
}

}

// I have got error in "filter.CenterColor = Color.FromArgb(215, 30, 30);"  this line
please help me..

ARGB颜色由4个通道定义:alpha(不透明度),红色,绿色和蓝色。

所以你可以使用Color。from mrgb 如果存在,或者Color。

第一个参数(alpha)为255。

你必须注意到,它是一个forge库过滤器。这不是使用System.Drawing.Color中的Color,而是使用Aforge库中的RGB()。你可以简单地使用新的RGB(颜色)来修复这个错误。例如:

filter.CenterColor = new RGB(Color.FromArgb(215, 30, 30));

在AForge中有RGB()的定义。成像类。

如果你想用int这样的属性来改变半径,你必须记住,filter.Radius只允许使用short(不是int)从0到450。然后只在int上使用Convert.ToInt16,就完成了。

祝你好运

// create filter
EuclideanColorFiltering filter = new EuclideanColorFiltering( );
// set center colol and radius
filter.CenterColor = new RGB( 215, 30, 30 );
filter.Radius = 100;
// apply the filter
filter.ApplyInPlace( image );
Bitmap d =new Bitmap(ofile.FileName);
for (int i = 0; i < d.Width; i++)
for (int j = 0; j < d.Height; j++)
{
                    Color C1 = d.GetPixel(i, j);
                    int r2 = C1.R;
                    int g2 = C1.G;
                    int b2 = C1.B;
                    int red = (byte)(.238 * r2 + .16 * g2 + .16 * b2);
                    r2 = red;
                    g2 = red;
                    b2 = red;
                    d.SetPixel(i, j, Color.FromArgb(r2, g2, b2));
                }

最新更新