我有黑白图片- RGB 565,200x50。因为我可以计算出每个像素的强度0..255?
发布于 2011-07-06 21:23:22
您可以尝试使用具有一个亮度和两个色度分量的颜色模型对其进行转换。亮度分量表示亮度,而两个色度分量表示颜色。你可能想看看http://en.wikipedia.org/wiki/YUV。
否则:如果我是正确的,从灰色到黑色的白色在RGB格式中具有相同的值,每个通道具有相同的位数(例如,从(0,0,0)到(255,255,255))。假设这是真的,你可以只取其中一个通道来表示强度,因为你可以从中确定其他值。不能保证这是否有效。
编辑:我写了一个演示上述想法的代码片段。我使用的是RGB888,但在删除断言并按照注释中的说明修改像素的最大强度后,它也应该适用于RGB565。请注意,每个像素只有2^5个不同的强度级别。因此,您可能希望使用平均强度的缩放版本。
我使用来自http://www.smashingmagazine.com/2008/06/09/beautiful-black-and-white-photography/的图片对其进行了测试。我希望它能帮你把这个移植到android上。
// 2^5 for RGB 565
private static final int MAX_INTENSITY = (int) Math.pow(2, 8) - 1;
public static int calculateIntensityAverage(final BufferedImage image) {
long intensitySum = 0;
final int[] colors = image.getRGB(0, 0, image.getWidth(),
image.getHeight(), null, 0, image.getWidth());
for (int i = 0; i < colors.length; i++) {
intensitySum += intensityLevel(colors[i]);
}
final int intensityAverage = (int) (intensitySum / colors.length);
return intensityAverage;
}
public static int intensityLevel(final int color) {
// also see Color#getRed(), #getBlue() and #getGreen()
final int red = (color >> 16) & 0xFF;
final int blue = (color >> 0) & 0xFF;
final int green = (color >> 8) & 0xFF;
assert red == blue && green == blue; // doesn't hold for green in RGB 565
return MAX_INTENSITY - blue;
}
发布于 2011-07-12 22:04:40
我就是这个意思,谢谢。妈妈,这是谁能帮上忙。我得到每个像素的强度0..255,然后得到平均值。
Bitmap cropped = Bitmap.createBitmap(myImage, 503, 270,myImage.getWidth() - 955, myImage.getHeight() - 550);
Bitmap cropped2 = Bitmap.createBitmap(cropped, 0, 0,cropped.getWidth() , cropped.getHeight() / 2 );
final double GS_RED = 0.35;
final double GS_GREEN = 0.55;
final double GS_BLUE = 0.1;
int R, G, B;
int result = 0;
int g = 0;
int ff;
for(int x = 0; x < cropped2.getWidth(); x++)
{
int ff_y = 0;
for(int y = 0; y < cropped2.getHeight(); y++)
{
Pixel = cropped.getPixel(x, y);
R = Color.red(Pixel);
G = Color.green(Pixel);
B = Color.blue(Pixel);
ff = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B) ;
ff_y += ff;
}
result += ff_y;
g = result / (cropped2.getWidth()*cropped2.getHeight());
}
Toast.makeText(this, "00" + g, Toast.LENGTH_LONG).show();
https://stackoverflow.com/questions/6596623
复制相似问题