如何更改图像的颜色,但仍然可以识别对象?

时间:2010-10-23 04:56:29

标签: java android image image-processing

标题可能有点模糊,让我举个例子: 如果我们将彩色图像变成黑白,我们仍然可以识别其中的物体。 我的问题是,我可以在程序中将颜色更改为RED或GREEN或其他颜色而不是黑白颜色(我更喜欢Java)。

我想做的就像这个问题: How would I tint an image programmatically on iOS?

但是,我想在Android而不是iPhone上执行此操作。

2 个答案:

答案 0 :(得分:1)

做这样的事情

Bitmap sourceBitmap = BitmapFactory... 

float[] colorTransform = .. // read ColorMatrix docs to understand the transform
ColorMatrix colorMatrix = new ColorMatrix();

ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
Paint paint = new Paint();
paint.setColorFilter(colorFilter);         

Bitmap resultBitmap = Bitmap.createBitmap(
     sourceBitmap.getWidth(), 
     sourceBitmap.getHeight(),
     Bitmap.Config.RGB_565);

 Canvas canvas = new Canvas(resultBitmap);
 canvas.drawBitmap(sourceBitmap, 0, 0, paint);

int pixelColor=resultBitmap.getPixel(123,321);

答案 1 :(得分:0)

是的,当转换为灰度(这就是256种灰度,而不是黑白)时,你会以某种方式(取决于算法)将原始颜色的强度映射到0-255范围内的值n然后将所有像素设置为(n,n,n),这将为您提供灰色阴影,0为黑色,255为白色。 现在,如果您使用(n,0,0)代替,您将获得具有不同红色强度的图像。

(正如我写的那样,我越来越怀疑我是否理解你的问题......)