Visualizing velocity fields

Dear ImageJ team and community members,

I have a nifti volume with the following dimensions

256 256 1 1 2,

where the ‘2’ is for x and y coordinates for the vector pointing from the center of the corresponding voxel.

I would like to visualize this data as a 2D vector field in ImageJ.

Currently when I just open in ImageJ naively it opens it as a 2 channel image!

Could you kindly help me with this request.

Thank you so much!

@nadluru - the bio-formats importer should provide some level of support for nifti.

You can post a sample image here, but if Bio-Formats is opening your volume incorrectly then their bug reporting workflow is probably your best bet.

So @ctrueden pointed out that I probably misread the intent of your post… the problem being with visualization and not simply reading the data.

It looks like there are a couple options for plugins to visualize your data as a vector field:

I haven’t used either plugin personally, but since your data is opened as 2 channels, you may want to run Image>Color>Split Channels to get the 2 input images for PIV analysis.

1 Like

Hi @nadluru,
Thanks @hinerm for pointing to PIV analyzer. This work-of-youth however cannot do what @nadluru wants natively. You will still have to program something to make use of it.

Given the state of PIV analyzer, I would recommend instead writing something from scratch, tailored for your needs.

The VisAD library has support for flow vector visualization. I currently ship VisAD with the LOCI update site. It would be straightforward (less than 1 hour’s work) to add a flow vector visualization plugin that uses it.

Here is some sample code:

import javax.swing.*;
import visad.*;
import visad.java2d.*;

DisplayImpl display = new DisplayImplJ2D("display");

RealType[] types = {RealType.Latitude, RealType.Longitude};
RealTupleType earth_location = new RealTupleType(types);
RealType vis_radiance = RealType.getRealType("vis_radiance");
RealType ir_radiance = RealType.getRealType("ir_radiance");
RealType[] types2 = {vis_radiance, ir_radiance};
RealTupleType radiance = new RealTupleType(types2);
FunctionType image_tuple = new FunctionType(earth_location, radiance);

int size = 32;
FlatField imaget1 = FlatField.makeField(image_tuple, size, false);

display.addMap(new ScalarMap(RealType.Latitude, Display.YAxis));
display.addMap(new ScalarMap(RealType.Longitude, Display.XAxis));
ScalarMap flowMap = new ScalarMap(vis_radiance, Display.Flow1X);
display.addMap(new ScalarMap(ir_radiance, Display.Flow1Y));

FlowControl flowControl = (FlowControl) flowMap.getControl();

DataReferenceImpl ref_imaget1 = new DataReferenceImpl("ref_imaget1");
display.addReference(ref_imaget1, null);

JFrame frame = new JFrame("Flow vectors");
JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());

If you activate the LOCI update site, you can run the above as a BeanShell script in the Script Editor just for fun.

And here is a screenshot:

@nadluru: Before I take this work any further, is this what you are looking for?


Thanks so much for this info Curtis and others leading up to this solution. I will play with the scripts.

So, I take it that the visualization in the screenshot above is along the lines of what you are looking for? If so, I would be happy to help you develop the above code snippet further. VisAD has a learning curve but it is very powerful. Getting more VisAD-based plugins into ImageJ under the “VisBio” moniker is one of my long-term goals for the project.

1 Like


That would be so great! Because of the delay in the replies I had resorted to other tools temporarily but using ImageJ for as much of my image processing as I can is of definite interest to me. I am in a crunch mode right now with some other projects and should be able to get back into ImageJ diving after mid November. Thanks again!

This is also great!

Thanks again Curtis!

1 Like