================================

GOAL: batch image processing

Goal: do some simple image batch processing to illustrate linux command line

SUMMARY

- lighten an image by 20%: "convert -brightness-contrast 20 input.jpg light-input.jpg"

- loop through list of images and lighten in BASH:

for file in rr-*.jpg; do
convert -brightness-contrast 20 $file light-$file
done

================================

Lighten Images from Command Line

imagemagick is an image processing tool that is usually included with
Linux.

To do a simple brighten Google tells me to use
"-brightness-contrast". Let's lighten and darken by 20%:

convert -brightness-contrast 20 rr-IMG_20160923_155144.jpg light-rr-IMG_20160923_155144.jpg
convert -brightness-contrast -20 rr-IMG_20160923_155144.jpg dark-rr-IMG_20160923_155144.jpg

This will take the input "rr-IMG_20160923_155144.jpg" and create two new images:

dark  |   original  |   light:

To do automatic image normalization:

convert -enhance -equalize -contrast rr-IMG_20160923_155144.jpg norm-rr-IMG_20160923_155144.jpg

The automatic didn't do very well, IMHO.

================================

Batch Processing

What do we do if we want to lighten 1,000 images?

The simplest is to use the BASH command-line for loop (that I have to
Google the exact syntax everytime). You can simply call a command for
each item in a list:

for file in rr-*.jpg; do
convert -brightness-contrast 20 $file light-$file
done

"rr-*.jpg" returns a list of all files in the current directory that
start with "rr-" and end with ".jpg". The "for" loops goes through
them and "\$file" refers to the current one the for loop is using. So
this simply creates a set of new images with names prefixed by
"light-".

original:
light:

================================

Command Construction with Python

The simple for loop is fine for simple manipulations and naming but
what if you want to do more complicated things?

I usually write loops in Python where it is easy to express arbirary
computation.

I usually read in a list of items and then output a list of commands
that I can sanity check before running.

TODO....

================================

Lighten Math

What does it mean to lighten?

For 8-bit RGB color image: $$I(x,y) \rightarrow (r,g,b)$$ where $$(r,g,b) \in ([0,255],[0,255],[0,255])$$

Thus to change intensity by a factor $$f$$ for pixel $$p$$ and each color channel $$c$$ we have:

$$p_c^\prime = \min( \max(p_c*f,0), 255 ). c \in (r,g,b). \forall p \in I$$
where the max/min clip to legal 8-bit values.

================================