PDA

View Full Version : Auto Detect Greyscale


Jeff Mott
23rd September 2004, 03:28
I'm trying to figure out how I would detect if a picture is greyscale or not. I've tried things like

orig = last
grey = Greyscale(orig)
Compare(grey,orig,"YUV",compare.log)

But this will still show a perfect match between the two. Can somone recommend some other method?

Manao
23rd September 2004, 07:14
source.YV12LUT(yexpr = "0", uexpr = "x 128 - 256 *", vexpr = "x 128 - 256 *", y=3, u=3, v=3)This will show a black picture if the U and V are exactly 128, else it will show a colored picture ( either blue, red or dark pink ).

However, the U and V levels may differ slightly from 128 ( for example after a RGB greyscale -> YUV conversion ) and the picture still being greyscale.

So you can loose the condition and U and V, and for example wanting them only in the range 126..130 :
source.YV12LUT(yexpr = "0", uexpr = "x 126 < 255 x 130 > 255 0 ? ?", \
vexpr = "x 126 < 255 x 130 > 255 0 ? ?", y=3, u=3, v=3)

sh0dan
23rd September 2004, 08:36
In conditional filters (Assuming YUV):
v = last
v_grey = v.greyscale()
conditionalfilter(v,v_grey, v, "ChromaUDifference(v, v_grey)+ChromaVDifference(v, v_grey)", "<", "1.0", show=true)

This compares the average difference between a frame and it's greyscale version. If the difference is less than 1.0 (on average) the greyscale version is choosen.

Jeff Mott
25th September 2004, 06:29
Ok, this sorta does what I need. I guess I should give more specific details about the problem to get more specific details about the answer. ;)

If anyone has ever seen American History X or Pleasantville, just to name a couple, you'd know that parts of each film is black and white while others are full color. I can use XviD's zones and greyscale encoding to take full advantage of this aspect of the video, but I don't want to manually scan the film trying to find all black and white scenes. I would, somehow, like AviSynth to be able to 1) detect which frames are already greyscale or not, and 2) report these frame ranges back to me.

tsp
25th September 2004, 10:28
something like this:


logfile="c:\greyscale.txt"
v = last
v_grey = v.greyscale()
Writefileif(logfile, "(ChromaUDifference(v, v_grey)+ChromaVDifference(v, v_grey))<1.0","current_frame")


This script will make a file called greyscale.txt with the framenumbers of the frames detected as greyscale

Jeff Mott
25th September 2004, 17:09
Sweet. Thanks :D

I had to adjust the threshold a little bit, but otherwise perfect.