View Single Post
Old 25th August 2013, 21:13   #12  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
Code:
smo = mt_convolution (horizontal="1 2 1", vertical="1", u=2, v=2)
It was my first attempt. It’s just a horizontal blur. The sharp vertical double lines white/black/white/black/white become something like light grey/grey/grey/grey/light grey. It hides the “double” artefact but now it looks quite blurry, the lines are thick and flat. I tried some other coefficient combinations but this one gave the most pleasing result.

Code:
dha = dehalo_alpha (ry=1)
sp1 = dha.PointResize (Width (), Height (), +1)
sm1 = dha.PointResize (Width (), Height (), -1)
shrp = mt_logic (sp1, sm1, "max").MergeChroma (last)
Second attempt. I tried to do something for the blurriness. Intuitively, you could think that overlaying two copies of the pictures, one shifted by two pixels, you could make the two replicas of the doubled lines overlap and create a stronger version of this line. This is true for the parts that overlap, but unfortunately there are also the parts that don’t overlap, and we now have a triple line! The middle line being stronger than the others. Actually this is what you obtain by replacing "1 2 1" with "1 0 1" in the first attempt.

Anyway we can notice that most of these sharp double lines are dark on a light background. We can take an advantage of this by changing the combination mode: instead of just averaging the tho pictures, we’re going to keep the lighter of them, pixel by pixel. So when both parts of the line overlap, we keep the line, and when a line overlap with a background, we keep the background.

The goal of the PointResize is to create the replicas, each shifted from one pixel to the left and to the right (so we keep the result centered). There is no actual resize, just a pixel shift. Then we combine both with mt_logic "max". But first, we try to reduce the horrible halos with dehalo_alpha(). This has a positive impact on this processing path. With the first attempt, it was not necessary, because dehalo_alpha() somewhat blurs the edges and we don’t want to go too far.

The result is still not very satisfactory, now our lines are too thin and the assumption we made caused lots of artefacts in places where it is not verified.

Code:
Merge (shrp, smo)
But when averaged, our smooth and sharp results hide each other their artefacts.

Code:
SmoothLevels (0, 1, 255, 16, 235) # Or encode it with PC-range flag
This is the code adjusting the brightness. It’s not clear if the source was PC-levels or not (probably not actually), but a Histogram() shows a large amount of pixels out of the TV-range (16–235 for the conventional black and white). Converting from PC to TV range looks much better anyway. You can probably increase the “0” of the source range to make sure the black stays black.

Code:
SeeSaw ()
Finally, we sharpen to compensate the overall blurriness. Again, you can tweak the settings to your taste.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote