I tried that, so something odd must be happening [no errors, just no ability to close the input images short of killing imageJ]

My crudely hacked code should reproduce the issue with any open image (stack) as input.

see below

‘’’

Haider Khan - haiderriazkhan@hotmail.com *

Ruthazer Lab, Montreal Neurological Institute. *

McGill University *

*

Copyright © 2015 Haider Riaz Khan *

*

The CANDLE algorithm is described in: *

*

P. Coupe, Martin Munz, Jose V.Manjon, Edward Ruthazer, D.Louis Collins.*

A CANDLE for a deeper in-vivo insight. Medical Image Analysis, *

16(4):849-64 (2012). *

mods V.Bindokas for macro or batchmode

’’’

from ij import IJ, ImageStack, ImagePlus

from ij.plugin import Filters3D

from ij.process import StackStatistics

import array

import time

from ij.gui import GenericDialog

from ij.io import FileSaver

import sys

import NativeCodeJNA

import InverseAnscombe

from ij import IJ, WindowManager

beta=0.05

patchradius=1

searchradius=5

```
# get input image
```

# InputImg = IJ.openImage();

InputImg = IJ.getImage()

titl = InputImg.getTitle()

```
# Get Input Image Statistics
```

InStats = StackStatistics(InputImg)

# print “mean:”, InStats.mean, “minimum:”, InStats.min, “maximum:”, InStats.max

```
# get the image stack within the ImagePlus
```

InputStack = InputImg.getStack()

z = InputImg.getNSlices()

```
# Instantiate 3D Median Filter plugin
```

f3d = Filters3D()

```
# Start of 3D Median Filter
# Retrieve filtered stack
```

medianFilteredStack = f3d.filter(InputStack, f3d.MEDIAN, 2, 2, 2)

```
# Construct an ImagePlus from the filtered stack
```

medianFilteredImage = ImagePlus(“MedianFiltered-Image”, medianFilteredStack)

# End of 3D Median Filter

```
# get image dimensions
```

x = medianFilteredImage.width

y = medianFilteredImage.height

```
# Get Image Statistics after Median 3D Filter
```

medianFilterStats = StackStatistics(medianFilteredImage)

```
# Anscombe transform to convert Poisson noise into Gaussian noise
```

IJ.run(medianFilteredImage, “32-bit”, “”);

IJ.run(medianFilteredImage, “Add…”, “value=0.375 stack”);

IJ.run(medianFilteredImage, “Square Root”, “stack”);

IJ.run(medianFilteredImage, “Multiply…”, “value=2 stack”);

IJ.run(InputImg, “32-bit”, “”);

IJ.run(InputImg, “Add…”, “value=0.375 stack”);

IJ.run(InputImg, “Square Root”, “stack”);

IJ.run(InputImg, “Multiply…”, “value=2 stack”);

```
# End of Anscombe transform
```

Stats = StackStatistics(medianFilteredImage)

medianFilteredStack = medianFilteredImage.getStack()

InputStack = InputImg.getStack()

```
# Get the Input and filtered Images as 1D arrays
```

medfiltArray = array.array(‘f’)

InputImgArray = array.array(‘f’)

for i in xrange(1 , z + 1):

ip = medianFilteredStack.getProcessor(i).convertToFloat()

ip2 = InputStack.getProcessor(i).convertToFloat()

pixels = ip.getPixels()

pixels2 = ip2.getPixels()

medfiltArray.extend(pixels)

InputImgArray.extend(pixels2)

InputImg.flush()

```
# Noise Estimation and Non-Local Means Filter
```

fimg = NativeCodeJNA.NativeCall(InputImgArray, medfiltArray, int(searchradius), int(patchradius), beta , int(x), int(y), int(z))

```
# Optimal Inverse Anscombe Transform
```

fimg = InverseAnscombe.OVST(fimg)

outputstack = ImageStack(x, y, z )

for i in xrange(0, z):

# Get the slice at index i and assign array elements corresponding to it.

outputstack.setPixels(fimg[int(i*x*y):int((i+1)*x*y)], i+1)

outputImp = ImagePlus((“cndl-”+titl), outputstack)

# print “OutputImage Stats:”

Stats = StackStatistics(outputImp)

# print “mean:”, Stats.mean, “minimum:”, Stats.min, “maximum:”, Stats.max

outputImp.setDisplayRange(Stats.min, Stats.max)

outputImp.show()

fs = FileSaver(outputImp)

fs.save()

outputImp.close()

InputImg.close();

IJ.run(“Close All”, “”);