Puzzling behaviour in image display

Hi all,

Trying the imglib2 views after the learnathon to implement a first command I am a little puzzled by the fact that the two different display methods don’t work in the same fashion. The ij.ui().show("extended", interval); method does not display the negative parts of the extended view. Is this intended behaviour, a limitation, a bug or am I just getting something obvious wrong?
I actually wanted to omit the ImageJFunctions part since it seems to be a transient solution only if I remember correctly.
Any hint is greatly appriciated :slight_smile:

import java.io.File;

import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.ui.UIService;

import ij.IJ;
import ij.ImagePlus;
import net.imagej.ImageJ;
import net.imagej.ops.OpService;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Intervals;
import net.imglib2.view.Views;

@Plugin(type = Command.class, menuPath = "Plugins>TestViews")
public class MyPluginClassName<T extends RealType<T>, O> implements Command {
    private Img img;
    private ImageJ ij;

	public void run() {
		final RandomAccessible< ARGBType > extendedView = Views.extendBorder( img );
		final RandomAccessibleInterval< ARGBType > interval = Views.interval( extendedView, Intervals.createMinSize( img.min(0)-100, img.min(1)-100, img.max(0)+200, img.max(1)+200) );
		ImageJFunctions.show( interval, "interval" );	//works and displays the extended view 
    	ij.ui().show("extended", interval); //only shows the extended view in the positive direction


       public static void main(final String... args) throws Exception {
        // create the ImageJ application context with all available services
        final ImageJ ij = new ImageJ();

        final File file = null;
        if (file == null) {
            final ImagePlus imp = IJ.openImage("C:/Users/broch/Desktop/blobs.png");
            final RandomAccessibleInterval< ARGBType > img = ImageJFunctions.wrap( imp );
            ImageJFunctions.show( img, "img" );
            // invoke the plugin
            ij.command().run(MyPluginClassName.class, true);

1 Like

I’m not sure if this is intended, but the difference between the two methods is that ImageJFunctions.show() will call Views.zeroMin() internally when the input interval has a non-zero min:

The UIService.show() method doesn’t seem to have this default behavior.

As a conclusion, you should be able to make these two method behave “the same” by making sure you are providing a zero-min interval:

final RandomAccessibleInterval< ARGBType > interval = Views.zeroMin( Views.interval( .... )

Thanks @imagejan

I’ll test that :slight_smile:

I tested with this small Groovy script:

#@ Img img
#@ UIService ui

import net.imglib2.util.Intervals
import net.imglib2.view.Views

extended = Views.extendBorder(img)
interval = Views.zeroMin( Views.interval(extended, Intervals.createMinSize( img.min(0)-100, img.min(1)-100, img.max(0)+200, img.max(1)+200) ) )
// interval = Views.interval(extended, Intervals.createMinSize( img.min(0)-100, img.min(1)-100, img.max(0)+200, img.max(1)+200) )

However, I’m a bit surprised because even ui.show() should lead to ImageJVirtualStack being called, so they should both create a new zero-min view. (I might’ve done a mistake in following the cascade of methods being called in the stack though…)

Maybe @ctrueden, @tpietzsch, @dietzc or others can explain?

I think this is the same issue as:

1 Like