PDA

View Full Version : Few tips on processing digital images


tvset
25th March 2004, 03:29 PM
I think that it's safe to say that digital camera is a pretty common thing these days. One advantage of using a digital camera is that making images is cheap. Actually, it's mostly free. Lots of people make lots of images and publish them on the Internet or burn them on CDROMs. Often, these collections of images look rather ugly, since people who made them didn't want to spend a lot of time post-processing these images.

Here are few things you can do with image collections that will not take a lot of time, but will make viewer's life easier.

ROTATION

The most annoying problem for myself when watching an album or a directory with images, is orientation. It's rather common to find a number of images rotated 90, 180 or 270 degrees. It's pain. Here is how you can fix it.

Fully Automatic
Many modern digital cameras do have a gravitation sensor (most of Canon cameras do at least), that tells them the position of the camera at the moment of the shot. This information, if known, usually becomes a part of the image. Camera writes an EXIF header called "Orientation: ", where it specifies the number of degrees that the image needs to be rotated. In order to use this information, you'll need two programs: jpegtran and jhead. jpegtran is a part of Fedora distribution (package: libjpeg). jhead - is not, but you can download it from here: http://www.sentex.net/~mwandel/jhead/. (http://www.sentex.net/~mwandel/jhead/)

After you have both of them, fire up your favourite terminal and do the following:

cd /path/to/image/directory/
jhead -autorot *.jpg

This will force jhead to go over all your JPEG images in the current directory, examine headers of each image, and relace image with rotated version everywhere, where "Orientation: " header is specifing a number of degrees. jhead will also fix the header after rotation, so that if you accidentally run it in the same directory nothing will happen.

Semi Automatic
In case you camera does not have gravitation sensor, you can select images for rotation manually. After you select them, your Fedora box can go over them by itself, without you clicking numberous clicks.

We'll use another useful package shipped with Fedora Linux Core 1 - ImageMagick. Rotating a single image is done like this:

convert -rotate 90 image-orig.jpg image-good.jpg

Here, "90" is the number of degrees we want to rotate an image (clock-wise), "image-orig.jpg" is the original image, and "image-good.jpg" is the result of convertion. In order to convert a banch of images, it'll be a good idea to create a script. Open up your favourite editor and creat the file rotate.sh with this content:

#!/bin/bash

# Go through all specified images
for IMAGE in $*
do
# Copy original temporarily to another file
mv $IMAGE $IMAGE.orig
# Rotate original image
convert -rotate 90 $IMAGE.orig $IMAGE
# Remove temporary copy of the original
rm $IMAGE.orig
done

Put this script somewhere in your PATH and give it executable permissions. Now you can use it in the following way:

rotate.sh image_001.jpg image_002.jpg image_003.jpg

Here you say that you want images "image_001.jpg", "image_002.jpg", and "image_003.jpg" be converted 90 degrees (that's in the script). You can specify as many images as you want. Using "*.jpg" will cause all images in the current directory to be rotated.

RESIZING

Second most annoying problem is viewing images that are larger then my screen, or are of huge size (painful downloading). Resizing images for the web, will make sure that images fit your viewers screen and are smaller in size, hence faster to download. But who likes boring work? :)

ImageMagick once again helps us here too. In order to resize a banch of images in the directory we will create a script, similar to the one above, called resize.sh. Here is the content:

#!/bin/bash

# Go through all specified images
for IMAGE in $*
do
# Copy original temporarily to another file
mv $IMAGE $IMAGE.orig
# Resize original image to 800x600
convert -resize 800x600 $IMAGE.orig $IMAGE
# Remove temporary copy of the original
rm $IMAGE.orig
done

Put this script somewhere in your PATH and give it executable permissions. Now you can use it in the following way:

resize.sh image_001.jpg image_002.jpg image_003.jpg

Here you say that you want images "image_001.jpg", "image_002.jpg", and "image_003.jpg" be resized to 800x600 pixels (that's in the script). You can specify as many images as you want. Using "*.jpg" will cause all images in the current directory to be resized.

MORE
ImageMagick provides a number of other tools that can help you process a number of images in one go. Please read manuals shipped with the package for any additional information.

Happy imaging. ;)

Ug
25th March 2004, 11:06 PM
Nice!

Why not submit it in Article format too? So that it'll be preserved in a more static format. Go here (http://www.fedoraforum.org/forum/articles.php?s=&action=intro&s=) to do so.

tvset
25th March 2004, 11:30 PM

Nice!
Thanks! :)
Why not submit it in Article format too? So that it'll be preserved in a more static format. Go here (http://www.fedoraforum.org/forum/articles.php?s=&action=intro&s=) to do so.
Done.