Image resize

Sending images over SSB or other bandwidth limited communication lines can be (is) a challenge. The issue of resizing images came up as a question on how to easy and simple resize images before sending it over radio/Winlink. I wrote this little page to show how it can be done and to get you started with the tools.

This small overview show how to resize images using a simple scriptable command line tool. The linux utility convert is part og a larger package called imagemagick. While GIMP is an excellent interactive GUI tool, the command line (CLI) tools can be scripted and a very simple to adapt to automated image converting. The imagemagick web page is a good source of detailed information, and a separate for the CLI tools. Convert (man page) is a utility in the imagemagick package.

This is the original image at 2.5 MB and 4000x3000 px (Olympus TG-6).

Sending an image of this huge size, 2500 kB would not be practically possible over Winlink. While it migt be doable over VHF/UHF is would not be possible over SSB. Just assume 1000 bits/sec over SSB. It will be 100 Bytes per secons. 2,500,000 Bytes would take 25,000 or about 7 hours just transfer time. No way is this by any means practical.

It is important to minimise the image, but the final image should still look somewhat like the original. Going from 2500 kB to 20 kB require some smart usage of the available tools. As most pictures are in JPG format I have only used JPG examples.

Example of the imagemagick utility convert.

convert Night.jpg -quality 20 -resize 1600x1200 Large1.jpg

convert Night.jpg -quality 70 -resize 1600x1200 Large2.jpg

convert Night.jpg -quality 20 -resize 800x600 Medium1.jpg

convert Night.jpg -quality 60 -resize 800x600 Medium2.jpg

convert Night.jpg -quality 20 -resize 400x300 Ns1.jpg

convert Night.jpg -quality 70 -resize 400x300 Ns2.jpg

The command convert is normally installed by default, if not it's part of the package imagemagick. For Ubuntu based installations apt install imagemagick will install the package. The utility convert has a large number of options, see imageimagick web page for more. For a simpler intro to convert try the manual page using : man convert.

Converting images to very small size is a none trivial task. Resizing pixel size versus compressing more with JPG compession (JPG is lossy and can compress very hard). There is a tradeoff between resizing and compressing.

Large1.jpg at 47 kB at 1600x1200 px (-quality 20 -resize 1600x1200)

Large2.jpg at 111 kB at 1600x1200 px (-quality 70 -resize 1600x1200)

Medium1 at 16 kB at 800x600 px (-quality 20 -resize 800x600)

Medium2 at 37 kB at 800x600 px (-quality 60 -resize 800x600)

Small1 at 5.9 kB at 400x300 px (-quality 20 -resize 400x300)

Small2 at 13 kB at 400x300 px (-quality 70 -resize 400x300)

From the examples we see that in order to get the best image at about 10-20 kB we need to apply both resize in pixels and apply rather high quality JPG settings, the range is from 1 to 100. As all images are unique there is no single optimal settings. The above settings are guidelines to have somethings that is ok for most images.

One can fix the resulting image size with an option, this works nice but theer are pitfalls. In the examples below it's clear that a pixel resize is beneficial before compressing further with JPG algorithm. As most of the pictures sent by email is to be viewed on a PC 800x600 is a reasonable size. Going from 2500 kB to 20 kB and still get a viewable quality is very good when sending images from places with no internet connection.

-resize 800x600 -define jpeg:extent=20kb -define jpeg:dct-method=float 

-resize 400x300 -define jpeg:extent=20kb

-resize 800x600 -define jpeg:extent=20kb

-resize 1600x1200 -define jpeg:extent=20kb

As JPEG is a format that cannot handle sharp edges well, infinite derivatives, like line drawings, figures etc. The smooth features in a picture can be exploited to reduce image size using Gaussian blur. This make the picture less sharp, but reduce size bu removing all high frequency components. It could be worth testing the image apprearence versus size by applying some quantity of Gaussian blur using :

-resize 800x600 -define jpeg:extent=20kb -define jpeg:dct-method=float -gaussian-blur 0.02

Here I have locked the size to 20 kB, but for experimentation this should be removed.