Flatbed Scanner Eliminates The Perils Of Macro Photography


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.

48 thoughts on “Flatbed Scanner Eliminates The Perils Of Macro Photography

    1. 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 ;)

      1. 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.

    1. 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.

    2. 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.

      1. 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.

      1. 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.

      1. 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.

  1. 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!


  2. 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.

    1. 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.

  3. 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.”

  4. 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.

    1. 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!

      1. 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.

  5. 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.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.