All things Raspberry Pi and Time Lapse

ImageMagick scripts

I found this post here about a guy who took all of his shots from a year and compiled them into a single image. This sounded like a cool idea, but I could never find the code for how this was accomplished. But I figured that it shouldn’t be too hard so I set about doing it for myself. I have 21 images so far and I compiled them into these two images. One from right to left. And the other from bottom to top.

Once I have more images it should look better as each section will be considerably smaller. I achieved these results using a command line program called ImageMagick on Linux. It was a very simple install ‘yum install ImageMagick’ (notice the capital letters) since I am using Fedora and that was all. Debian based distros may be something like ‘sudo apt-get install ImageMagick’ but I have not tried it. The weird thing though was that I was actually using the command line tool ‘convert’ from the command line instead of ‘ImageMagick’. Great documentation available at their site about the usage here. And documentation specifically about the cropping here. The command line usage looks like this:

convert input_file XxY+X+Y output_file

The program uses the X and Y axis for where to crop. The top left corner of the image is 0x0. The +X+Y is offset from that initial 0x0. Check out the scripts below for actual usage in the script. I did the math before I ran the script and that is where the 92 and 73 come from. I took the dimension of the image and divided by the number of images that I had. So the first image is 2048 wide and I had 21 images. Then I rounded that number down to get the 92 that was used in the script.

This first script is for the top image cutting columns of the image.

#!/bin/bash
# jamesmiller
# get list of files in current directory
files=`ls | grep “^rasplapse*”`
# set the initial crop point
x_factor=0
# for each file in the current directory
for x in $files
do
# ImageMagick convert program to crop the image
convert $x -crop 92×0+$x_factor+0 column_$x
# add to the initial crop point so the next image
# is not the same strip as the previous image
x_factor=$((x_factor + 92))
# add a border of white
#convert column_$x -border 1x column_$x
done
# get the list of newly created images
column_files=`ls | grep “^column*”`
# add all of the strips of images into one image
convert $column_files +append column_file.jpg

This script is for the bottom image cutting rows of the image.

#!/bin/bash
# jamesmiller
# get list of files in current directory
files=`ls -r | grep “^rasplapse*”`
# set the initial crop point
x_factor=0
# for each file in the current directory
for x in $files
do
# ImageMagick convert program to crop the image
convert $x -crop 0x73+0+$x_factor row_$x
# add to the initial crop point so the next image
# is not the same strip as the previous image
x_factor=$((x_factor + 73))
done
# get the list of newly created images
row_files=`ls -r | grep “^row*”`
# add all of the strips of images into one image
convert $row_files -append row_file.jpg

The very last line of each script is what compiles all of the strips of images into one image. NOTE: these scripts are meant to be executed in the folder containing the images. And they may need to be modified to suit other uses depending on the file naming structure and so forth.

I also tried these scripts using the pictures that were taken every 2 minutes. But even separating them out into three different pictures it didn’t turn out that neat. There was very little change across the picture because not that much moved in a single day.

Looking forward to using this technique on more pictures like the pictures shown above once I have more images!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: