Resample 3D data along a plane and convert to IJ1 ImagePlus

Dear all,

Problem
Consider a 3D image (1 channel for simplicity). Define a plane, for instance using 3 points, and then resample the image along the normal to this plane. Eventually, obtain an imageJ1 image.

Application:
A non-isotropic object in 3D, e.g. a microtubule arrangment (spindle, multipolar spindle, …), and we would like to create a resampled image along the main plane of the object. With this image the user can then extract further properties such as line-profiles, etc. Also you can use all the IJ1 tools

I guess one way is to use BDV tools for it. Could some of the developers and user of BDV (e.g. @tpietzsch, @NicoKiaru, @Christian_Tischer) point me to where to look at?
The points could be defined in BDV directly or in ImageJ1 and just use the BDV tools for the resampling.

Thanks

Antonio

3 Likes

Hello @apoliti,

So one option is available if you activate the bigdataviewer-playground update site

Here is a sample script which demos how it works with the mitosis example dataset:

// Example of image 3D reorientation
//  A mitosis is reoriented such as centrosomes  are aligned in the Z axis at the center
// of the resampled image
//
// * 5D stack supported
// * Metadata matters ! Make sure Image properties are correct (Image>Properties...)
// * This scripts requires bigdataviewer-playground update site:
// 
// Github repo:
// - https://github.com/bigdataviewer/bigdataviewer-playground
// 
// Update site:
// - https://biop.epfl.ch/Fiji-Bdv-Playground/
// 
// The 3D resampling plugin can be found in the search bar or in 
// Image>Stacks>Rotation 3D Resample

// Open sample mitosis image
run("Mitosis (5D stack)");

// Clears roiManager :
if (roiManager("count")!=0) {
	roiManager("deselect");
	roiManager("Delete");
}

//  the first two rois, which should be unique points, are 
// used to define the Z axis of the rotated image

// Sets two point roi at centrosomes
makePoint(62, 43, "small yellow hybrid");
Roi.setPosition(1, 3, 1);
roiManager("Add");

makePoint(101, 158, "small yellow hybrid");
Roi.setPosition(1, 5, 1);
roiManager("Add");

// Performs resampling in 3D -> a cached virtual image is returned
run("Rotation 3D Resample", 
	"radiusx=5.0 "+ // Half width in physical unit (here microns)
	"radiusy=6.0 "+ // Half height in physical unit (here microns)
	"radiusz=8.0 "+ // Half thickness in physical unit (here microns)
	"voxfx=0.1 "+   // Voxel size in X in the output image in physical unit (microns)
	"voxfy=0.1 "+   // Voxel size in Y in the output image -> should be equal to voxfx in ij1
	"voxfz=0.1 "+   // Voxel size in Z in the output image in physical unit (microns)
	"alignx=true "+ // Does an extra rotation in Z after first reorientation to maintain
					// an extra axis unchanged, (try it)
	"interpolate=false"); // Interpolate or not pixels values from the original image

From:

To:

For big images, it’s reasonably fast to obtain the resampled image window, since you get a virtual stack. Duplicating it can take a lot time because it will require computing all slices sequentially. Note that the virtual stack is cached, so if you go back to a slice that has already been computed once, it should reappear very fast.

If you need a cropped version in c and t, a working strategy is to make the virtual stack with all channels and timepoints, and then duplicating only the requires channels and timepoints.

If you need a different reorientation, then there’s a way to do it in bigdataviewer directly, with a transform defined either interactively by the user or programmatically.

Best,

Nico

3 Likes

Here’s a way to do something similar interactively using BigDataViewer:

It’s pretty slow, I’m not exactly sure why, but I think it’s because I’m using a slow demo BigDataServerserver.

// Example of bigdataviewer 3D image reorientation
// and export in ImageJ1
//
// Bigdataviewer playground is a required update site.
//
// Github repo:
// - https://github.com/bigdataviewer/bigdataviewer-playground
// 
// Update site:
// - https://biop.epfl.ch/Fiji-Bdv-Playground/
// 


waitForUser("Opens dataset", "Click ok to connect to remote BigDataServer");
// Opens a demo dataset from a public BigDataServer
// See https://youtu.be/LHI7vXiUUms?t=4072 if you would like to know how to open any other
// bioformats supported file
run("BDVDataset [BigDataServer]", 
	"urlserver=http://bds.mpi-cbg.de:8081 "+
	"datasetname=Pdu_E1_H2BeGFP_CAAXmCherry_0123_20130315_224014.corrected");

datasetSourcePath = "http://bds.mpi-cbg.de:8081/Pdu_E1_H2BeGFP_CAAXmCherry_0123_20130315_224014.corrected/"

// Set bdv sources color (Nuclei channel)
run("Set Sources Color", 
	"sacs="+datasetSourcePath+">Channel>1 "+
	"color=255,0,255");

// Set bdv sources color (Membrane channel)
run("Set Sources Color", 
	"sacs="+datasetSourcePath+">Channel>3 "+
	"color=0,255,0");

waitForUser("Display dataset in bdv window", "Click ok then wait for the loading and autocontrast... (~5 secs)");
// Show sources in BigDataViewer
run("BDV - Show Sources (new Bdv window)", 
	"sacs="+datasetSourcePath+" "+	
	"autocontrast=true adjustviewonsource=true is2d=false "+
	"windowtitle=[Demo Dataset] interpolate=false "+
	"ntimepoints=10 projector=[Sum Projector]");

waitForUser("Reorientation", "Reorient the dataset in 3D then press ok");

run("BDV - Log view transform", ""); // Prints the current affine transform 3D corresponding to the current view


waitForUser("Export", "Click ok to start the IJ1 virtual stack export (see code for export parameters)");
// Exports the current bdv view
run("Current BDV View To ImagePlus (Basic)", 
	"capturename=Reoriented_Cropped_BdvDataset "+
	"zsize=20.0 "+ // physical unit
	"timepointbegin=0 "+ // cropping in time
	"numberoftimepoints=2 "+
	"samplingxyinphysicalunit=5.0 "+ // final xy voxel size ( physical unit )
	"samplingzinphysicalunit=10.0 "+ // final z voxel size ( physical unit )
	"interpolate=false"); // Do not interpolate the original source

2 Likes

Thanks @NicoKiaru, I will try it. For the spindle example, one may want to do the other way around. So basically go from the results back to something like the original image.

For instance the user marks 3 points that define the plane we want to be in XY. The resampling is along the normal to the plane.

Fortunately, with some extra code I can use the plugin as it is. Users specifies plane points from which one computes the normal and then pass the normal to rotation 3D resample. I will post the results when I am done.

Thanks also for the BDV code. Very useful

Antonio

2 Likes