ImageCalculator and frustration

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ImageCalculator and frustration

Fred Damen
Greetings,

The Java statment:
(new ImageCalculator).run("Add 32-bit stack", sumimp, tmpimp);
will quietly do nothing if sumimp and tmpimp are int16, i.e., sumimp is
unchanged.  I realize the stupidity on my part, but this is not what I
expected.  And each time I run into it I waste time trying to figure out
why the program that calls it seems broken.  Thus I though I would
document this for others.

Note that when the equivalent is run from the GUI menus, the
ImageCalculator will turn on the "create" option and create a 32-bit image
in a new window, even though the "create" option was deselected.

Hope this helps someone else,

Fred

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageCalculator and frustration

Wayne Rasband-2
> On Sep 4, 2020, at 4:05 PM, Fred Damen <[hidden email]> wrote:
>
> Greetings,
>
> The Java statment:
> (new ImageCalculator).run("Add 32-bit stack", sumimp, tmpimp);
> will quietly do nothing if sumimp and tmpimp are int16, i.e., sumimp is
> unchanged.

The run() function returns the 32-bit stack, so you need to use

   sumimp = (new ImageCalculator).run("Add 32-bit stack", imp1, imp2);

There is a static version of run() that is easier to use:

  sumimp = ImageCalculator.run(imp1, imp2, "Add 32-bit stack”);

The ImageJ 1.53e15 daily build fixes a bug that caused run() to return null if the operation argument did not contain 'create' or '32-bit’. Here is a script that reproduces the bug:

  imp1 = IJ.createImage("1", "16-bit black", 400, 200,1);
  ip = imp1.getProcessor();
  ip.setFontSize(100);
  ip.setColor(Color.white);
  ip.drawString("1", 40, 150);
  imp2 = IJ.createImage("2", "16-bit black", 400, 200, 1);
  ip = imp2.getProcessor();
  ip.setFontSize(100);
  ip.setColor(Color.white);
  ip.drawString("2", 240, 150);
  imp3 = ImageCalculator.run(imp1, imp2, "Add");
  imp3.show();

-wayne


> I realize the stupidity on my part, but this is not what I
> expected.  And each time I run into it I waste time trying to figure out
> why the program that calls it seems broken.  Thus I though I would
> document this for others.
>
> Note that when the equivalent is run from the GUI menus, the
> ImageCalculator will turn on the "create" option and create a 32-bit image
> in a new window, even though the "create" option was deselected.
>
> Hope this helps someone else,
>
> Fred

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html