Page 1 of 1

scaling down to 120x90px Gray with less ringing

Posted: 2019-09-14T17:41:51-07:00
by FlorinAndrei
I'm training a TensorFlow model to recognize some natural objects. To generate the training data, I'm taking lots of pictures with a pretty good camera at 4000x3000 px resolution, full color. I need to scale these down to 120x90 px 8-bit grayscale. I'm using ImageMagick 6.9.7 on Linux.

"convert -resize 120x90" works well, but there are some ringing artifacts around sharp edges. I've tried this instead (found it on a forum somewhere after a Google search):

Code: Select all

find images/original/* | cut -d / -f 3 | parallel \
    convert images/original/{} -colorspace RGB +sigmoidal-contrast 6.5,50% \
        -filter Lanczos -distort resize 120x90 \
        -sigmoidal-contrast 6.5,50% -colorspace Gray images/small/{}.png
It's perhaps a little better, but there is still some ringing. See here:

Image

There's still pretty obvious ringing around the person and the telegraph pole.

Is there a better way? Can I reduce ringing even further?

The goal is to create tiny images as close as possible to the "look" of the originals (while discarding lots of resolution and all of color data). The neural network will learn how the world looks like from these images, and I don't want to train it with ringing artifacts.

Re: scaling down to 120x90px Gray with less ringing

Posted: 2019-09-14T17:48:33-07:00
by fmw42
See the discussion by Nicolas Robidoux who came up with the method you have found. See https://imagemagick.org/Usage/filter/nicolas/. He has other filter besides plain lanczos that you might try. The short answer is perhaps trade blurring for ringing by adjusting the resample blur amount with -define filter:blur=X

Re: scaling down to 120x90px Gray with less ringing

Posted: 2019-09-14T18:31:49-07:00
by FlorinAndrei
There's a lot of information on that page, but I'm parsing it. Thank you. Already I've found a combination that's much better:

Code: Select all

find images/original/* | cut -d / -f 3 | parallel \
  convert images/original/{} -colorspace Gray \
    -filter Triangle -resize 120x90 \
    images/small/{}.png
This is the result:

Image

There's still some residual halo, but it's much less than the first try.

To better explain what I need: it seems to me like this project has a lot of focus on producing images that perceptually "look good" to human observers (maybe I'm wrong, but that's the impression I get after reading docs and discussions). What I need instead is to avoid introducing "information" that was not there in the original. It doesn't matter that a human observer finds the image imperfect (too blurry); what matters is feeding the algorithm clean data.

Is halo a mathematical necessity? Will a rescaled image always show some halo no matter what? Is there a way to completely eliminate it?

Re: scaling down to 120x90px Gray with less ringing

Posted: 2019-09-14T19:06:07-07:00
by fmw42
-filter Triangle -resize is just doing bilinear, so it is more "smooth" than lanczos.