在Java中过滤多种颜色?

在Java中过滤多种颜色?,java,colors,awt,imagej,Java,Colors,Awt,Imagej,使用ImageFilter,我们如何在Java中过滤多种颜色 在本文中 他成功地过滤了白色(RGB-255、255、255) 我想过滤相关颜色,因为我们图像的背景没有完美的白色背景-RGB(255,255,255) 对于白色,它有不同的RGB组合,如RGB(2502512555)、RGB(25325241)等 你可能不会用肉眼注意到这一点,但如果我们要使用数字色度计或任何可能检查图像的工具,我们可以注意到差异 可以过滤多种颜色吗?任何建议 提前感谢。根据您的需要,您可以通过多种方式完成此任务

使用ImageFilter,我们如何在Java中过滤多种颜色

在本文中

他成功地过滤了白色(RGB-255、255、255)

我想过滤相关颜色,因为我们图像的背景没有完美的白色背景-RGB(255,255,255)

对于白色,它有不同的RGB组合,如RGB(2502512555)、RGB(25325241)等

你可能不会用肉眼注意到这一点,但如果我们要使用数字色度计或任何可能检查图像的工具,我们可以注意到差异

可以过滤多种颜色吗?任何建议


提前感谢。

根据您的需要,您可以通过多种方式完成此任务

我建议您创建一种方法来确定需要过滤的颜色

if (filterColour(rgb)){
...
}


// method one predefine a set of colours that are near white
// suitable if you do not have too many colours or colors you want to
// filter are distinct from one another
private boolean filterColour(int rgb){
     return whiteishColours.contains(rgb);
}


//method two convert to HSV then use brightness and saturation to determine
//a zone of colours to filter
//I have not merged the components for this
private boolean filterColour(int r, int g, int b){
    float[] hsv = new float[3];
    Color.RGBtoHSB(r,g,b,hsv);
    return (hsv[2] > 0.9 && hsv.[1] < 0.1);
}
if(滤色器颜色(rgb)){
...
}
//方法一预先定义一组接近白色的颜色
//如果您没有太多颜色或您想要的颜色,则适合
//过滤器彼此不同
专用布尔过滤器颜色(int rgb){
返回白色颜色。包含(rgb);
}
//方法二转换为HSV,然后使用亮度和饱和度来确定
//要过滤的颜色区域
//我还没有为这个合并组件
私有布尔过滤器颜色(int r,int g,int b){
浮动[]hsv=新浮动[3];
颜色:RGBtoHSB(r、g、b、hsv);
回报率(hsv[2]>0.9&&hsv[1]<0.1);
}

谢谢BevynQ。我试试这个。
if (filterColour(rgb)){
...
}


// method one predefine a set of colours that are near white
// suitable if you do not have too many colours or colors you want to
// filter are distinct from one another
private boolean filterColour(int rgb){
     return whiteishColours.contains(rgb);
}


//method two convert to HSV then use brightness and saturation to determine
//a zone of colours to filter
//I have not merged the components for this
private boolean filterColour(int r, int g, int b){
    float[] hsv = new float[3];
    Color.RGBtoHSB(r,g,b,hsv);
    return (hsv[2] > 0.9 && hsv.[1] < 0.1);
}