How to Take a Detailed Macro Photo of a PCB

How to see the smallest details on a printed circuit board? You can try scanning it or taking a photo. But the detail is still not enough. To take a decent macro photo, it's not enough to just have a good DSLR (or mirrorless). You also need a macro lens, but not an easy one. For most, the maximum magnification ratio is 1:1. And everything that is better is very expensive. The author of the article found an unexpected solution and tells how to take a photo and process it for maximum detail.

Suddenly – microscope

After browsing several extreme macro photography forums, I discovered that some people use microscope lenses in their cameras.

An image of an infinity microscope lens mounted on a camera.

An infinity microscope lens mounted on a camera. Thorninger.com.

Microscope lenses are divided into two groups: with infinity correction and without infinity correction. What does it mean? Lens without infinity correction focuses the captured image on a plane located at a certain distance from the lens. A infinity corrected lens converts captured light into a parallel beam.

When you need to transform a Fourier image using transparency masks or perform other complex scientific image transformations, the second type is suitable. After all, if you work with a parallel beam, it is easier to filter the light. To use this type of lens for macro photography, you will need an additional lens to focus the parallel beam onto the image at the sensor plane.

The first type of microscope lens (without infinity correction) can be used directly with an interchangeable lens camera. The only thing you need is an extension tube, which can be 3D printed in an hour. I found a great one repository on Thingiverse, where there are extension tubes for microscope lenses with various camera mounts. When combined with the cheapest 4x objective without infinity correction, the microscope's achromatic objective produces decent results.

Image of a cheap microscope lens

Cheap microscope lens from AliExpress

Picture of my PCB rendering setup

My setup on an inspection microscope stand for precise focus control.

Filming process

Now comes the hard part. I spent several days photographing different boards and stitching them together into one big picture. If you do something wrong at this stage, more and more problems will follow. My advice is to fix the camera at such a distance that the subject is in focus, and then move it in a certain way.

Scan the object linearly, zooming in only one dimension at a time (X or Y), as shown in the image below. The next image should overlap the previous one by 30-50%. If you have a full frame camera, try using it in crop mode or just make small movements. This way, you will only use the sharpest and least distorted image from the microscope lens. And remember, good and uniform lighting is everything to us.

Shooting scheme

Shooting scheme

Image processing

You can work with JPEG files straight from the camera, but I like to process RAW files in darktable. The correct exposure and contrast can be set at this stage, as changing these parameters can improve the quality of the seams in the final stitched image. Whatever you do, don't reduce or add noise when adjusting highlights, because this will reduce the equalization factors in Hugin. I usually crop the images further to remove the most distorted parts. You can export images in JPEG format at 98% quality to reduce file size. I've noticed that usually the limiting factor is a cheap microscope lens and you don't need high quality/pixel density.

Example of the darktable stack I use

An example of the darktable stack I use

Gluing in Hugin

Hugin is a set of tools for image processing. In it you can perform various manipulations on photos, but you have to pay for the versatility and flexibility with the complexity of the interface.

The first thing to do after launching Hugin-Panorama Stitcher is to change the interface to expert by clicking Interface->Expert. Then in File->Preferences, under the Control Point Detector tab, click New and add CPFind again, but with the arguments –linearmatch –linearmatchlen=2 -o %o %s.

The value in the “Program” field should be copied from the CPFind entry as it depends on where you have Hugin installed. This option will allow you to match an image to only one adjacent image in the folder, instead of matching it to every picture. This significantly reduces computation time for large image sets and improves accuracy.

So the workflow will look like this:

  1. Add images by clicking Add images….

  2. Select all images from the folder.

  3. Set Lens type to Normal (rectilinear).

  4. Set HFOV (v): 10.

  5. Set Focal length multiplier: 1.

  6. Select the Hugin CPFind script you created with linear arguments Feature Matching Settings: list from the list, and click Create control points.

  7. Select Custom parameters from Optimize, Geometric: list.

  8. Change the view to the Optimiser tab.

  9. Right click on Yaw(y) and click Unselect all. Do the same for the other columns.

  10. Right-click on X (TrX) and click Select all. Do this for Y(TrY) and Roll(r) as well (check Roll only if the images were flipped by the camera or you rotated the object itself).

  11. Click on Optimize now!. If you see a result similar to the one below, then everything is fine. If all the values ​​are zero or thousandths, you should take the photo again and try a little better.

Optimiser run finished.

Results:
average control point distance: 0.209935
standard deviation: 1.102026
maximum: 54.850377

Apply the changes?
  1. Click on Preview panorama (OpenGL), the ninth button on the top panel with the letters GL.

  2. See if your images are centered and create a continuous image. Objects may be slightly misaligned. Again, if the images are not visible or are not aligned, you should start over and take better quality photos. This will be faster than trying to align images manually.

Example of first image alignment

Example of first image alignment

  1. Now go back to the previous Hugin window and open the Control Points tab.

  2. Select the first image in the left window and in the right window.

  3. Using the arrows between the lists of image names, change images and stop where the pictures have long vertical or horizontal elements.

  4. By left-clicking on the left image, select the beginning of a horizontal or vertical element. And then on the right image, click on the end of this element. If the points are jumping around, uncheck auto fine-tune. Repeat this step for the desired number of images.

    Example of a marked straight line
    Example of a marked straight line
  5. Click Optimize now again! on the Optimizer tab.

  6. Switch the Fast Panorama preview view mode again.

  7. Click on the Move/Drag tab.

  8. Move the board to the center of the image or click the Center button in the upper left corner.

  9. Switch the tab to Projection.

  10. Select Rectilinear from the top list.

  11. Click on the Fit button in the top left.

  12. Select Mosaic plane in Mode: list. If you get a hint “Should the Tpy and Tpp parameters reset to zero?”, click “Yes

  13. Return to the main Hugin window to the Photos tab.

  14. Select CPFind (prealigned) in Feature Matching Settings:list.

  15. Click Create control points.

  16. Return to the Optimiser tab and click Optimize now!.

  17. Repeat steps 19–25.

  18. Click on Show control points – the eleventh button from the top left.

  19. Click on the Distance column and sort your points in descending order of distance.

  20. Remove the top ones. You can do this automatically, but it is better to check them one by one and do it manually. If you have Fast Panorama preview open, the selected points will appear in this window. Do not delete horizontal or vertical line points.

  21. Click Optimize now! again.

  22. Check out the Fast Panorama preview to see if your image is damaged. If this happens, congratulations, you can start shooting again or add more control points manually and try again from step 18.

  23. If everything looks good, go to the Optimiser tab and right-click on the Z (TrZ), Hfov (v) and Select all columns. Also select the Roll(r) column if you haven't done so before.

  24. Click Optimize now!.

  25. The most terrible step. If you are not happy with the result, go back to the previous steps and experiment.

  26. On the Fast Panorama preview Crop tab, crop the image using the white stripes that appear in the image.

Example of a marked straight line
  1. Finally, go to the Stitcher tab in the main Hugin window and click Calculate Optimal Size. The size of the output image will depend on the resolution of the input images, object size, and cropping.

  2. Check the first three checkboxes in the Panorama Outputs section and select your desired output file format.

  3. Click the Stitch button! bottom right.

Three image files should appear. Browse them and choose the best one. If you're not happy with the results, take better photos or tinker with the control points in Hugin.

Example of a stitched image

Example of a stitched image

If any errors occur during image stitching, it is likely due to duplicate images or the inclusion of pictures in the process that are not part of the same set of images. And if the resulting image has blur or shifts (like the image above), try adding more control points between similar images in the Control Points tab in the main Hugin window.

Thank you for your attention!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *