【发布时间】:2018-11-03 15:52:26
【问题描述】:
我正在进行图像处理,需要将 RGB 位图图像转换为 YCbCr 颜色空间。我检索了每个像素的 RGB 值并将转换矩阵应用到它。
public void convertRGB (View v) {
if (imageLoaded) {
int width = inputBM.getWidth();
int height = inputBM.getHeight();
int pixel;
int alpha, red, green, blue;
int Y,Cb,Cr;
outputBM = Bitmap.createBitmap(width, height, inputBM.getConfig());
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
pixel = inputBM.getPixel(x, y);
alpha = Color.alpha(pixel);
red = Color.red(pixel);
green = Color.green(pixel);
blue = Color.blue(pixel);
Y = (int) (0.299 * red + 0.587 * green + 0.114 * blue);
Cb = (int) (128-0.169 * red-0.331 * green + 0.500 * blue);
Cr = (int) (128+0.500 * red - 0.419 * green - 0.081 * blue);
int p = (Y << 24) | (Cb << 16) | (Cr<<8);
outputBM.setPixel(x,y,p);
}
}
comImgView.setImageBitmap(outputBM);
}
}
问题是他输出的颜色与原始颜色不同。我尝试使用 BufferedImage 但它在 Android 中不起作用
原文:
转换后:
我可以知道在android java中处理YCbCr图像的正确方法是什么。
【问题讨论】: