Back to ObjectJ Examples
Download Stabilize in Chunks
version 7 21-oct-2016
If a movie is "shaky", this macro possibly can stabilize it. You need a fiducial point (thresholdable particle) in the image that does not change position during a certain time window (chunk) of the movie.
The time window is defined by two rectangular rois, one at the beginning and one at the end of the desired time window. These rois have same postition and size.
Create a rectangular roi within th The user can limit space and time within which a particle can serve 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.
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.
Open StabilizeChunks-5.txt in ImageJ
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 that so that the reference particle is the only 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 
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 
Roi will appear red and stored as second roi in RoiManager
Choose Plugins>Macros> Stabilize Chunk 
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.
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).