Page 1 of 1
[solved] Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T08:23:40-07:00
by LDAsh
After a couple of hours of sifting through documentation, I'm still no closer to solving this...
I would like to take a greyscale image (256 colours), convert it to 16bit-per-channel (65536 colour greyscale), apply some blur, and then convert it back to a 256-colour image with dithering techniques. The purpose is to solve as much banding as possible in 24bit images.
I've looked at a bunch of different software to do this, including GIMP, and so far none seem up to the task.
Searching around forums, people have thrown a vague mention to ImageMagick, but not actually provided useful details, as usual.
I might be after "convert -depth 48"? but the documentation doesn't seem to explain how it works.
My attempts to convert to png48 format are failing, either because my command-line is wrong or my system won't allow it.
Code: Select all
convert image24.png -format png48 -define png:bit-depth=48 image48.png
Re: Convert to 16bit-channel before operations and back again
Posted: 2018-04-22T08:52:36-07:00
by snibgo
What version of IM are you using? What does "convert -version" say? If you are using Q16, then conversion from any input to 16 bits/channel is automatic, and blurring will be in 16-bit. By default, output depth will be the same as the input, but you can use "-depth 8" or "-depth 16" to force a certain depth.
Code: Select all
convert in.png -blur 0x3 -depth 16 out.png
Note that IM's "-depth" is the bits per channel per pixel, not the total bits per pixel.
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T10:06:06-07:00
by LDAsh
So I really messed up on the command-line AND I was using the wrong version of ImageMagick!
Now I have success in getting to 48bit and applying operations, even though I can't see it on these systems, but I'm now having trouble getting back to an 8bit grayscale with nice dithering.
To clarify, I'm starting with an 8bit grayscale with a chunky amount of banding, and I'm trying resize it up and blur it at 48bit, and then resample and dither to roughly the same resolution, if not higher, depending on the results. Like this:-
The image is just a 1024x512 grayscale linear gradient, so that's 4-pixel wide banding, but at 65536 colours I should be able to get away with 2048 or even possibly 4096 with that kind of dithering, but I'm still getting the same banding after this BAT:-
Code: Select all
convert image24.png -define png:format=png48 -resize 3072x1536 image48.png
convert image48.png -blur 0x3 -depth 16 image48b.png
convert image48b.png -dither Floyd-Steinberg -resize 1024x512 image48b.gif
I tried playing with "dither-method" and searched around for more control over dithering, but no matter what I try I still get banding identical to how it started. I'm back into a state of confusion about how to acheive the kind of dithering results in the pic posted above at 2K or 4K resolutions.
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T10:08:17-07:00
by snibgo
What version of IM are you using? What does "convert -version" say?
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T10:15:08-07:00
by LDAsh
Version: ImageMagick 7.0.1-5 Q16 x64 2016-05-18
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T10:26:21-07:00
by snibgo
For v7, I suggest you use "magick", not "convert", though this may make no difference.
v7.0.1 was very early in the 7 series and rather buggy. I suggest you upgrade to the current version.
"-dither" sets the dither method that will be used for certain operations like "-colors N". It doesn't affect "-resize", so your "-dither" has no effect.
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T10:47:54-07:00
by LDAsh
Thanks for the replies!
So I uninstalled/reinstalled everything and now it's "Version: ImageMagick 7.0.7-28 Q16 x64 2018-03-25"
And so now my BAT file looks like this:-
Code: Select all
magick image24.png -define png:format=png48 -resize 3072x6144 image48.png
magick image48.png -blur 0x3 -depth 16 image48b.png
magick image48b.png -define png:format=png24 -resize 1024x2048 image48z.png
magick image48z.png -colors 256 -dither Floyd-Steinberg image48z.gif
Still the same banding as it started, though, so the GIF is identical to the original PNG.
Could it be that it's just not blurring or the blur is not strong enough, so there's nothing for the dithering to do?
Or I should be dithering before resizing? In my mind, it should be part of the same operation, the resizing and the dithering.
Or, even though it says it's a 48bit PNG (which I verified), the blur is not operating on 16bit channel, only 8bit still...
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T11:18:38-07:00
by snibgo
I don't know why you have four commands instead of one.
Blurring by 0x3 then shrinking to one-third size will remove almost all the effect of the blur. Try a much larger blur, eg "-blur 0x30".
Your "-dither" setting is not followed by any operation affected by that setting. So, again, your "-dither" has no effect.
By default, dithering is on, using the Riemersma method. So your "-colors" will use dithering. But the dithering may not be noticeable with so many colours, especially if your image is grayscale. Try a much smaller number, eg "-colors 6".
Re: Convert to 16bit-channel before blur & resize/dither
Posted: 2018-04-22T12:01:10-07:00
by LDAsh
Hey-yey!!! I did it. So I actually had to change "-colors 256" to "-colors 255", because 256 seemed to break it. (*should be documented)
I also reorganised a couple of things, like you mentioned about the dithering, but now wonderfully it works:-
Code: Select all
magick image24.png -define png:format=png48 -resize 4096x2048 image48.png
magick image48.png -blur 0x9 -depth 16 image48b.png
magick image48b.png -dither Riemersma -colors 255 image48x.png
magick image48x.png -define png:format=png24 -resize 2048x1024 image48z.png
And here's the result:-
(exaggerated):-