Log in

View Full Version : Sharpener Testing Script


mikeytown2
28th January 2009, 10:42
After watching this video here (Skip to about 19 Min in, the rest of it is kinda boring...)
http://meetthegimp.org/episode-085-geeks-only-really/
I decided to replicate this using the files provided via this link
http://simplefilter.de/en/analysis/contrast.html
http://simplefilter.de/download/SF_Contrast_Testkit_RGY.zip

Run Script Below and have fun testing various AviSynth sharpeners!

#Number of pixels In (1-5)
pixels = 5


#Don't Change
colors = 256
depth = pixels*2-1
#Gray Bars
BlankClip(1,colors,colors*depth,"YV12",25, color=$000000)
base = mt_lutspa(false, mt_polish("(x%2)?127-(x/2):128+(x/2)"), U=-128, V=-128).PointResize(width*depth, height)
#Gradient
gradient_mask = base.GraMaMa(4, 0, colors*depth, 0, colors*depth)
#Blank Clip
BlankClip(1,colors*depth,colors*depth,"YV12",25, color=$000000)
blank=last
#Red Channel
mtString_red = (depth==3) ? mt_polish("(x%3==0)?255:(x%3==2)?255:0") : \
(depth==5) ? mt_polish("(x%5==0)?255:(x%5==2)?255:(x%5==4)?255:0") : \
(depth==7) ? mt_polish("(x%7==0)?255:(x%7==2)?255:(x%7==4)?255:(x%7==6)?255:0") : \
(depth==9) ? mt_polish("(x%9==0)?255:(x%9==2)?255:(x%9==4)?255:(x%9==6)?255:(x%9==8)?255:0") : \
mt_polish("0")
red = mt_lutspa(false, mtString_red, U=-128, V=-128)
#Green Channel
mtString_green = (depth==3) ? mt_polish("(x%3==1)?255:0") : \
(depth==5) ? mt_polish("(x%5==1)?255:(x%5==2)?255:(x%5==3)?255:0") : \
(depth==7) ? mt_polish("(x%7==1)?255:(x%7==2)?255:(x%7==3)?255:(x%7==4)?255:(x%7==5)?255:0") : \
(depth==9) ? mt_polish("(x%9==1)?255:(x%9==2)?255:(x%9==3)?255:(x%9==5)?255:(x%9==6)?255:(x%9==7)?255:0") : \
mt_polish("0")
green = mt_lutspa(false, mtString_green, U=-128, V=-128)
#Blue Channel
mtString_blue = (depth==7) ? mt_polish("(x%7==3)?255:0") : \
(depth==9) ? mt_polish("(x%9==3)?255:(x%9==4)?255:(x%9==5)?255:0") : \
mt_polish("0")
blue = mt_lutspa(false, mtString_blue, U=-128, V=-128)
#RGB Channel - Color Mask
rgy_color_mask = MergeRGB(red, green, blue)

base
##########################
#Test Your Sharpener Here#
##########################
LimitedSharpenFaster()

##########################
#End of Sharpener Area #
##########################
Overlay(last, gradient_mask, mode="difference", pc_range=true)
Levels(129,128,0,0,255,false)
(Depth==1) ? last : Overlay(rgy_color_mask, last, mode="multiply", pc_range=true)

PointResize(width,512).Spline64Resize(512,512).Levels(0,4,255,0,255)

GraMaMa() - http://www.geocities.com/wilbertdijkhof/
mt_***() - http://avisynth.org/mediawiki/MaskTools2

Here's LSF Output (yes it's not all black - click on the thumbnail)
http://img217.imageshack.us/img217/5241/lsfni9.th.png (http://img217.imageshack.us/my.php?image=lsfni9.png)

EDIT:
Use this to test about any function... DeHalo, Resize, Blur, ect...

EDIT:
Thanks J_Darnley for using masktools!

EDIT:
Using Better Colors -Cyan & Magenta
Better resize for high pixel count - Easier to read, still gets the idea across.

*.mp4 guy
28th January 2009, 13:10
try lsf with:

limitedsharpenfaster(smode=4, ss_y=1, ss_x=1, overshoot=0, strength=80)

That should more accurately reflect the performance of limitedsharpen's underlying principles.

I would like to play around with this, but I have an old version of the GIMp which won't wok with that stuff, and I'm not willing to update it.

J_Darnley
28th January 2009, 13:44
I think you could generate them with some mt_lutspa and MergeRGB
rgycolourmask goes: red, green, yellow, green, red, repeat

To generate testimage:
mtString = mt_polish("(x%2)?127-(x/2):128+(x/2)")
mt_lutspa(false, mtString, U=-128, V=-128)
PointResize(width*5, height)
With mt_lutspa getting a 256px wide video gets you all of testimage (height doesn't really matter for vertical stripes).

To generate rgycolourmask:
mtString_red = mt_polish("(x%5==0)?255:(x%5==2)?255:(x%5==4)?255:0")
red = mt_lutspa(false, mtString_red, U=-128, V=-128)

mtString_green = mt_polish("(x%5==1)?255:(x%5==2)?255:(x%5==3)?255:0")
green = mt_lutspa(false, mtString_green, U=-128, V=-128)

MergeRGB(red, green, blank)

P.S. *.mp4 guy, do you mean you can't open the image with gimp or are some of the features used missing from your version?
And here is your lsf suggestion: http://users.telenet.be/darnley/avisynth/test-lsf-1.png

And so for completeness:
BlankClip(1500,256,1280,"YV12",25, color=$000000)
base = mt_lutspa(false, mt_polish("(x%2)?127-(x/2):128+(x/2)"), U=-128, V=-128).PointResize(width*5, height)

gradient_mask = base.GraMaMa(4, 0, 1280, 0, 1280)

BlankClip(1500,1280,1280,"YV12",25, color=$000000)
mtString_red = mt_polish("(x%5==0)?255:(x%5==2)?255:(x%5==4)?255:0")
red = mt_lutspa(false, mtString_red, U=-128, V=-128)
mtString_green = mt_polish("(x%5==1)?255:(x%5==2)?255:(x%5==3)?255:0")
green = mt_lutspa(false, mtString_green, U=-128, V=-128)
rgy_color_mask = MergeRGB(red, green, last)

base
#Test Your Sharpener Here
limitedsharpenfaster(smode=4, ss_y=1, ss_x=1, overshoot=0, strength=80)

Overlay(last, gradient_mask, mode="difference", pc_range=true)
Levels(129,128,0,0,255,false)
Overlay(rgy_color_mask, last, mode="multiply", pc_range=true)

*.mp4 guy
28th January 2009, 15:05
It opens, but there is no way for me to select the layers. Thanks for your help, I was able to test lsf with the settings I suggested, and it indeed, does nothing.

mikeytown2
1st February 2009, 11:09
@J_Darnley
Nice Work! Going to play around with MaskTools now... :)

EDIT: Done playing ;) check the first post.
Sorta generalized it.

level 5 - RGYCMCYGR
level 4 - RGYCYGR
level 3 - RGYGR
level 2 - RGR
level 1 - W

MadRat
2nd February 2009, 02:09
Thanks mikeytown2, this is just what I was looking for.

Jeremy Duncan
2nd February 2009, 06:16
I caN get the patten and put a sharpener in there, but I can't be multiple colored lines in there and I don't know what those colored lines represent.
i tried to get it going to colored lines for close to a hour now and I'm tired and need to rest.

:)

mikeytown2
2nd February 2009, 09:19
2 Things that are important:

Imputing the test code in the right place
Knowing what the colored lines mean & the Pixel Level


1.
thats the easy part :)

2.
level _n_ - The "radius/width" of the vertical lines is _n_px.
M=Magenta
R=Red
G=Green
Y=Yellow
C=Cyan

level 1 - M
level 2 - RGR
level 3 - RGYGR
level 4 - RGYCYGR
level 5 - RGYCMCYGR

So Level 2 the test "pattern" is a total of 3px wide, level 3 is 5px wide.

At Level 5: (9px wide)
Red: first pixel on either side, right on the edge. -Edge Sharpness/Contrast
Green: second pixel in from the edge. - Edge Sharpness/Halo
Yellow: third pixel in from the edge. - Halo/Edge Sharpness
Cyan: forth pixel in from the edge. - Halo
Magenta: fifth pixel in from the edge. - Halo
It lets you know how deep in from the edge the sharpener works. The more advanced/potentially stronger ones reach deeper into the stack. Example: if the Yellow line is more vertical then the Red line, then you get halos (means the center's contrast is increasing more then the edge).


The more vertical the line is, it's more sharp. The more horizontal the line is, it's less sharp. 45 degree angle is untouched - "generally" what u want deeper in the stack: less halos in general. Watch the video (on the first post) in it's entirety if you still have questions... or play around by giving this script different inputs. Also disable the Levels() and/or the last Overlay() to play see this before mid stream.

An Interesting Example is SeeSaw - It effects all levels.
a=FFT3DFilter(10)
SeeSaw(last,a)

Didée
2nd February 2009, 10:01
IMO it's mostly a waste of time. If you know your filter, then this method shows you what you already knew beforehand. If you don't know your filter, there's not much information to derive from the result.

Short of exhaustive elaboration, a few small examples:

RemoveGrain(4), XSharpen(255,255), LimitedSharpen(ss_x/x=1.0,overshoot=0) all (should) give the same result: zero change.
Same for SeeSaw: vanilla SeeSaw should give a zero result. In the above example with SeeSaw(+FFT3DFilter), you're actually measuring the effect of FFT3DFilter, not of SeeSaw.

Whether there is overshoot or not has not much to say per se. Sharpness/contrast are partly correlated. Which kind of change is useful/wishful and which are not, that's a tricky decision to make. With a method as simple as this one (in regard to the test pattern), you won't get behind the lines.

The way of generating the displayed result is nice by itself.
Alas, the result is not interesting.

"Much ado about nothing".

mikeytown2
2nd February 2009, 10:21
@Didée
You are correct, it's mainly pointless. :p

So I came up with a more interesting example showing the degradation of an image. I also updated the function... output is more user friendly in my opinion.

Blur(1)
http://img57.imageshack.us/img57/1186/56115152jg5.png

Blur(1).Sharpen(1)
http://img57.imageshack.us/img57/1391/71681050my9.png

Blur(1).Sharpen(1).Blur(1)
http://img266.imageshack.us/img266/2011/49524371yv5.png

Blur(1).Sharpen(1).Blur(1).Sharpen(1)
http://img530.imageshack.us/img530/4268/91256470ur4.png