将灰度图像转换为彩色
问题描述:
将灰度图像(1像素/字节)转换为颜色位图的最佳方式是什么? - 使用颜色空间(RGB形式的字节数组)?将灰度图像转换为彩色
我认为这会使用ColorMatrix类,但我无法弄清楚如何使用它来实现这一点。
答
该算法用于从灰色变换 - > RGB概述(在我的最爱)OpenCV文档:
RGB->灰色是R,G,B的加权和。 Gray-> RGB是Gray Value = R,G,B值的直接副本(不缩放)。
您可以使用int []并执行double for循环以将所有灰度值复制到RGB数组,然后可以使用Canvas.drawBitmap(int [],width,offset,height,offset,RGB)绘制到画布上。
//color[], gray[]
for(int y = 0; y < getHeight(); y++){
for(int x = 0; x < getWidth(); x++){
color[x+y*w] = 0xff << 24 | gray[x+y*w] << 16 | gray[x+y*w] << 8 | gray[x+y*w];
}
}
// make sure to set hasAlpha to be false, or set the 0xff value to be alpha
//canvas.drawBitmap(color, ...)
即使使用ColorMatrix calss,您也必须处理必须将GrayScale位复制到[r g b a]值。 ColorMatrix真正用于从ARGB到ARGB的缩放/转换。
你能帮我这个:http://stackoverflow.com/questions/18132772/cannot-get-the-original-colored-bitmap-after-tesseract-processing-android – TharakaNirmana 2013-08-10 08:56:27