Log in

View Full Version : DitherPost Image Corruption


MysteryX
24th June 2016, 17:48
I have this script working fine.


ColorBarsHD(200, 200)
ResizeShader(600, 500, kernel="bicubic")


https://s32.postimg.org/rjqa84je9/Dither_Shader.png (https://postimg.org/image/rjqa84je9/)

This also works fine, which means the output of the first resize gives a valid output

ColorBarsHD(200, 200)
ResizeShader(800, 600, kernel="bicubic", lsb_out=true)
ResizeShader(600, 500, kernel="bicubic", lsb_in=true)


This one, however, severely corrupts the image!

ColorBarsHD(200, 200)
ResizeShader(600, 500, kernel="bicubic", lsb_out=true)
DitherPost(mode=6)

https://s32.postimg.org/wh3ut8ldd/Dither_Mode6.png (https://postimg.org/image/wh3ut8ldd/)

The only thing I could think about is that values outside the 16-235 range could confuse DitherPost. I added a Clamp between 50 and 200 within the shader. Some colors were gone but the weird image corruption was still there!

This is the only thing I found to work

ColorBarsHD(200, 200)
ResizeShader(600, 500, kernel="bicubic", lsb_out=true)
Dither_convert_yuv_to_rgb (matrix="709", output="rgb48y", lsb_in=true)
r = SelectEvery (3, 0)
g = SelectEvery (3, 1)
b = SelectEvery (3, 2)
Dither_convert_rgb_to_yuv (r, g, b, matrix="709", lsb=true)
DitherPost(mode=6)


Any idea on what could be causing such image corruption?

MysteryX
27th June 2016, 02:30
119 people looked at this already. Nobody has a clue on this one?

geometer
27th June 2016, 03:54
as it seems to me, that "corruption" is more like a moral judgement, first thing I would ask you - to define what you deem wrong in the result, using very specific and purely technical expressions.
second, I would anticipate the first posted picture to have 800*600px, and the second, 600*500px. the current difference is too small to be an issue to me, it just seems one has a tad brighter colors.

hello_hello
27th June 2016, 04:31
I'll confess when I looked at the images my reaction was "what corruption?" but I refrained from asking in case doing so eventually made me look silly. :)

There's a tiny difference in colour (or probably more accurately, luminance or gamma), but isn't that somewhat normal when resizing? The scripts indicate different resizing while the screenshots are the same resolution and that may have been a typo but it was too confusing for my poor brain.

MysteryX
27th June 2016, 04:33
as it seems to me, that "corruption" is more like a moral judgement, first thing I would ask you - to define what you deem wrong in the result, using very specific and purely technical expressions.
Besides the slight color distortion which you see with DitherPost(mode=0), when using mode=6, the lower part has horizontal lines screwing up the lower blocks


second, I would anticipate the first posted picture to have 800*600px, and the second, 600*500px
That a typo :) When I originally posted it, the internet went down and the whole post was lost. I retyped it quickly but that error leaked in. Fixed the scripts.

MysteryX
28th June 2016, 02:33
Curious. I tried magnifying the distortion to make it more visible. If I change brightness/constrast, or if I upscale the image in Photoshop, the distortion lines disappears. I can't make a more visible version of it.

It's most visible in the lower-right corner of the picture I posted.

raffriff42
28th June 2016, 03:22
Dither is doing exactly what it is designed to do.
Perhaps this will help - first image (https://www.dropbox.com/s/hlrata60yjk7me3/x4_Dither_Shader.png?dl=0), cropped and enlarged 4x (click to view in a new tab)

Second image (https://www.dropbox.com/s/2dsr0y1d9dgzaw9/x4_Dither_Mode6.png?dl=0), cropped and enlarged 4x.


Can't see the difference? Click here (https://www.dropbox.com/s/kidfvjcfp0pquyr/x4_Dither_Mode6_annotated.png?dl=0).

EDIT I suspect you are seeing some interaction between the dither pattern and your screen.

MysteryX
28th June 2016, 05:57
Here's a way to see the difference. Looking at the raw Stack16 data before DitherPost.


// distortion
ColorBarsHD(200, 200)
ResizeShader(600, 500, kernel="bicubic", lsb_out=true)

https://s32.postimg.org/9y06gy575/Dither_Out1.png (https://postimg.org/image/9y06gy575/)


// OK
ColorBarsHD(200, 200)
ResizeShader(600, 500, kernel="bicubic", lsb_out=true)
Dither_convert_yuv_to_rgb (matrix="709", output="rgb48y", lsb_in=true)
r = SelectEvery (3, 0)
g = SelectEvery (3, 1)
b = SelectEvery (3, 2)
Dither_convert_rgb_to_yuv (r, g, b, matrix="709", lsb=true)

https://s32.postimg.org/o5pv5lhw1/Dither_Out2.png (https://postimg.org/image/o5pv5lhw1/)

MysteryX
29th June 2016, 05:23
I suspect you are seeing some interaction between the dither pattern and your screen.
Whether that's the case or not, there shouldn't be any difference between the 2 Stack16 images posted above.

It may not be a big issue, but closing my eyes on that one can lead to other problems. I think that many C++ and especially ASM programmers around here are familiar with that truth.

geometer
29th June 2016, 05:26
What disturbs me most, is the color subsampling and the "Gibb" with it.
Frequency spectrum among the two is definitely different, the halos have different width and intensity.
The spectral transfer diagram is quite important to judge influence on noise.
E.g. after the dithering to do some filtering again is likely to have chaotic results on the appearance of the noise.

raffriff42
29th June 2016, 06:39
there shouldn't be any difference between the 2 Stack16 images posted above.Really, why? In the second image you are converting YUV>>RGB>>YUV; how can that not make a difference? You know, a very small - even invisible - change in the DitherPost'ed image can change the LSB part of the stack16 image quite a bit.

The chroma is softer in the second image, as would be expected from the extra processing. A simple bicubic resize looks slightly better (IMHO), I'm sorry to say.## "16bit bicubic"
ColorBarsHD(200, 200)
Dither_convert_8_to_16
Dither_resize16(600, 500, kernel="bicubic")
DitherPost

EDIT: Note, the images from postimg.org above seem to look worse re the problems geometer describes, than the images I get when running the scripts. I still think bicubic wins, even 8bit bicubic.

MysteryX
29th June 2016, 07:22
I'm only using Bicubic in both cases.



ColorBarsHD(200, 200)
Dither_convert_8_to_16
Dither_resize16(600, 500, kernel="bicubic")
DitherPost


This case works, even with DitherPost(mode=6)

Why would this work while doing the Bicubic via ResizeShader result in output distortion? Is it only "random luck based on subtle difference"?

EDIT: Note, the images from postimg.org above seem to look worse re the problems geometer describes, than the images I get when running the scripts. I still think bicubic wins, even 8bit bicubic.
Copy/paste the image into Photoshop and you'll see the problem instantly gets worse (??)

geometer
29th June 2016, 07:44
depending on sender and receiver software, a copy-paste is a maze of data format transformations!

MysteryX
29th June 2016, 09:22
I'm testing it again with v1.5.1 (just released) (https://github.com/mysteryx93/AviSynthShader/releases/tag/v1.5.1) and I'm not seeing the same distortion anymore. Not sure what changed.