[ImageJ-devel] ImageJ2 scripting

Curtis Rueden ctrueden at wisc.edu
Mon Apr 27 13:42:09 CDT 2015


Hi Jan,

Here is another version of the script, which avoids wrapping each Dataset
in another ImgPlus (which the framework would then wrap into yet another
Dataset....):

   # @DisplayService display
   # @OpService ops
   # @net.imagej.Dataset inputData1
   # @net.imagej.Dataset inputData2

   inputData1.setName("my1")
   inputData2.setName("my2")
   display.createDisplay(inputData1)
   display.createDisplay(inputData2)

But note that you also don't need to explicitly call createDisplay. Any
output parameters of your script will automatically have displays created
for them. E.g.:

   # @OUTPUT net.imagej.Dataset outputData

Will be shown at the conclusion of the script.

Apologies for the appalling lack of documentation -- it would be great to
flesh out the wiki docs about all this.

HTH,
Curtis

On Mon, Apr 27, 2015 at 1:23 PM, Mark Hiner <hiner at wisc.edu> wrote:

> Hi Jan,
>
> >an error message is displayed: "A Dataset is required but none exist."
>
> This was due to limitations with the input preprocessor presenting the
> list of datasets. Since ImagePluses aren't explicitly tracked by the IJ2
> framework, having an ImagePlus recognized as a Dataset requires some extra
> layers. We had covered the single input case (which is why your first
> script worked) but not the general multi-input case. There is an issue
> tracking the multi-input
> <https://github.com/imagej/imagej-legacy/issues/106> case, which I
> resolved today. So this should work as intended in our next release - and
> thank you for the motivation to wrap this up!
>
> You can also manually enable ImagePlus <> Dataset synchronization to
> ensure ImagePluses always have a corresponding Dataset:
> http://imagej.net/Compatibility#Translation_of_data_structures
>
> >(where can this title be set, by the way?)
>
> For the multiple choice input selection, the labels are based on the name
> of the input type. Since the input type is Dataset, the Dataset name is
> used (which delegates to the wrapped ImgPlus). In your code you are
> applying labels to the Display, but not the underlying dataset - if you
> name the ImgPlus, or explicitly create a Dataset and set its name, that
> name will propagate up to the input chooser (and the Display). As a side
> note, you should use the net.imagej.ImgPlus instead of the net.imglib2.meta.
>
> An updated script would be:
>
>
>    # @DisplayService display
>    # @OpService ops
>    # @net.imagej.Dataset inputData1
>    # @net.imagej.Dataset inputData2
>
>    from net.imagej import ImgPlus
>
>    display.createDisplay(ImgPlus(inputData1, "my1"))
>    display.createDisplay(ImgPlus(inputData2, "my2"))
>
> Hope that helps. Let me know if you have any other questions.
>
> Best,
> Mark
>
> On Mon, Apr 27, 2015 at 8:58 AM, Jan Eglinger <jan.eglinger at gmail.com>
> wrote:
>
>> Dear all,
>>
>> *** TL;DR:
>> How do I proceed to get multiple input Datasets as ImageJ2 parameters
>> from open images in Fiji?
>> ***
>>
>> I was recently exploring ImageJ2 scripting in Fiji and found the
>> OpsThresholdIJ1Analyze template [1] in the script editor very helpful.
>>
>> When trying to get more than one @net.imagej.Dataset input parameter
>> however, I noticed some inconsistencies.
>> Let me try to illustrate with the two following scripts:
>>
>>     # @DisplayService display
>>     # @OpService ops
>>     # @net.imagej.Dataset inputData1
>>
>>     from net.imglib2.meta import ImgPlus
>>
>>     display.createDisplay("my1", ImgPlus(inputData1))
>>
>>
>> The above script re-displays the current image as expected (I tried with
>> the Blobs sample image open, which will be re-displayed with a non-inverted
>> LUT.)
>>
>> When I ask for two input datasets (right after a fresh start of Fiji with
>> only the Blobs sample image open):
>>
>>     # @DisplayService display
>>     # @OpService ops
>>     # @net.imagej.Dataset inputData1
>>     # @net.imagej.Dataset inputData2
>>
>>     from net.imglib2.meta import ImgPlus
>>
>>     display.createDisplay("my1", ImgPlus(inputData1))
>>     display.createDisplay("my2", ImgPlus(inputData2))
>>
>> an error message is displayed: "A Dataset is required but none exist."
>> The same error message is displayed when I open a second image in Fiji
>> before running the script.
>>
>> Now, when I run script #2 after script #1 was run at least once, I get a
>> dialog with two choices "InputData1" and "InputData2", both choice fields
>> containing "blobs.gif" and a number of "Untitled" entries (where can this
>> title be set, by the way?).
>>
>> I guess that a choice is only displayed if there are ImageJ2 datasets
>> (i.e. wrapped ImagePlus) already available. The single input case seems to
>> be special-cased as it auto-wraps the currently open image.
>>
>> So how do I proceed to get more than one input in ImageJ2 scripting from
>> open (ImageJ1-)images?
>>
>> Thanks for your advice,
>> Regards,
>> Jan
>>
>>
>> [1]:
>> https://github.com/imagej/imagej-legacy/blob/master/src/main/resources/script_templates/Python/OpsThresholdIJ1Analyze.py
>>
>> _______________________________________________
>> ImageJ-devel mailing list
>> ImageJ-devel at imagej.net
>> http://imagej.net/mailman/listinfo/imagej-devel
>>
>
>
> _______________________________________________
> 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/20150427/4122953b/attachment.html>


More information about the ImageJ-devel mailing list