Crop a specific region from a series of images

Solution 1:

You could use convert from package imagemagick:

$ convert image_in.jpg -crop <widthxheight+left+top> image_out.jpg

Then you could wrap that command in a for loop, with file pattern matching, etc.

Solution 2:

A more complete version of the given answer:

Take Gimp and use its function Crop to determine the area you want to keep. Select the area from the bottom right to the top left such that the coordinates of the upper left point and the width and height are displayed in Gimp's status bar.

In my example it said at the bottom

316,88, ...px... Rectangle 1622x634 ...

I then wrote a script and made it executable:

#!/bin/bash

# Variablendefinition
inputdir="/home/a/tmp/png"     # ~ did not work here instead of /home/a
outputdir="/home/a/tmp/crop"

# Abarbeiten der eingelesenen Bilder mit Hilfe einer For-Schleife
# und dem Programm ImageMagick.

for pic in "$inputdir"/v*.png ; do 
    picname=$(basename "$pic")          # siehe Ausgaben in eine Variable schreiben
    echo "Bearbeite Bild:    $picname"
    convert "$pic" -crop 1622x634+316+88 "$outputdir/$picname"
done

and that used this script which performed my cropping task.

I am still looking for an answer of a good compression taking into account that there are only small changes from one picture to the next one.

Solution 3:

For doing image series in parallel (I would recommend only on SSD drive), install imagemagick and parallel (sudo apt install imagemagick parallel) and then try this:

mkdir out
parallel -j 4 convert {} -crop 2048x2048+0+0 out/{} ::: img-*.png

it uses 4 processes -j 4 to convert file {} into out/{} if file matches mask img-*.png

mogrify from imagemagick package may work as well.

Regarding to similarity and compression, the most efficient is to use uncompressed images and compress them with something that does not compress individual files, but everything together. p7zip is usually the best and tar+bzip2 are sometimes/rarely better (usually for text and data like images that have very low contrast) tar+xz is very similar to p7zip (the same compression, different metadata). However for the most people zip is by far the most convenient format. For technical people using Windows 7zip is ok and I would advice using tar only if recepient is familiar with Linux.