Score:2

Crop a specific region from a series of images

in flag

I have a series of png-images (actually they are taken from an mp4-file).

I want to crop the same region from all the images I have taken.

What tool is best for that, such that I can define the region first and then crop all the png images to the same region of interest.

Is there something to batch compress the resultant images (lossless)?

I tried apngasm, unfortunately the details to be shown in the series get optimized away - although apngasm is said to work lossless!

Since all the resultant images have great similarity: What is the best way to zip them to minimum size such that they can easily appended to an email such that the other person can look at them step by step to discuss the detail I want to show in them.

Score:8
pl flag

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.

Score:2
in flag

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.

Score:1
us flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.