android java中的图像颜色校正

时间:2013-01-20 03:31:55

标签: android image colors

我正在编写一个程序,允许用户比较2张照片,1作为样本颜色,另一个是要编辑的。我将收集第一个像素信息,然后应用以下方法编辑后者。

结果照片:http://www.flickr.com/photos/92325795@N02/8392038944/in/photostream

我的照片正在更新,尽管质量/噪音/颜色,但这里和那里有奇怪的颜色。任何人都知道我应该做什么来删除它?或者甚至更好地改进我正在使用的方法?下面是代码:

输入是要编辑的位图,inColor是要编辑的照片中鼻子的颜色,reqcolor是样本/最佳照片中我的鼻子的颜色。

public Bitmap shiftRGB(Bitmap input, int inColor, int reqColor){

    int deltaR = Color.red(reqColor) - Color.red(inColor);
    int deltaG = Color.green(reqColor) - Color.green(inColor);
    int deltaB = Color.blue(reqColor) - Color.blue(inColor);

    //--how many pixels ? --
    int w = input.getWidth();
    int h = input.getHeight();


    //-- change em all! --
    for (int i = 0 ; i < w; i++){
        for (int  j = 0 ; j < h ; j++ ){
            int pixColor = input.getPixel(i,j);

            //-- colors now ? --
            int inR = Color.red(pixColor);
            int inG = Color.green(pixColor);
            int inB = Color.blue(pixColor);

            if(inR > 255){ inR = 255;}
            if(inG > 255){ inG = 255;}
            if(inB > 255){ inB = 255;}
            if(inR < 0){ inR = 0;}
            if(inG < 0){ inG = 0;}
            if(inB < 0){ inB = 0;}

            //-- colors then --
            input.setPixel(i,j,Color.argb(255,inR + deltaR,inG + deltaG,inB           + deltaB));
        }
    }

    return input;

} 非常感谢你的帮助!我不能再表示感谢了,而是提前感谢另一位!

1 个答案:

答案 0 :(得分:1)

该功能似乎按预期工作。

但是,我注意到的一件事是,在实际设置新像素的最终输出之前,你要在“if”情况下验证边界。

        if(inR > 255){ inR = 255;}
        if(inG > 255){ inG = 255;}
        if(inB > 255){ inB = 255;}
        if(inR < 0){ inR = 0;}
        if(inG < 0){ inG = 0;}
        if(inB < 0){ inB = 0;}
        input.setPixel(i,j,Color.argb(255,inR + deltaR,inG + deltaG,inB + deltaB));

我相信这是你实际上要做的事情。

        inR += deltaR
        inG += deltaG
        inB += deltaB
        if(inR > 255){ inR = 255;}
        if(inG > 255){ inG = 255;}
        if(inB > 255){ inB = 255;}
        if(inR < 0){ inR = 0;}
        if(inG < 0){ inG = 0;}
        if(inB < 0){ inB = 0;}
        input.setPixel(i,j,Color.argb(255,inR,inG,inB));