Misery
Misery

Reputation: 689

How to transform NV21 YUV to RGB and back

I am working on an application that is supposed to work with NV21 YUV format on Android. Just for the purpose of checking what my algorithm does I need to save YUV format to RGB and then to bitmap file to take a look at it. So the algorithm I wrote for this is very simple. The program loads the bitmab RGB image converts it to NV21 and then converts it to RGB and saves to disk. I implemented the conversions given in Wikipedia YUV subject. I am using Full swing for BT.601 for RGB to YUV conversion and Y'UV420sp (NV21) to RGB conversion (Android) for RGB to YUV. However the image loses its colors. I checked my code (which is very simple unoptimized and straightforward) many times and I haven't found any error. Is there something wrong with the conversions I am using?

Input image:

enter image description here

Output image:

enter image description here

Upvotes: 0

Views: 1887

Answers (1)

kikobyte
kikobyte

Reputation: 344

Knowing nothing about your code, it is almost impossible to tell something definite.

However, the way the image is corrupted indicates that:

  1. The Luma (Y) plane was processed correctly.
  2. The Chroma (V/U interleaved, 4:2:0 subsampled) plane was processed incorrectly, moreover, all the chroma rows are the same, which usually happens when you forget to move your offsets further when processing subsequent rows. Prevalence of green tones in YUV color model often indicates you're reading in zeros for chroma planes (might be actually a garbage area).

I suggest that you double-check proper handling of U/V pointers when either converting from RGB, or to RGB. Rememer, NV21 is mixed-planar and 4:2:0 subsampled, while generic RGB (esp. if you use it for bitmap import/export) can be either planar or interleaved, but not subsampled.

Also, usually it is much easier to get a comprehensive advice if supply some code showing how do you handle things.

Upvotes: 3

Related Questions