Chroma key
Blitz3D Forums/Blitz3D Programming/Chroma key
| ||
Does anyone have a good algorithm for removing blue/green for chroma keying images. I am considering making a daft matchstick man kung-foo game,just for a bit of fun. |
| ||
I made some stuff. Its pretty simple, only the matte line may be tricky. I'd suggest to: calculate the ratio Blue vs Red and Blue vs Green if both relations are above a given ratio, you may mask the pixel v#=1.2 ratio1#=blue#/red# ratio2#=blue#/green# if (ratio1 > v) and (ratio2 > v) then ; mask it endif Personally I have added a matte line optimation that will help to reduce a greenish outline of the antialiased contour of the object, eg. if ratio is bigger than 1.0 and smaller than 1.2 then take the brightness of the foreground pixel and the colortone of the wanted background pixel (from the desired new background image) and create a new RGB value from it. |
| ||
Thanks for that JFK this is the routine that I currently use ;----------------------------------------------- Function chroma_blue_single(chroma_image$) ;----------------------------------------------- Cls SetBuffer BackBuffer() image=LoadImage(chroma_image$) DrawImage image,0,0 LockBuffer BackBuffer() For y=0 To ImageHeight(image) For x=0 To ImageWidth(image) int_rgb=ReadPixelFast (x,y) rgb_blue=getblue(int_rgb) rgb_red=GetRed(int_rgb) rgb_green=GetGreen(int_rgb) If rgb_blue-rgb_green>intensity And rgb_blue- rgb_red>intensity WritePixelFast(x,y,mask_value) EndIf Next Next UnlockBuffer BackBuffer() End Function Which is pretty much as you suggest. But I just thought that it was a bit simple and thought that there must be a much better,more effective way of doing this. Maybe this is an effective way, my results haven't been too bad. |
| ||
yeah, plain masking is simple. The tricky part is the contours, so prevent blocky contours, eg. in Chroma Keying for movies. But of course this only makes sense when you know the new background pixel, unless you store the masked image in a special format with alpha transparency for the contours: the more green a nonmasked pixel still is, the more transparent it's going to be, plus it will have to use the color tone of the background instead of its orignial greenish tone that is part of the green (masked) background. I think photoshop is doing this too when you check the "antialiase" checkbox in the lasso tool. |
| ||
Ah, see what you are gettig at there, I have noticed this effect myself. I will try and normalise the edges of the masked images to fit the background image pixels and see how this effects my final result. Thanks fo the advice |