If you have ever played around with macro photography, you’ll know how hard it is to get a focused image of something that isn’t two-dimensional. For virtually every 3D object, you’ll have to deal with the depth of field – the small region where things are actually in focus. [David] came up with a neat homebrew solution for making sure everything in his macro photos is in focus using a discarded flatbed scanner and a Raspberry Pi.
[David]’s technique relies on focus stacking. Basically, [David] takes dozens of images of the same object, moving the camera closer by a fraction of an inch before snapping each frame. These pictures are stitched together with CombineZ, a piece of software used for extending the depth of field in images.
The hardware part of the build is a Raspberry Pi hooked up to a stepper motor driver and the shutter button of [David]’s camera. By attaching his camera to the carriage of a flatbed scanner, [David] can inch his camera ever closer to his object of study while grabbing the images for CombineZ.
The results are impressive, and would be nearly impossible to replicate any other way without tens of thousands of dollars in camera equipment.
Could something like this be done with video, in real time? like for use under a digital microscope?
Focus stacking might work in “real-time” for slowly-moving objects if you used a high-fps camera on a vibrating mount… Or combined multiple cameras with clever optics.
Or, depending on what you consider real-time, you could use a video camera, move it back and forth and stack always the last n images. Then it is just a question of computational power. Probably not on a Raspberry Pi ;)
Frame stacking is actually fairly common in the astrophotography world. It allows you to get a dark image without the noise and without blowing out the lights in it. From what I’ve heard a lot of people will use video and pull the frames out to do just that since they can get far more frames that way.
Yeah, but you do not have to move the camera, just adjust the exposure (or not even that), right?
The camera is already moving, along with planet Earth. B^)
Wouldn’t this just be HDR photography?
No, HDR is when you take 3 differently exposed photos and stack them so that the different shadows and highlights are prominant
Not quite, however an exposure/lens/focus event could take place at each linear step…
actually i had an idea to have a tiny vibrating lense in the camera (much like a cdrom drive reader head) to do this.
If you have a Canon DSLR that’s supported, you can do this using Magic Lantern. Look for ‘focus stacking’. It even drops a small shell script to automatically combine the stack of images into one.
This is much easier way to do focus stacking
There is much easier way to do focus stacking:
http://hackaday.com/2011/10/04/dslr-focus-stacking-assistant-takes-the-hard-work-out-of-macro-photography/
That functionality isn’t available on all cameras.
Changing the focus on most lenses also changes the focal length, that is why often the entire camera is moved instead of changing the focus.
I thought it was the other way around – focal length changing focus.
I guess you mean changing the focus also changes the magnification? Although moving the camera does as well of course, but maybe less so.
You can get impressive depth of field in macro with an extension tube (which can be built, or bought for a few dozen dollars), a very small aperture and a long exposure.
Exactly. Macro Photography done with the right gear does not need tricks like this.
small apertures require lots of light (strobes) or long exposures. I personally prefer strobes, because then the background ends up with even less detail.
But tens of thousands of equipment? come on, HAD, a tilt-shift bellows costs about $400 depending on your (d)SLR model. An older model Lensbaby and some $20 aluminium extension tubes cost less, and both will let you get the selective focus without stacking.
I’m not against focus stacking, btw. Sometimes, you have the lens so far out of alignment with the film plain that even at f22 you can only get a little bit in focus at a time. But it’s not needed in most cases. Focus stacking is for objects magnified, things that are smaller than your image sensor that you’ve made appear a lot bigger; not objects larger than the film sensor.
With the total extension of about 6 inches I can get out of the bellows I made for my camera… the smallest aperture available results in an effective depth of field of less than a millimeter (assuming I can get enough light).
A rig like this would let me produce photos of tiny things that are optically impossible for me to capture now.
eh… I exaggerated that a bit… still, the focus stacking rig is one of my planned future projects as it allows me to produce photos with a greater depth of field than is optically possible.
I use the small aperture and long exposer, good lighting, non issue
I have a normal NON DSLR camera and Macro isnt a issue. My pictures come out better than that and on smaller objects…
http://s4.beta.photobucket.com/user/AtomSoft/media/SAM_1757_zpsc37033ce.jpg.html
While that is a decent picture, I can get MUCH closer with my Canon DSLR and my macro lens. Looks sharper too.
Heh, better? Canon A640 P&S: http://johnbokma.com/mexit/2008/03/03/fixing-a-heatsink-problem-in-a-compaq-presario.html Check the replacement clip one.
Other examples: http://toxicice.com/images/vaejovis-spm-spermatophore.jpg (see http://johnbokma.com/mexit/2008/04/21/vaejovis-punctatus-mating.html for some explanation), and one of my favourites: http://www.flickr.com/photos/johnbokma/4781018342/sizes/l/in/photostream/
Anyway, never judge a technique by a single example.
Nice pics. I have dragonfly pictures instead :D Can see the facets of their eyes :D
Yeah, I have a $75 (new) Canon A800 point and shoot that has macro mode. I get fantastic macro shots with great depth of field – in one shot and without an elaborate lighting stage. The A800 never ceases to amaze me. I use it far more than my DSLR. As a bonus, it runs on standard AA batteries and gets great battery life. No I don’t work for Canon.
maybe he should just alternate the focus rather than moving the camera…cause if you move the camera your angle of view changes.
actually, this is the “better” way to do that, because changing the focus also changes the focal length, and the effects of that are worse.
That’s what prime lenses are for: no change in focal length as you change the focus. Or use adjustable bellows to move the focus, at 3 inches of extension the change in fcoal length over 1 inch of focus is pretty minimal with the right lenses.
10’s of thousands of dollars? I have one of the most expensive macro lenses made and they are “only” $1900 new.
Like other have said, you can do the same thing that he has done with a dSLR with a extension and a small aperture with a lot of light or long exposure. And many Point and Shoots have very good macro modes too.
Now, I am going to use this post as an excuse to link to some of my macro photos!
http://www.flickr.com/photos/67292116@N00/sets/72157627041373036/
Ridiculous!
Herd of photography?
But, were any cows tipped during the filming of this posting?
An un-herd of amount.
he-he best set of comments on this post :-)
1) moving the camera is the correct way vs “zoom”ing or focusing.
2) this is better than stopping down to f/32 or whatever, because, regardless of your fancy lens, extension tubes, etc. diffraction starts tossing your megapixels out the window above ~f/5.6.
False. Lenses are typically happiest around f/4-f/6. The “diffraction issues” threshold depends on the size of the lens, the sensor size, and a few other factors..and is usually much higher, at least f/16.
Not at the sensor densities today. f/16 maybe for a FF 6mp or film.
I was about to ask “Is there any UNIX equivalent to the windows CombineZ software ?”
When I found the answer to my own question, which may be of interest others:
http://en.wikipedia.org/wiki/Focus_stacking#Software
while this is totally impressive, it can be done with nothing more than a $15 “Macro Focusing Rail Slider” & a bit of time NOT “nearly impossible to replicate any other way without tens of thousands of dollars in camera equipment.”
Although I will use focus stacking from time to time in my case it’s usually no more than four or five images. I also realize that each of us do what we need to do to achieve the results we want the stacking 40+ images seems a bit excessive. I’m certain however that there are things that I do that people would find excessive so it’s acceptable.
As an evidence photographer perhaps 70 or 80% of my work is macro photography. Because of this I can only guess that I’m accustomed to the shallow depth of field and accept it as part of what I do.
So, have any defense lawyers tried to throw out any of your stacked photos as evidence because they’ve been “altered” by focus stacking? Have you been called in as an “expert witness” to defend photographic evidence?
Do you work with cute babes like the stars in those TV programs do? B^)
CSI/NCIS fans want to know!
Oh god no. Evidence photos may only have minimal alterations. Nothing more than color correction (basically a white balance adjustment and basic sharpening. That happy stacking is just for me and my own photos every once in a blue moon.
Never once I have I been called to testify about any of my photos but it’s not out of teh question that it will happen one day.
And no, It’s most certainly not like TV. I always tell people, it’s not glamorous and we NEVER get the girl at the end of the show. LOL More photos of broken door jams than anything else.
You could actually use the flatbed scanner itself for quite decent results of mostly 2 dimensional objects like PCB’s. I think even that some of the scanners allow you to modify the focus of the scanner.
You can also use CHDK hack for canon point and shoots. It has focus bracketing.
Keyence’s video microscopes use a similar technique for enhancing depth of field.
Surprised that no one pointed out that Lytro can do the same thing. The build is still cool, I just question the “tens of thousands of dollars” statement.
Aw, this was a very nice post. Taking a few minutes and actual effort to make a superb article… but what can I say… I put things off a
whole lot and never seem to get anything done.