0

So I have a hobby project of strapping a USB microscope onto a 3D printer to take pictures of an object at different X, Y, and Z locations, which are then stitched into a full image. I started with the code from this stack to generate a 2D rectangular raster pattern, and then upgraded that to do 2.5 D imaging (stacking and stitching) by looping repeatedly to move the Z axis after each 2D scan, and finally doing the same with a 4th axis to enable 3D imaging.

The problem is that most things are not rectangles, and the scan can end up becoming very wasteful, stopping to take pictures in areas that are not object or obviously out of focus. I would love to be able to 1: shift the "scan plane", for instance to scan a flat object tilted upwards, and 2: Just in general be able to generate arbitrary scan patterns, or at least simple ideal shapes.

How would you take information about a 3-dimensional shape (for instance, from an STL), and wrap an otherwise 2D "dot matrix" raster pattern around the surface (or at least the part pointing up)?

Bowtie
  • 121
  • 1
  • 4

1 Answers1

0

I figured out the basics for doing this with my original rectangular/cuboid scans. The math is simple to rotate about for instance the Y Axis:


def RotateArray(ScanLocations, degrees = 30):
    #function to rotate a 3D array around a specified axis (currently Y). Ideally, around arb point in space.  
    #X Location minus offset becomes new hypotenuse after rotating.
    #(sin(degrees) * X) + Z gives new Z .
    #cos(degrees)* X gives new X. Right? Y should be unchanged.

    XLocations,ZLocations = ScanLocations['X'],ScanLocations['Z']
    sinof = sin(np.deg2rad(degrees))
    cosof = cos(np.deg2rad(degrees))
    XOffset = min(XLocations) #not fair to assume it is zeroth position

    ZLocations = [round((x-XOffset)*sinof + z,2) for x, z in zip(XLocations, ZLocations)]
    XLocations = [round(((i - XOffset) * cosof)+XOffset,2) for i in XLocations]

    ScanLocations['X'] = XLocations
    ScanLocations['Z'] = ZLocations
    return (ScanLocations)


Visualization using ncviewer.com:

original scan

Rotated Scan around Y axis

A new problem I need to solve now is rearranging my movements to be more efficient. I'd like to selectively priority one axis, for instance, Z, so that images which will be stacked are taking without X/Y movements in between.

Bowtie
  • 121
  • 1
  • 4