首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android java中的图像颜色校正

android java中的图像颜色校正
EN

Stack Overflow用户
提问于 2013-01-20 11:31:55
回答 1查看 472关注 0票数 2

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

图片来源:http://www.flickr.com/photos/92325795@N02/8392038944/in/photostream

我的照片正在更新,尽管有质量/噪音/颜色,但到处都有奇怪的颜色。有没有人知道我该怎么做才能移除它?或者更好地改进我正在使用的方法?代码如下:

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

代码语言:javascript
运行
复制
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;

}非常感谢你的帮助!我无法表达我的感激之情,只能提前说一声谢谢!

EN

回答 1

Stack Overflow用户

发布于 2013-01-20 11:54:46

该函数似乎如预期的那样工作。

然而,我注意到的一件事是,在实际设置新像素的最终输出之前,您正在使用"if“情况来验证边界。

代码语言:javascript
运行
复制
        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));

我相信这就是你真正想要做的。

代码语言:javascript
运行
复制
        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));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14421427

复制
相关文章

相似问题

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