PDA

View Full Version : Filtering part of a frame using mask, layer and overlay


MadRat
10th October 2009, 23:05
I found this still image from the movie Bladerunner that I want to use as a wallpaper. The problem is the still is filled with noise; so I did what I could to remove the noise but that left the face was over filtered. I spent the next 8 hours trying to figure out how to use masks, layers and overlays to cut out the head, filter the background, filter the head separately then recombine it back into one image. I've gotten pretty close but there are still nasty artifacts around the outside of the mask.

Original
http://img257.imageshack.us/img257/2366/bladerunneroriginal.th.png (http://img257.imageshack.us/i/bladerunneroriginal.png/)

Mask
http://img18.imageshack.us/img18/4391/bladerunnermask.th.png (http://img18.imageshack.us/i/bladerunnermask.png/)

Script

bg=ImageSource("bladerunner-original.png").ConvertToRGB32() #load the noisy image
msk=ImageSource("bladerunner-mask.png").ConvertToRGB32() #load the image mask
msk=Mask(msk,msk) #set up the image mask
background=layer(bg,msk) #layer the image mask with the original file to create a background with a hole cut out for the head

msk2=invert(msk) #reverse the image mask
msk2=Mask(msk2,msk2) #set up the reversed image mask
head=layer(bg,msk2) #layer the image mask with the original file so that all that's seen is the head

# Massively denoise the background then sharpen
converttoyv12(background)
fft3dfilter(sigma=10,bt=4,plane=0,sharpen=1,bw=32,bh=32,ow=16,oh=16)
lsfmod()
ConvertToRGB32()
background2=last

# Denoise the head but less than the background then sharpen
converttoyv12(head)
fft3dfilter(sigma=6,bt=4,plane=0,sharpen=1,bw=32,bh=32,ow=16,oh=16)
lsfmod()
ConvertToRGB32()
head2=last

maskclip = ColorKeyMask(head2, $ffffff, 15) #make white the transparent color
Overlay(background2,head2, mask=ShowAlpha(maskclip), mode="blend", opacity=1) #put everything togehter


Obviously I'm doing something wrong. I've been reading threads and documentation all day but can't find an example that demonstrates what I want to do. Can anyone offer any help?

Keiyakusha
10th October 2009, 23:11
Well, maybe this is not really what you want, but if you want to do filtering with avisynth... how about creating 2 images. After filtering one, load both in photoshop (or gimp, or something...) and cut+overlay face from unfiltered image (using your mask or not) by just few clicks? IMHO such scripts for processing one image is way overkill...

EDIT: by the way if your image originally was in RGB, you loosing much information by doing converttoyv12(). Also I don't see much point in ConvertToRGB32() after Imagesource()

J_Darnley
10th October 2009, 23:23
What is so hard about using a mask?

source = Source()
mask = Source().ConvertToYV12(matrix="PC.601")
filtered = source.Filter()
head = source.Filter2()
Overlay(filtered, head, mask=mask)

I would recommend using a PC-range matrix when converting an image for processing. Another alternative would be to process each plane separately.

MadRat
10th October 2009, 23:49
What is so hard about using a mask?


I needed an example, thank you, J_Darnley.
Here's the working script:


source = ImageSource("bladerunner-original.png").ConvertToYV12()
mask = ImageSource("bladerunner-mask.png").ConvertToYV12()
filtered = source.fft3dfilter(sigma=10,bt=4,plane=0,sharpen=1,bw=32,bh=32,ow=16,oh=16)
head = source.fft3dfilter(sigma=6,bt=4,plane=0,sharpen=1,bw=32,bh=32,ow=16,oh=16)
Overlay(filtered, head, mask=mask)
LSFmod()


Almost forgot, after adding Dehalo_Alpha and gradfunkmirror after LSFmod this is the final image:
http://img203.imageshack.us/img203/6906/bladerunnerfinal.th.png (http://img203.imageshack.us/i/bladerunnerfinal.png/)

J_Darnley
10th October 2009, 23:58
Right, having looked again at the Overlay documentation, I see how confusing it could be.

Gavino
11th October 2009, 00:55
mask = ImageSource("bladerunner-mask.png").ConvertToYV12()
You forgot to use matrix="PC.601", recommended by J_Darnley, so your mask will have 235 for white and 16 for black.
In fact, I think you can leave out the ConvertToYV12 since Overlay will accept an RGB mask.