Log in

View Full Version : Adding grain to textured areas only


opieant
18th March 2009, 02:13
I am trying to develop a method of improving the quality of one video by using a higher-quality source as a reference, but have hit a bit of a snag. I am currently using color correction (for washed-out colors), chroma shifting, edge enhancement reduction, and adding a little bit of grain with the following:


#Correct reds/blues bleeding to the right
ChromaShift(C=-2,L=0)

#Some color improvement
Tweak(hue=0,sat=1.20,bright=3,cont=0.95)

#Soften H-edges (reduce edge enhancement), sharpen V-edges
UnFilter(50,-35)

#Shave a tiny bit off of remaining enhanced edges
WarpSharp(bump=64,blur=3,depth=128)
#Again, slightly differently
aWarpSharp(cm=1,depth=8.0)

#Add a bit of grain to the whole image
AddGrain(3,0,0)

The problem I end up with is that textures such as grass, dirt, and gravel are unnaturally smooth. This is due to an unknown type of filtering that was done on the lower-quality source prior to compression, not the effects of Unfilter, WarpSharp, and aWarpSharp. Increasing the value of stddev to about 40 for AddGrain() can help to make the textured areas look more detailed in comparison to the high-quality source, but it also makes the many larger, less textured (smoother) areas far too noisy.

Is there a way to use MaskTools or something similar to apply a filter to textured areas only?

Samples of the two sources I'm comparing can be grabbed at hxxp://www.filefactory.com/file/af6b24d/n/texture_samples_zip. DGIndex and DGDecode required, cpu=4 or cpu=6 recommended for DGDecode. :)

opieant
18th March 2009, 02:19
To get the most out of the provided sample clips, you can add the following lines just after calling mpeg2source() to get progressive output:

For sample_lq:
DoubleWeave()
Trim(0,87).SelectEvery(5, 0,3)

For sample_hq:
DoubleWeave()
Trim(0,74).SelectEvery(5, 0,3)

R3Z
19th March 2009, 10:50
I hacked together a rather crude function that does what i want, ie add blurred grain to areas of little detail.

Heres the result (the difference amplified is the difference between my function and the original);

http://www.users.on.net/~inet_s51/doom9/1.jpg
Others;
http://www.users.on.net/~inet_s51/doom9/2.jpg
http://www.users.on.net/~inet_s51/doom9/3.jpg

Function and settings used;

Uses Blockbuster, AddGrain and MT_Masktools.


function DetailBasedGrain(clip source, int "BM", int "dmin", int "dmax", int "grain_str", float "blur_str1",float "blur_str2", float "sharp_str")
{
bm=default(bm,"noise") # BlockBuster Method
dmin=default(dmin,1) # Blockbuster Detail Min
dmax=default(dmax,15) # Blockbuster Detail Max
grain_str=default(grain_str,2) # Grain strength
blur_str1=default(blur_str1,1.5) # Blur Strength
blur_str2=default(blur_str2,0.75) # Blur Strength
sharp_str=default(sharp_str,1) # Sharpen Strength

grain_dist = source.BlockBuster(method=bm,detail_min=dmin,detail_max=dmax,variance=grain_str)
difference = mt_makediff(source, grain_dist, U=1, V=1)
grain_pro = difference.Blur(blur_str1).Blur(blur_str2).Sharpen(sharp_str)
mt_makediff(source,grain_pro,U=2,V=2)

return last
}

DetailBasedGrain(dmax=23,grain_str=13,blur_str2=1.5,blur_str1=1, sharp_str=.6)

Settings used for grainfactory3a just for comparisons sake;

grainfac=grainfactory3a(g1str=7, g2str=7, g3str=15)

It may be of some use, hell i will probably be ridiculed for its utterly disgracefull code :(

Cheers,

R3Z

opieant
19th March 2009, 17:38
R3Z: Thanks, I'll try to play with this later today. Looks like I may want the inverse of the mask, but otherwise it looks promising.