Tiling with Knobby

Knobby scheduler allows the user to move the microscope by specifying a list of relative changes in position at given frame numbers.  One quick way to fill up the table is provided by a set of text fields in the knobby panel.  This allows one to perform (x,y,z) tiling with a given range and step size.


The first row of entries correspond to the range (in um) to be covered in the x, y and z axes respectively.  The second row specifies the step size in each case.  The last entry at the bottom tells Knobby how many frames to sample at each location.

In the example above, Knobby will perform a z-stack with 40um range and 20 um steps (that is, a total of 3 locations), on an (x,y) grid of 3×3 with 200um horizontal and vertical range and steps of 100um.

As you input the desired values the table will update automatically.

Once ready, click the “Arm” checkbox (and the “Return” checkbox if you want knobby to go back to its initial position at the end) and start your acquisition.

Here is the resulting scan for the example above:

Spatial Calibration for Multiple Objectives

Multiple users of the scope may be running projects that require different types of objectives.  How to keep a spatial calibration for each and switch between them when necessary?

Scanbox now includes an “objective” configuration variable — a cell array of strings each with the name of a different objective.  Right now I have:

% objective list
sbconfig.objectives = {'Nikon 16x','Nikon 25x'};

Now, within the Knobby panel you will see a pull down list containing the objective names:


Select the desired objective before performing a calibration.  Once the calibration is finished it will be saved.  If a calibration is not present for a given objective the calibration button will read “No Calibration” and the mouse control will be disabled. If you change the objective, simply select the corresponding entry in the pull down list to apply the new calibration (no need to restart Scanbox).

When collecting data the info structure will include the objective name and calibration data:

info =

struct with fields:

resfreq: 7930
postTriggerSamples: 5000
recordsPerBuffer: 512
bytesPerBuffer: 10240000
channels: 2
ballmotion: []
abort_bit: 0
scanbox_version: 2
scanmode: 1
config: [1×1 struct]
sz: [512 796]
otwave: []
otwave_um: []
otparam: []
otwavestyle: 1
volscan: 0
power_depth_link: 0
opto2pow: []
area_line: 1
calibration: [1×13 struct]
objective: 'Nikon 25x'
messages: {}
usernotes: ''

External TTL trigger

To automatically start /stop acquisition by means of an external TTL signal follow the following instructions.

First, connect an appropriate TTL control signal to the P1.6 (pin #21) of the extension header of the Scanbox board.  The view below shows a top view of the Scanbox control board.  The pin in question is located on the back row of connectors when viewing the board from the front.  As a ground pin, you can use pin #3.  To make it easier to make the appropriate connections it helps to get the this cable and route it outside the box.


StartCapture the Scanbox software and operate as usual by focusing and selecting the area you want to record.  When ready to switch to external trigger control, simply click the “External TTL Trigger” checkbox, which is located in the middle of the Scanner control panel.

After enabling the TTL trigger, the manual Focus/Grab buttons will be grayed out and blocked from usage.  If you want to go back to manual control simply deselect the TTL Trigger checkbox.

The rising edge of the TTL control signal is used to start/stop the microscope.  Minimum pulse width is 1 ms.

While controlling the microscope using an external TTL signal it is useful to run it in continuous resonant mode (so you avoid waiting for the resonant mirror to warm up) , and set the “autoinc” configuration variable to “true”, so file numbers increment automatically after the completion of each session.

To use this feature you have to update to the latest version of the firmware/software.

Update [6/23/17]:

If you are willing to give use of TTL1 as an event line, a new trig_sel configuration variable allows you to use it instead of the signal from the header to start and stop the acquisition.  You will have to upgrade to the latest version of the software.  Follow the instructions here.  You can skip the steps asking you to update knobby, the motor box, and run vc_redist.x64.exe.  After the update, simple set the trig_sel configuration variable to true if you want to trigger with TTL1 (or false if you want to trigger using the header signal).

Bada boom! New system coming soon!

So why the long silence in the Scanbox blog?

We have been working hard on a the development of our new system. A modular, expandable system that will run the new line of Neurolabware microscopes (aka the Kraken microscope) and is backward compatible with our previous box.

Want a sneak peak?

Bada boom!



Here is a closeup of some of the LCD/power modules…



If you are interested in the new features of the Kraken microscope and the new modular system please get in touch with Neurolabware.

Surface sampling in Scanbox

Answering a request from colleagues in London, the upcoming version of the Scanbox firmware will allow users to change the depth of imaging on a line-by-line basis.

Up to now, during volumetric imaging, users were allowed to change the setting of the electronically tunable lens (ETL) once per frame (during the transition from one frame to another).

The new version offers the possibility of changing the depth (z) as a function of the line number (y).  For example, the image of a pollen grain below, was obtained using a sinusoidal modulation in depth.


There are at least two potential uses for this new feature.

First, one can increase the yield of imaged cells by first measuring a z-stack and then designing a (smooth) sampling surface z = f(y) that maximizes the number of cells that can be imaged.

For example, assume the projection of cell bodies within the volume is given by the scatter-plot below. Then sampling with the solid curve line will yield many more cells (red circles) than sampling with any horizontal plane (such as the dashed horizontal lines).


I will explain how to calculate an optimal (smooth) function of depth that maximizes the number of cells sampled in a separate post (the algorithm is too large to fit in the margin here.) [Actually, I added it below].

The surface sampling method offers a compromise between random access and volumetric imaging across planes, many of which may not contain many cells, thereby reducing the temporal resolution unnecessarily.  Have any groups done something like this before?

The second use of this new feature is that it can allow us to correct for the ringing in ETL focal plane that results from a step change.

If you have been doing volumetric imaging, where N frames are sampled at each depth, you might have realized that a few of the lines at the top of the frame on the first frame after a depth transition is screwy.  This is due to the ringing of the ETL. One can potentially use the ability to change ETL command on the fly to compensate for this ringing.

I have not yet implemented this.  Are there any Scanbox users doing volumetric imaging that are willing to help?


Given a set of cell body projections (y_i, z_i) we want to find a smooth function z=f(y) that intersects as many cell bodies as  possible.

We do this by restricting z(y) to be sum of the first N harmonics, z(y) =a_0+\sum_{k=1}^N a_k \cos ( 2 \pi k y + \phi_k ), so it is both smooth and periodic as well, which will prevent ringing in the ETL during fly back to the first line. The function has 2N+1 parameters.  For simplicity, here we normalize the total number of lines in the frame is normalized to be in the range [0,2 \pi].

Given a set of parameters, denote by d_i the minimum distance between the location of cell i and any of the points on the curve z(y). Our objective function is J= \sum_{k=1}^M \tanh ( (d_i - r_0)  \beta ).  Here, r_0 represents the average radius of a cell and \beta controls the sharpness of the error function near that boundary, M is the total number of cells in the volume. For a give sent of points, we used Matlab’s fminsearch to find the optimal parameters for the curve.

How much improvement in yield can we expect using surface sampling versus just one plane?

We ran a few simulations where the number of points is uniformly distributed within the volume and calculated the fraction of cells we can intersect as a function of the number of harmonics used. Zero harmonics means just the horizontal plane that intersects the maximum number of cells.yield  The graph on the left shows the results.

Even in the simple case of a uniform distribution one can more than double the yield expected from a single plane by having a few (~5-6) harmonics. In other words, using surface sampling we can double the number of cells with respect to a horizontal plane without any penalty in temporal resolution.  Not bad at all.

We will re-do this analysis with some actual volumetric data from our Lab soon. I suspect this estimate represents a lower bound on what can actually be achieved.


Knobby updates

The last release of Scanbox provides a mechanism to update the firmware in Knobby and provides a few fixes to the existing version.  We will be using this mechanism to deploy future improvements.

The present version fixes a bug that incorrectly moved the objective to its original position when the X, Y, or Z axes where moved right after a Zero with vertical alignment was performed.  It also provides a way to cancel a Zero/Store/Recall function if they were triggered by mistake.  To cancel you simply have to touch the same button once again.

The new version also adjusts the hit areas on the touchscreen for the Lock/Unlock button and the XYZ menu selection for the Zero command, which were slightly off causing some unnecessary frustration.

To update Knobby’s firmware proceed as follows.

After downloading the latest Scanbox versions use pathtool in Matlab to ensure all the sub-directories within the distribution are added to the path.  Then within Matlab, type “knobby_update”.  If everything look Ok you will see something like the output below.  Your Knobby will reboot and you can then start Scanbox and start using it.

>> knobby_update
Knobby Firmware Update (dlr - 5/6/2016)
Reset Arduino Due...
Atmel SMART device 0x285e0a60 found
Device : ATSAM3X8
Chip ID : 285e0a60
Version : v1.1 Dec 15 2010 19:25:04
Address : 524288
Pages : 2048
Page Size : 256 bytes
Total Size : 512KB
Planes : 2
Lock Regions : 32
Locked : none
Security : false
Boot Flash : false
Erase flash
done in 0.030 seconds

Write 54480 bytes to flash (213 pages)

[ ] 0% (0/213 pages)
[== ] 9% (21/213 pages)
[===== ] 19% (42/213 pages)
[======== ] 29% (63/213 pages)
[=========== ] 39% (84/213 pages)
[============== ] 49% (105/213 pages)
[================= ] 59% (126/213 pages)
[==================== ] 69% (147/213 pages)
[======================= ] 78% (168/213 pages)
[========================== ] 88% (189/213 pages)
[============================= ] 98% (210/213 pages)
[==============================] 100% (213/213 pages)
done in 11.410 seconds

Verify 54480 bytes of flash

[ ] 0% (0/213 pages)
[== ] 9% (21/213 pages)
[===== ] 19% (42/213 pages)
[======== ] 29% (63/213 pages)
[=========== ] 39% (84/213 pages)
[============== ] 49% (105/213 pages)
[================= ] 59% (126/213 pages)
[==================== ] 69% (147/213 pages)
[======================= ] 78% (168/213 pages)
[========================== ] 88% (189/213 pages)
[============================= ] 98% (210/213 pages)
[==============================] 100% (213/213 pages)
Verify successful
done in 10.177 seconds
Set boot flash true
CPU reset.


Installing knobby

Many of you will be receiving Knobby in the mail soon.

Installing it is easy.  Just follow these steps:

  1. Connect knobby to a USB port
  2. Open the Device Manager and check which COM port # knobby was assigned to (it is the one displaying an Arduino Due board).
  3. Open Matlab, edit scanbox_config.m and set the tri_knob variable to the corresponding COM port.  Save.
  4. Start Scanbox.


As Scanbox starts up you will see a welcome message on the screen and Knobby will be initialized.  Test that all axes work properly. Finally, uninstall the 3Dconnexion software and reboot your machine.  You are done!

Let me know if you have questions…

Bidirectional scanning in Scanbox

We have implemented bidirectional scanning to Scanbox. To switch between bidirectional and unidirectional scanning all you have to do is hit the toggle button within the “Scanner” panel.

The defaubidirectionallt setting is “U”, standing for unidirectional scanning; hitting the button will switch it to “B”, indicating bidirectional scanning.  You can only switch between the two modes while the microscope is not scanning.

In bidirectional mode scanning samples are obtained while the laser scans in both directions of motion of the resonant mirror, and lines are advanced at both edges of the scan. On the plus side, this means that you can scan the same area twice as fast. You will notice the frame rate box doubling its value when you switch from unidirectional scanning to bidirectional scanning.

However, bidirectional scanning has some drawbacks as well.  First, you should be aware that that the Pockels’ cell will be active during both phases of the scan, while in unidirectional scanning it was active only in one direction. The result is that you will be delivering twice the amount of power onto the tissue, which may limit the length of your experiments due to potential photo-damage. Thus, use bidirectional scanning only if your indicators are fast enough and the scientific question you need to answer requires doubling the scanning speed.

Second, in bidirectional scanning even and odd lines are sampled in different directions, so they should be aligned properly to yield an image without spatial discontinuities. This alignment has to be fine tuned by the user in each setup, as there is variability in the resonant frequency of mirrors, the laser pulse frequency, and the phase of the sync pulse from the resonant mirror controller.

Scanbox allows for this fine tuning by changing a single variable in the configuration file named ‘ncolbi’ — a vector that allows alignment to be fined tuned separately for the three magnification factors.  This is necessary as well because the resonant frequency changes slightly with amplitude.

Once properly tuned, Scanbox performs compensation for non-uniform sampling and the alignment of even/odd lines during bidirectional scanning in real time.  Below is the mean image of 100 frames collected under bidirectional scanning.  You can see the alignment is very good by looking at the fine vertical processes in the image.

Alignment of even/odd lines in bidirectional scanning t 31 frames per second.

A final drawback of bidirectional scanning is that your file size will roughly double. This means that all other processing will also take longer — from aligning the images to extracting the signals.

Having said this, the faster rates achieved in bidirectional scanning will be helpful when coupled with the ability to do volumetric imaging by means of the optotune lens.

The bidirectional mode of Scanbox is now in beta testing.  I have not fully evaluated the extent to which other features of Scanbox, such as real time processing and image stabilization work in bidirectional mode. I welcome feedback from brave users who are willing to test bidirectional mode in their setups.

If you plan on giving bidirectional scanning a try let me know how it goes!  The updated code will be in Scanbox Github shortly.