[ImageJ-devel] Simple usage of ImageJ2 and ImgLib2
Curtis Rueden
ctrueden at wisc.edu
Fri Aug 10 10:19:20 CDT 2012
Hi Padraig,
> With a view to moving to imgLib2 and ImageJ2 I have been going through the
> Javadoc to try to display an image perform more complicated tasks.
We have added a simple tutorial on how to load and display a dataset in
ImageJ2:
https://github.com/imagej/imagej-tutorials/tree/master/load-and-display-dataset
You use the IOService to read in a Dataset, which is the data portion of an
ImagePlus (no display or UI attached). You can then choose to display that
dataset if you want using the DisplayService.
> Ideally I would like to use Swing and get a Canvas containing the image
> and to be able to put this on a JFrame.
We have focused a lot on headless operation so far, so you can create a
headless ImageJ context, load a dataset, and create a display for that
dataset, all headless. And if you plug in the Swing (or other) UI, the
display will be automatically visualized using that interface.
However, thus far, we have not focused on an API for manually working with
UI-specific objects such as JPanels. We really need another layer of
services for that—in this case, probably a SwingService that can deliver
things like SwingDisplayPanels and SwingDisplayWindows on demand.
At the moment you could do something like the following, but there are
still bugs:
final IOService ioService = context.getService(IOService.class);
final Dataset data = ioService.loadDataset("data.tif");
final ImageDisplay display = new DefaultImageDisplay();
display.setContext(context);
display.display(data);
final ThreadService threadService = context.getService(ThreadService.class);
threadService.queue(new Runnable() {
@Override
public void run() {
final SwingImageDisplayViewer displayViewer =
new SwingSdiImageDisplayViewer();
final SwingDisplayWindow displayWindow = new SwingDisplayWindow();
displayViewer.view(displayWindow, display);
final SwingDisplayPanel displayPanel = displayViewer.getPanel();
final JFrame myFrame = new JFrame("My Frame");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.getContentPane().setLayout(new BorderLayout());
myFrame.getContentPane().add(displayPanel);
myFrame.pack();
myFrame.setVisible(true);
}
});
And it is certainly not the final API for this layer of functionality.
I have gone through the ImageJ2 javadoc and I have found a range of classes
> that seem relevant such as Defaultdataset, SwingSdiImageDisplayViewer,
> SwingDisplayPanel but
We are working on fleshing out the javadoc more, but ultimately tutorials
are going to be a better route to learning the system if you don't already
have some grounding in the basic ImageJ2 design. There will be some new
tutorials in the next few weeks, with many more by the beta5 release in
October.
I keep running into errors with Services that don't exist because I am
> probably not using ImageJ2 as intended.
Those errors are likely due to your classpath configuration. Are you using
Maven for managing your project dependencies? If not, for simplicity, you
could try using the imagej-2.0.0-SNAPSHOT-all.jar bundle of everything in
one JAR; see this FAQ entry for pros and cons:
http://developer.imagej.net/faq#n213
Regards,
Curtis
On Mon, Jul 16, 2012 at 3:13 AM, Padraig Looney <padraig.looney at gmail.com>wrote:
> Dear list,
>
> Apologies if this posting is not in the correct place but I seem to have
> hit a brick wall in moving to ImgLib2 and ImageJ2.
>
> I have used ImageJ 1 without the the user interface for a variety of
> software projects. In Image J to open an Image I would use
>
> Opener opener = new opener();
> Imageplus imp = opener.openImage("someFile");
> imp.show();
>
> and from there I could perform the processing and change the display etc.
>
> With a view to moving to imgLib2 and ImageJ2 I have been going through the
> Javadoc to try to display an image perform more complicated tasks. So I
> have found this example among others on the Imglib2 site but in the imgLibs
> package there is no ImageJFunctions anymore.
>
> public < T extends RealType< T > & NativeType< T > > Example1b()
> throws ImgIOException, IncompatibleTypeException
> {
> // define the file to open
> File file = new File( "DrosophilaWing.tif" );
>
> // open with ImgOpener using an ArrayImgFactory, here the return
> type will be
> // defined by the opener
> // the opener will ignore the Type of the ArrayImgFactory
> ImgFactory< ? > imgFactory = new ArrayImgFactory< T >();
> Img< T > image = new ImgOpener().openImg( file.getAbsolutePath(),
> imgFactory );
>
> // display it via ImgLib using ImageJ
> ImageJFunctions.show( image );
>
> // open with ImgOpener as Float using a CellImgFactory, it will
> be opened as float
> // independent of the type of the image
> // to enforce to open it as FloatType, an instance of FloatType
> has to be passed along
> Img< FloatType > imageFloat = new ImgOpener().openImg(
> file.getAbsolutePath(),
> new CellImgFactory< FloatType >( 10 ), new FloatType() );
>
> // display it via ImgLib using ImageJ
> ImageJFunctions.show( imageFloat );
> }
>
> Ideally I would like to use Swing and get a Canvas containing the image
> and to be able to put this on a JFrame. I have gone through the ImageJ2
> javadoc and I have found a range of classes that seem relevant such as
> Defaultdataset, SwingSdiImageDisplayViewer, SwingDisplayPanel but I keep
> running into errors with Services that don't exist because I am probably
> not using ImageJ2 as intended.
>
> Many thanks
>
> Padraig Looney
> Medical Physicist
> Royal Surrey County Hospital
>
>
>
>
>
> _______________________________________________
> ImageJ-devel mailing list
> ImageJ-devel at imagej.net
> http://imagej.net/mailman/listinfo/imagej-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20120810/fdda7bb2/attachment.html>
More information about the ImageJ-devel
mailing list