How to copy, paste and flip horizontally and vertically many images?

447 Views Asked by At

Basically, I have 500+ images which I need to modify in exactly the same way. I have images like this Image input.

And I need to copy the left side of the image, more precisely the rectangle which dimensions are 645x999 pixels, paste it, flip it diagonally and move it on the right side. I could do this manually with any image editor but I want to know if I can make a program (preferably in c++), or enter a command that can do this for me. I wish to obtain this Image output, any advice would be of great help.

Thank you.

1

There are 1 best solutions below

4
Chris Hill On BEST ANSWER

The following netpbm commands show how to do this for a single file

cat cwxAr.png | pngtopnm | pamcut -width 670 -height 999 | pnmtopng > il.png
cat il.png | pngtopnm | pnmflip -tb | pnmflip -lr | pnmtopng > ir.png
cat il.png | pngtopnm > il.pnm
cat ir.png | pngtopnm > ir.pnm
pnmcat -lr il.pnm ir.pnm | pnmtopng > i.png

note - to obtain the output image that is given in the example the width is 670 pixels, not 645.

This should generate intermediate images il.png enter image description here

ir.png enter image description here

and a final picture i.png

enter image description here

To do this for a series of files the following script would work, where the variable flist is set to the list of files to be processed

#!/bin/bash -f

flist=( cwxAr-0 cwxAr-1 cwxAr-2 )
outpref=( cwxAr-out )
nout=0
for f in ${flist[*]} ; do
 fout=`printf "%s-%4.4d.png" ${outpref} ${nout}`
 echo "Reading "${f}", writing ",${fout}
 cat ${f}.png   | pngtopnm | pamcut -width 670 -height 999 | pnmtopng > il.png
 cat il.png | pngtopnm | pnmflip -tb | pnmflip -lr | pnmtopng > ir.png
 cat ir.png | pngtopnm > ir.pnm
 cat il.png | pngtopnm > il.pnm
 pnmcat -lr il.pnm ir.pnm | pnmtopng > ${fout}
 nout=$(( nout +1 ))
done