首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >爪哇hsb学位或255度

爪哇hsb学位或255度
EN

Stack Overflow用户
提问于 2018-04-17 18:35:05
回答 1查看 182关注 0票数 0

我想知道当您调用color.HSBtoRGB时,色调值是否会输入为0-255、0-1、0-360的范围?我是在询问,因为我试图将边缘角转换成颜色,但它只给我蓝色或紫色?有人能解释我在做什么吗?

代码语言:javascript
复制
public void sobelGrey(){
    this.greyScale();
    double edgex;
    double edgey;
    Picture pi = new Picture(this.getWidth(), this.getHeight());
    Picture tou = new Picture(this.getWidth(), this.getHeight());
    Pixel[][] Y = pi.getPixels2D();
    Pixel[][] X = tou.getPixels2D();
    Pixel[][] h = this.getPixels2D();
    for (int y = 1; y< X.length-1; y++){
        for(int x= 1; x<X[1].length-1; x++){
            edgex =
                    h[y-1][x-1].getRed() * -1 +
                            h[y][x-1].getRed()  * -2+
                            h[y+1][x-1].getRed()  * -1+
                            h[y-1][x+1].getRed() * 1 +
                            h[y][x+1].getRed()  * 2+
                            h[y+1][x+1].getRed()  * 1;
            Y[y][x].setRed((int)Math.abs(edgex/2));
            Y[y][x].setGreen((int)Math.abs(edgex/2));
            Y[y][x].setBlue((int)Math.abs(edgex/2));
        }
    }

    for (int y = 1; y< X.length-1; y++){
        for(int x= 1; x<X[1].length-1; x++){
            edgex =
                    h[y-1][x-1].getRed() * -1 +
                            h[y-1][x].getRed()  * -2+
                            h[y-1][x+1].getRed()  * -1+
                            h[y+1][x-1].getRed() * 1 +
                            h[y+1][x].getRed()  * 2+
                            h[y+1][x+1].getRed()  * 1;
            X[y][x].setRed((int)Math.abs(edgex/2));
            X[y][x].setGreen((int)Math.abs(edgex/2));
            X[y][x].setBlue((int)Math.abs(edgex/2));
        }
    }

    for (int y = 1; y< X.length-1; y++){
        for(int x= 1; x<X[1].length-1; x++){
            int x1 = (int) Math.sqrt(Math.pow(X[y][x].getRed(), 2) + Math.pow(X[y][x].getGreen(), 2) + Math.pow(X[y][x].getBlue(), 2));
            int y1 = (int) Math.sqrt(Math.pow(Y[y][x].getRed(), 2) + Math.pow(Y[y][x].getGreen(), 2) + Math.pow(Y[y][x].getBlue(), 2));
            int hr = (int) (200/(2*Math.PI)*(Math.tanh(y1/ (x1+.000000000000001))));

            int rgb = Color.HSBtoRGB(hr/255, hr, (int) Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2)));
            Color fixed = new Color(rgb&0xFF*7/10, (rgb>>8)&0xFF*80/255/10, (rgb>>16)&0xFF*4/10);
            if( !(Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2))< 40))
            h[y][x].setColor(fixed);
            else
                h[y][x].setColor(Color.black);
        }
    }
    pi.explore();
    tou.explore();
    explore();
}

我正在使用计算机科学AP图像处理从Eimacs,并使用天鹅

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-17 19:56:02

您将hr (和其他变量)声明为int。然后在Color.HSBtoRGB(hr/255, ...中,将int除以int。对于低于255的所有hr值,结果将是0

如果除以255.0,可能就足以强制进行浮点除法了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49885197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档