View Full Version : Shifting Histograms
a uio
16th April 2009, 00:22
Hi,
Recently I was comparing codecs for the 100th time, and I made a surprise discovery. Some codecs shift the entire histograms of image up or down by 1-2%. Xvid and Ffdshow (trying several compressions) both exhibited clear histogram shifting. X264 and Morgan Multimedia Mj2k held the histograms in place.
I was wondering if this is well known? I expect lossy compression to lose image detail, but not to make entire red, green or blue channels lighter/darker.
Cheers,
A
Blue_MiSfit
21st April 2009, 20:05
You sure you're decoding the outputs correctly? The TV / PC levels issue is pretty well known and causes lots of issues.
~MiSfit
a uio
22nd April 2009, 00:30
You sure you're decoding the outputs correctly? The TV / PC levels issue is pretty well known and causes lots of issues.
~MiSfit
Yes. Those typically cause errors in the range of 5-6% and are easy to see. These 1% shifts are quite subtle unless you look at the histograms and toggle back and forth.
My first guess would be that there is truncation instead of rounding going on in calculations that consistently shifts all values in some direction.
benwaggoner
24th April 2009, 16:54
Hi,
Recently I was comparing codecs for the 100th time, and I made a surprise discovery. Some codecs shift the entire histograms of image up or down by 1-2%. Xvid and Ffdshow (trying several compressions) both exhibited clear histogram shifting. X264 and Morgan Multimedia Mj2k held the histograms in place.
I was wondering if this is well known? I expect lossy compression to lose image detail, but not to make entire red, green or blue channels lighter/darker.
Well, since you're comparing in RGB, you're likely comparing differences in Y'CbCr > RGB algorithms. For it to be a codec difference, you should compare the decoded YV12/IYUV output.
a uio
30th April 2009, 21:08
It might be in the YUV/RGB conversion. You could try directly comparing YV12 if you haven't done that already.
Indeed, directly encoding YV12 sources and decoding to YV12 eliminated the histogram shifting. So it seems that between VDub, Adobe Premiere, and the codecs, I'm getting different YUV/RGB conversions. If I find out more, I'll post it.
Thanks,
A
Wilbert
30th April 2009, 22:02
Like Ben said. Have a look at: http://avisynth.org/mediawiki/Colorimetry
I did some more controlled testing. Using only VirtualDub, I encoded a sample clip and then decoded it. To test the YUV conversions that were occurring inside the codecs, I set VirtualDub to output RGB24 to codecs during encoding, and to request RGB24 from codecs when decoding. The histogram shifting reappeared, in contrast to tests that directly encoded/decoded YV12 instead, where there was no shifting.
Morgan MJPEG2K, X264, and Lagarith (YV12 mode) all had no histogram shifting.
Xvid made all three RGB channels 1% darker or so.
Ffdshow Mjpg made the Red channel 1% darker or so, the Blue channel a much smaller about darker, maybe 0.2%.
To make sure this wasn't a 601/709 issue, I repeated the tests on a solid 50% gray frame. The same shifting still occurs.
I iterated the procedure for Xvid and Ffdshow, and the shifting accumulates. Xvid frames get darker with each iteration. Ffdshow frames turn green/cyan.
After five iterations, the differences are very clear to the naked eye. If anybody else cares to try these simple tests, I'd love to hear if they get similar results.
Regards,
A
a uio
13th May 2009, 19:11
Update: The issue has been confirmed by the Xvid team and was indeed a rounding problem in the RGB/YUV conversion code. A fix is in the works.
Cheers,
A
Carl Sundbom
14th May 2009, 15:04
Ah, this explains what I've been seeing too. Thought I was going crazy. Thanks for figuring this out, looking forward to the fix.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.