How to flatten photos of a round object?
December 29, 2011 11:24 AM   Subscribe

Straightforward way to take a flattened "panoramic" photograph of a round object?

I'd like to take some photos of round objects and stitch them together into an image as if the object had been unrolled (e.g. flattening the wraparound label of a wine bottle).

I've found a couple tutorials online about flattening a single image of a round object, but it seems like there must be a way to utilize an existing panorama package/etc to do this. It may be that there's a technical term for this I don't know that's preventing me from finding some good instructions.

I'm basically naive with respect to image editing, but I'm fairly tech-competent and have access to the Photoshops, et cetera.
posted by j.edwards to Technology (9 answers total) 2 users marked this as a favorite
Don't know if you have a smartphone, but if you do, maybe one of the smart phone panorama apps could do this well? E.g. Yes, they're normally used where the person stands still and rotates themselves and takes a series of photos, but I don't see why you couldn't use it to rotate around in object. If you're not familiar with those sorts of apps, I can tell you the great (and very impressive) thing is that they automatically adjust and stitch together each image in the sequence by analysing the content of each, to create a smooth, seamless panorama.
posted by Hartham's Hugging Robots at 12:44 PM on December 29, 2011

around an object.
posted by Hartham's Hugging Robots at 12:45 PM on December 29, 2011

Response by poster: Hmm, just tried that one and another (Photosynth) and they both use the gyroscope to determine the camera orientation, so neither rotating the camera around an object nor rotating the object itself seem to work.

Thank you for the suggestion, though! The app seems great otherwise and will likely get some unrelated use by me.
posted by j.edwards at 1:23 PM on December 29, 2011

I would use Hugin ( ) . I once did something similar when i was flattening out peoples sleeved tattoos just to see if it would work.
Take the photos as you have done. Either rotating the objetc or moving your camera around the pbject at a fixed distance. Make sure there is a lot of overlap as you are only going to use a relatively thing strip from each one, depending on the curvature of course .
Then treat it as the tutorial for stitching scanned images . Your images are "flat" in the limit of what you are doing.
Hugin may look difficult but as a first pass throw all the images at it with a low field of view and see what the auto does. It may look terrible but it may look decent enough to start from.
From there you can crop the input images to remove the shadow fall off areas and play with other parameters.
posted by stuartmm at 1:37 PM on December 29, 2011

I think Photoshop CS3 (and later versions) have applications for correcting spherical aberration. They might do the trick, but chances are most of the object will not be in the focal plane when acquiring the image.

Thus, it would probably be better to take multiple images while rotating the object, then crop the images such that you are only left with the front most (i.e. flat, in focus) part of the object, then the Photomerge feature of Photoshop should be able to stitch them together. This would be more easily done with a video, though, because it would require quite a lot of images, depending on how curved the object it.

There are relatively simple (and free) techniques for turning video into sequences sequences, and the rest can be done in a pretty easily. If you're interested in trying this and are using a Mac, I can detail out all of the steps involved. If you're interested in trying this and are using a PC, I can detail out a lot of the steps involved.
posted by kisch mokusch at 1:48 PM on December 29, 2011

Ah. Heh. There you go, I'm a dufus :) Well, yes, they're great for taking panoramic photos where you rotate, but that's not what you asked... good luck with finding the right solution.
posted by Hartham's Hugging Robots at 1:56 PM on December 29, 2011

And by sequences sequences I mean image sequences!
posted by kisch mokusch at 2:06 PM on December 29, 2011

Response by poster: I am on a Mac -- would definitely be interested in detail on the steps.

Am messing around with Hugin a bit as well, though it seems like taking a video and pulling frames from it would be the ideal way to go in terms of easiness.

Thanks, all!
posted by j.edwards at 9:00 AM on December 31, 2011

Best answer: Okay, so the long way to do what you want would be to take lots of photos of your curved object, manually crop each one such that the flat portion is in focus and then use an automatic stitching program (like Photomerge) to put them together. But this is incredibly laborious, which is why I suggested the video. Of course, the image quality drops with video, but the process detailed below should take a lot less time. It took a while to write out, which is why I wanted to make sure you wanted it before I went to the effort!

Firstly, you want to make sure the plane of focus of the object remains in the same place. So in your wine bottle example, you would set the camera at a fixed point and then rotate the wine bottle around it's axis as carefully as possible to avoid moving the point of focus and as slowly as possible to reduce motion blur.

Once you have your movie file, you'll need ffmpeg to convert the movie into an image sequence. Since the command is driven through Terminal, I am going to recommend that you create two folders in very specific locations with specific names so that you can easily enter the command. Firstly, after downloading ffmpeg, create a folder named ffmpeg_folder in your home directory (the little house icon, where you find Desktop, Documents, Downloads etc.) and put the ffmpeg execution file in it. Then create another folder in the home directory called temp_out. This is where the image sequence will go. It should thus look like this.

Now put your movie file on your Desktop, open TextEdit, and enter the following text:

~/ffmpeg_folder/ffmpeg -i /Users/yourhomedirectoryname/Desktop/moviefile.avi ~/temp_out/imageseq-%d.jpg

Of course, you will need to enter the name of your home directory (mine is ben in the link above) and the moviefile name will obviously be something else as well. Once you've changed those two parts, copy the entire text, open Terminal (in Applications/Utilities) and past it in. Press Enter. Your temp_out folder should now contain a set of jpegs named imageseq-1, imageseq-2, imageseq-3 etc. One caveat: I'm not sure what movie formats ffmpeg can convert. I know that it can do .avi and .mov, but I've never tried anything else. If you have something different, you can convert to .avi and .mov using FLV Crunch (also free).

For the next part, I would use Imagej (incidentally, this is the 5th time I've recommended ImageJ on AskMe). Hugin looks pretty cool, but I don't have any experience with it. Whereas I've used Imagej quite a bit. It's quite powerful and, best of all, it's free. If you have a 64-bit Intel Mac then I would recommend using ImageJ64, since it doesn't have some of the memory limitations of Imagej. It's very modular, which means you add and remove whatever plugins you need and put them in to the "plugins" folder. However, the easiest thing for you is to download the MBF "ImageJ for Microscopy" Collection. It's a collection of plugins that are of use for those of us that use microscopes, but it also has a few things that you need. What it doesn't have is Image Stabilizer, which you need to download separately and put into the plugins folder.

The first thing you should do after opening Imagej is increase the amount of memory it can utilize. Otherwise it will just crap out the moment you give it a difficult task. To change this, you go to Edit -> Options -> Memory & Threads… where you can set the memory. If you've got a 64-bit Intel Mac and can run Imagej64 then set your Maximum memory to 10000 Mb. If you can only run Imagej, then you'll have to set it to 1690. You then need to close Imagej and then re-open it for the new settings to kick in.

Then, to import your image sequence go to File -> Import -> Image Sequence… and select the first file (i.e. imageseq-1) in the temp_out folder. Make sure scale is at 100% and press okay. It will import the entire sequence within the folder.

First thing you'll want to do is to simply scroll through the image sequence and remove the frames you don't want. There are a number of ways to delete the slices; either remove individual slices (Image -> Stacks -> Delete Slice) or to remove everything before and after particular frames by going to Plugins -> Stacks - Reducing -> Delete slices before here/Delete slices after here. What you want is the object to be in the same location, without blur. So make sure to delete those frames that have motion blur.

The next thing that may or may not be necessary is to use the Image Stabilizer Plugin. It can be a bit hit and miss, and can take quite a bit of computer time to process even medium-sized stacks (especially if they aren't grayscale), but sometimes it works with impressive results. If you opt to use it, scroll to the middle of your stack before going to Plugins -> Image Stabilizer. Tick the "Output to a new stack" option and press okay (there are other options here but truthfully I don't understand the plugin that well. Feel free to play with them). If it works well, your object will now sit in exactly the same position throughout the stack.

Next, you need to crop out the out-of-focus stuff. The following procedure does the entire stack in one go. That's why you need to go to great lengths to make sure the object is always in the same place. You may wish to save the file at this point (File -> Save will create a single tif that contains the entire stack).

Now select the left-most icon in the toolbar (a rectangle), and then left click and drag the rectangle over your image. You can adjust it as you please, but you basically want to enclose the in-focus part of the object. Now select Image -> Crop. Imagej will crop everything outside of the rectangle and give you a much smaller image sequence. You then need to save the file as an image sequence (File -> Save As -> Image Sequence... )

Now it's simply a matter of opening all of those new files in Photoshop. Then go to File -> Automate -> Photomerge, select all open files, and press okay. Depending on your computer and the number of files you may wish to take a coffee break at this point, but the final output should be, fingers crossed, a flat image of a curved object.

Please note that I have not tried this, so I'm looking forward to reading the update about whether it works or not!
posted by kisch mokusch at 5:04 AM on January 2, 2012

« Older If you could live anywhere...   |   Lifetime leather jacket? Newer »
This thread is closed to new comments.