Log in

View Full Version : get luma of a scan line


mathmax
25th April 2010, 05:55
Hi,

I want to get the average luma of a scan line.

I have two problems:

- AverageLuma() require that clip is in YV12. And since I convert to YV12, I cannot crop a single line because the height must be a multiple of 2 with this format.. Is there an other function to get the luma of a line of pixels?
- AverageLuma() throws an exception "invalid arguments". For example in this script:

ImageSource("image.bmp")
ConvertToYV12()
crop = crop(0,0,-0, 2)
luma = AverageLuma()

Thank you in advance for any help.

mathmax
25th April 2010, 12:50
Thank you for your answer :)

I tried this script:

ImageSource("image.bmp")
PointResize(720, 480)
ConvertToYV12()
crop = Crop(0,0,28,2)
cropLeft = crop.Crop(0,0,8,2)
cropRight = crop.Crop(20,0,8,2)
newcrop = ScriptClip(" Levels(crop, AverageLuma(cropLeft), 1, AverageLuma(cropRight), 0, 255) ")

Overlay(crop, newcrop, 0, 1)

As you can see, I would like to adjust the levels of newcrop setting the black with the average value of the 8 first pixels of "crop" and the white with the average of the 8 last pixels of "crop".
But inside ScriptClip(), Levels() seems to have no effects... I don't even know if ScriptClip() returns a clip..

Maybe there is an other fucntion to get the luma of some pixels?

Gavino
25th April 2010, 13:36
But inside ScriptClip(), Levels() seems to have no effects
A runtime script must return a clip with the same properties as its input. Here you default the input to 'last', the full-sized clip, but return a cropped-size clip, so ScriptClip will write an error message on the clip (which you can't see as you crop it down to one scanline). Also, AverageLuma returns a float, but Levels expects ints. So you need
newcrop = crop.ScriptClip("Levels(int(AverageLuma(cropLeft)), 1, int(AverageLuma(cropRight)), 0, 255)")

mathmax
25th April 2010, 14:06
Thank you. Now I'm trying to apply this script on each line of a frame..


ImageSource("MyImage.bmp")

PointResize(width, height * 2)
ConvertToYV12()

ProcessLine(last, 0)
return PointResize(width, height / 2)

function ProcessLine(c, int n)
{
crop = c.Crop(4,n*2,28,2)
cropLeft = crop.Crop(0,0,8,2)
cropRight = crop.Crop(20,0,8,2)
newcrop = ScriptClip(crop, "
black = int(AverageLuma(cropLeft)) #get the average luma of the left pixels
white = int(AverageLuma(cropRight)) #get the average luma of the right pixels

Levels(black, 1, white, 0, 255) #adjust the level to make the left real black and right real white.
")

Overlay(c, newcrop, 30, n*2)

return (n < 239) ? ProcessLine(last, n + 1) : c
}


but it doesn't work. I get this:

http://forum.videohelp.com/attachments/1528-1272199472/adjustedge.jpg