Scanning and Processing - derangedhk417/MicroscopeControl GitHub Wiki
This is out of date as of this writing. See Using Smart Scan
This page is meant to document Scan.py
, ScanProcessing.py
and ImageProcessor.py
. These three files combined (with MicroscopeControl.py
) can be used to scan a sample and determine the location and bounds of every flake in the sample.
Scan.py
Is a command line tool that allows a user to specify a region of the stage to image. The user must specify the coordinates to scan (in stage coordinates) and the physical size of the image at whatever zoom level to microscope is at. In a future update, this will be determined via a calibration program automatically. The process for using this program is as follows:
- Turn on the light source, motor controller and stage.
- Run
python MicroscopeControl.py --no-camera
. - In the prompt that appears, type
microscope.focus.setZoom(0.99)
(This is recomended, but not strictly necessary.) - Enter
microscope.focus.setFocus(0.5)
- Open the Pixelink capture software and use the joystick on the stage controller to navigate to a point in the sample where there is something to focus on.
- Use the knob on the z-stage to focus the microscope.
- Use the joystick on the stage controller to find the corners of the rectangular region that you want to scan. At each corner, you'll need to read off the coordinates listed on the stage controller.
- Run
python Scan.py -x x_low x_high -y y_low y_high -W image_width_mm -H image_height_mm
You'll need to run python Scan.py -h
first to make sure that you've satisfied all of your requirements with the command line parameters. You'll generally need to specify more parameters than those listed in step 8. In particular, the --focus-range parameter may need to be chosen. By default, it is 0.4 to 0.6. This is the range of focus motor positions that are swept when determining what focus position is best. If the sample is transparent and it is possible to focus on the stage instead of the sample surface, this value will need to be carefully chosen to avoid having the system accidentally focus on the stage. In general, you want the values to be as small as possible while still being certain that the true focal point will be within their range. For fairly flat samples, 0.45 to 0.55 will usually work.
The program will move the stage to each of the four corners and auto focus itself. It will then fit those focal points to a function of the form z = ax + by + c. This function will be used to continuously adjust the focus throughout the scan.
Important: The --square-size parameters allows you to break the scan up into square regions. The program will repeat the focus calibration process for each region. If you only want to use a single square (only calibrate once), set --square-size to a value larger than the largest dimension of the rectangle that you are scanning.
Scan.py will image every single part of the region specified and will move the stage according to the specified width and height of the camera view between images. If you want there to be a slight overlap between images, simply make the -H and -W parameters slightly lower than the actual image dimensions.
The result of Scan.py is a folder of images, where each image is named with the following format <index>_<x_pos>_<y_pos>.png
. index
is a unique number identifying the file, starting at zero. x_pos
is the x-coordinate of the image in millimeters (stage units) and y_pos
is the y-coordinate in the same units.
If you do not pass the --dont-process
flag to the system, it will automatically spawn child processes and run the flake extraction code on images as they are loaded, see below for details on this process.
Scan.py
delegates the process of extracting flake geometry from an image to this file. The process involves a lot of steps and will be covered on a different page. ScanProcessing.py
can be run as a standalone program. It is strongly recommended that you run it on an image folder with the --debug-display
flag and --np 1
. This will display every step of the flake extraction process as a series of images. It will also print the line number each time it displays an image. This allows you to quickly locate the code that performs each part of the process.
This file contains the classes used by ScanProcessing.py
. The two primary classes are ImageProcessor
and FlakeExtractor
. ImageExtractor
allows you to succinctly express a series of sequential image transforms to apply to an image. It also automatically stores an image at each step in the process and displays them if you call .display()
. FlakeExtractor
makes use of ImageProcessor
and some other logic to perform the flake extraction and background subtraction process.