Orby Online

Reinventing ourselves since 2001


Developing LitenessPhoto: a photoblog theme for Wordpress

Posted on June 13, 06

In the process of creating a Wordpress photoblog theme called LitenessPhoto for the photography section of this website, I’ve had to learn the ins and outs of PHP’s EXIF extension and GD library of image functions.

Exif display example

For the uninitiated, EXIF data is information stored in an image file that can specify what kind of camera was used to take a digital picture, exposure information, image resolution, and quite a bit more. For a good overview, check out this Wikipedia article. The GD library allows PHP to create, manipulate, and pull information from photos.

I created Orby Photo with the intention of being able to automatically display the exposure time, f/stop, exposure bias, focal length, and ISO speed of any pictures taken with my camera; all without any work needing to be done by me (use of the EXIF extension). I also want the ability to display an album picture (usually a combination of some of the photos from an album) created by myself, or have one created automatically by PHP if one created by me is not present in a specified folder (use of the GD library).

Although this was easy on paper, a number of wrenches and baby sledges were thrown into the mix at various points during and after development.

For instance, getting the f/stop value should be as easy as $aperture = $exif[FNumber];. However, it seems that the presence of the $exif[FNumber] variable is dependent upon which version of iPhoto I’m using. This forces me to use $exif[ApertureValue] whenever $aperture = $exif[FNumber]; isn’t present.

For reasons I won’t go into here, these numbers are not the same. Instead, $exif[FNumber] is equal to to the square root of two raised to the power of the value $exif[ApertureValue]. Because we’re now dealing with irrational numbers, the computed f/stop value doesn’t always come out to the correct f/stop value of the image. Because of this, a series of if/else statements must be present in order to correct for situations where the computed value is not equal to the actual f/stop value (e.g. 21.9 instead of 22). Because wider f/stop values sometimes include one decimal place, I couldn’t simply round to the closes whole number, or f/2.8 would become f/3.

Instead of a simple output statement for the f/stop value, the code quickly ballooned to:

if (isset($exif[FNumber]))
	$aperture = $exif[FNumber];
else
	$aperture = round(pow(sqrt(2),
		convert_fraction($exif[ApertureValue], true)),1);

if ($aperture == ‘21.9′)
	$aperture = 22;
elseif ($aperture == ‘14.1′)
	$aperture = 14;
elseif ($aperture == ‘20.1′)
	$aperture = 20;
elseif ($aperture == ‘24.9′)
	$aperture = 25;

$output .= “$tabs<h3>:Aperture</h3>:\\n$tabs<p>:f/”.$aperture.”</p>:\\n”;

I hope to finish up development of the theme soon, and then begin the process of packaging it up so other Wordpress users can easily add it to their sites.

">
| /" title=""> | /-" title=" "> | yunohost admin ]

Making panoramas with Hugin and enblend on a Mac

Posted on August 4, 05

Hugin iconHugin is a cross-platform GUI that allows the user to “assemble a mosiac of photographs into a complete immersive panorama, stitch any series of overlapping pictures and much more.” Having long wanted to create panoramas but lacking the skills and time to make one that looks good, Hugin seemed like the perfect tool for me.

I went to the Hugin for OSX port page, navigated to the download section, and grabbed a copy. After downloading, I quickly realized that like most open source programs, the documentation on how to use Hugin was sorely lacking. I eventually learned how to do what I wanted to do through trial and error as well as reading numerous tutorials scattered around the web.

My first headache was getting Autopano to work, which is arguably the most important tool that Hugin can use. When it works, Autopano scans through the images you add to Hugin, finds where they overlap, and figures out the best way to stitch the images together. The version of Autopano linked within Hugin’s tools folder requires that the Mono environment be installed on your computer to work, so pick that up first.

After installing Mono, I noticed the following line in Hugin’s explanation on how to get Autopano working:

There are two ways of using Autopano-SIFT from HuginOSX. One is very easy, but does not always work, and hence not supported. The other should work as long as you set up autopano-sift correctly, but it involves editing shell script.

As usually happens, the very easy way did not work for me, so I had to do some minor shell script editing. After following the instructions and properly setting up the AUTOPANO_PATH variable and changing every instance of “generatekeys.exe” to “generatekeys-sd.exe” in the autopano-complete.sh file, I thought I was ready to rock.

However, Hugin quickly let me know that my rocking was yet to happen. Instead, it gave me this error:

Error message from HuginOSX

I double, triple, and quadruple checked my changes to the shell script, and I couldn’t find what I’d done wrong. I completely removed Autopano from my computer and downloaded a new copy to insure I hadn’t inadvertently changed something else.

Eventually, I realized that Autopano does not like it when the images you’ve added to Hugin have spaces in their path or filename. So after changing the folder and file names (in the example case seen in the error message above from “folder with spaces” to “folder”), my images were analyzed and properly linked.

I’m not going to go into the finer points of optimizing the panorama by adding vertical and horizontal lines or any other such thing - I do not have the experience or knowledge of Hugin to be considered a source on such things. But with the little experience that I do have, I was able to successfully turn thirteen separate images into this:

Pano after Hugin and Autopano stiched it up

If you click on the image to see a larger version, you’ll see that the stitching areas between images are very visible, and very ugly. This is where Enblend comes in. Although Enblend can be run from within Hugin by selecting the “into a high quality TIFF file” option in Quick Stitcher, I recommend against it. Instead, export everything as multiple TIFF files.

Once this is complete, you can run the images through Enblend via the command line in Terminal. An example command would be:

/Applications/HuginOSX/tools/enblend/enblend -v -o \\
/Path/To/Save/Final/Pano/Image.tiff \\
/Path/To/Image/1.tiff \\
/Path/To/Image/2.tiff \\
/And/So/On.tiff

Enblend takes quite a while (can be many hours depending on image size, number of images, and processor speed) to do it’s stuff, and I prefer running it through the terminal so I can free up system resources by closing Hugin. There isn’t any sort of progress indicator or time remaining information in enblend, so I run it with the -v flag (verbose) to keep me from thinking my computer froze.

Enblend looks at the various parts of the TIFF files that overlap, and figures out how to blend them. It will blend images over a wide area in parts of the images where there is little variation in the surrounding area - like in skies and clouds - and will blend images in a very small area where people won’t notice a harsh transition - like in rocky areas or in tree trunks.

If you compare the image below to the image above, you’ll see how great a job enblend does:

Pano after Enblend has done its magic.

For the next step, I played around with enblend’s exported TIFF image in Photoshop. I used the Stamp tool and Gaussian blur filter almost exclusively, and am pretty happy with the results. There are some areas I could spend more time in, like making the sky areas that I added look more uniform, but overall I think it looks pretty good for a first try.

Pano after some Photoshoping.

My biggest gripe with the Hugin is its lack of documentation. There are numerous options and optimization modes that are not referenced anywhere in the help. Sure, I can look around online for most of the information, but it would save every new user a half-day’s worth of time if all of that information was put in the one place it should be - Hugin’s help file.

That’s not to say Hugin and its associated tools are bad, because they aren’t - they just lack the information necessary for new users to get up to speed in a short amount of time.

Some statistics from the project:

  • Total pictures stitched: 13
  • Final resolution of panorama: 17964 x 2529 pixels.
  • Total time necessary for me to be at computer: ~30 mins.
  • Total time my computer spent on processing the images: ~6 hours

In case you’re curious, the panorama shows what you can see from the top of Mt. Rose, the third highest peak in the Lake Tahoe Sierra. You can see some other pictures from the hike here.