Norbert Vischer
University of Amsterdam
version 7.2
25-june-2021
If a movie is "shaky", this macro possibly can stabilize it. You need a thresholdable particle in the image of which you asssume that it was stable during a certain time window (chunk) of the movie.
The time window is defined by two rectangular rois, a green one at the beginning and a red one at the end of the desired time frames. These two rois have same postition and size, and limit space and time within which the particle serves as fiducial point. Within the chosen roi and time window, the particle analyser detects the current x-y position of the largest particle found and identifies it as fiducial object. It records its x-y position that is later used for compensating any undesired movement. Once a chunk is stabilized, you can continue to to stabilize a different chunk using a different fiducial particle. Replace "interpolation=Bilinear" by "interpolation=None" (~line 157) if you need to avoid interpolation.
Hyperstacks:
If used for hyperstacks, fiducial objects must be in channel 1, and all other channels will undergo the same translation. Note that the hyperstack must not be 5D (i.e. either nChannels or nFrames must be 1).
Use Image>Color>Arrange Channels if necessary.
Installation:
Open StabilizeChunks-7.2.txt in ImageJ and choose menu Macros>Install Macros.
Usage:
Open the unstable movie and adjust threshold so that a refence particle is well defined as "foreground" (red color in Fig 1).
Create a rectangular roi so that the reference particle is the only (or at least largest) object inside the roi during the desired stabilisation period.
Navigate to the start slice where stabilisation should start and choose
Plugins>Macros> Mark Chunk Begin [1]
Roi will appear green and stored as first roi in RoiManager.
Without changing the roi, navigate to the end of stabilisation period and choose
Plugins> Macros> Mark Chunk End [2]
Roi will appear red and stored as second roi in RoiManager
Choose Plugins>Macros> Stabilize Chunk [3]
Program will now calculate the particle's trajectory, and ask for confirmation. Before clicking 'OK', check the plot that shows the x and y-deviation that needs to be corrected, and the trajectory of the movement, shown as segmented line in the image.
Stabilization is then performed by sub-pixel translation. In order to avoid any “jump” after the end of the chunk, also slices beyond the chunk end will be translated.
Any black borders will be cropped.
Fig 1:
Unstable movie: slice 37 was used as start point and slice 85 as endpoint.
Red (thresholded) particle inside the roi has travveled from left to right in slice 85.
Fig 2: Before translating slices 38 .. 250, the particle’s trajectory during slice 37 .. 85 is shown as segmented line, asking for confirmation (OK or Esc).