public class Compute extends Object
IFunction
into an Image
. In essence, the IFunction
defines an operation with one or two pixels as arguments, such as Multiply
,
Divide
, etc. The inFloats(IFunction)
evaluates the function
and places the result in a new Image
. To specify a different type, use the
apply(IFunction, RealType, int)
, and for RGBALegacyType
, use
apply(IFunction, RGBALegacyType, int)
or inRGBA(IFunction)
.
The underlying machinery first inspects the IFunction
and all its nested
IFunction
instances, collecting all visible Cursor
instances,
using the method findImages(IFunction)
.
All Image
instances related to the found Cursor
instances are
inspected to ensure that their Container
are compatible.
If the Container
are not compatible, the content
of the images would not be iterated in a way that would make sense. So an Exception
will be thrown.
Finally, the results of evaluating the IFunction
are stored and returned in
an Image
. The dimensions of the returned image are the same as those of the
first image found. If the dimensions do not match, an error will eventually pop up, or
the computation result in images that have unexpected data in chunks of them (for example,
when there is an OutOfBoundsStrategy
that prevents an early error from occurring).
An example program: correct the background illumination of an image, given the associated brighfield and a darkfield images, and the mean value of the image:
public ImagescriptCorrectIllumination( final Image extends RealType>> img, final Image extends RealType>> brightfield, final Image extends RealType>> darkfield, final double mean) throws Exception { Image corrected = Compute.inFloats(1, new Multiply( new Divide( new Subtract(img, brightfield), new Subtract(brightfield, darkfield)), mean)); return corrected; }
Constructor and Description |
---|
Compute() |
Modifier and Type | Method and Description |
---|---|
static Image<RGBALegacyType> |
apply(IFunction op,
RGBALegacyType output,
int numThreads)
Execute the given
IFunction , which runs for each pixel,
and store the results in an Image of type RGBALegacyType . |
static <R extends RealType<R>> |
apply(IFunction op,
R output,
int numThreads)
|
static void |
checkContainers(Collection<Image<?>> images)
Ensure that the
Container of each Image of @param images is compatible
with all the others. |
static Set<Image<?>> |
findImages(IFunction op)
Find all images in @param op and nested
IFunction instances. |
static Image<DoubleType> |
inDoubles(IFunction op)
Execute the given
IFunction , which runs for each pixel,
and store the results in an Image of type DoubleType . |
static Image<DoubleType> |
inDoubles(Image<? extends RealType<?>> img)
Convenience method to avoid confusion with script wrappers that are themselves
Image
rather than IFunction ; this method ends up creating a copy of the image, in DoubleType . |
static Image<DoubleType> |
inDoubles(int numThreads,
IFunction op)
Execute the given
IFunction , which runs for each pixel,
and store the results in an Image of type DoubleType with
as many threads as desired. |
static Image<FloatType> |
inFloats(IFunction op)
|
static Image<FloatType> |
inFloats(Image<? extends RealType<?>> img)
|
static Image<FloatType> |
inFloats(int numThreads,
IFunction op)
|
static Image<RGBALegacyType> |
inRGBA(IFunction op)
Execute the given
IFunction , which runs for each pixel,
and store the results in an Image of type RGBALegacyType with
as many threads as desired. |
static Image<RGBALegacyType> |
inRGBA(Image<? extends RealType<?>> img)
Convenience method to avoid confusion with script wrappers that are themselves
Image
rather than IFunction ; this method ends up creating a copy of the image, in RGBALegacyType . |
static Image<RGBALegacyType> |
inRGBA(int numThreads,
IFunction op)
Execute the given
IFunction , which runs for each pixel,
and store the results in an Image of type RGBALegacyType with
as many threads as desired. |
public static final void checkContainers(Collection<Image<?>> images) throws Exception
Container
of each Image
of @param images is compatible
with all the others.Exception
public static final Set<Image<?>> findImages(IFunction op) throws Exception
IFunction
instances.Exception
public static final <R extends RealType<R>> Image<R> apply(IFunction op, R output, int numThreads) throws Exception
public static final Image<RGBALegacyType> apply(IFunction op, RGBALegacyType output, int numThreads) throws Exception
IFunction
, which runs for each pixel,
and store the results in an Image
of type RGBALegacyType
.op
- The IFunction
to execute.output
- An instance of the RGBALegacyType
type of the result image returned by this method.numThreads
- The number of threads for parallel execution.Exception
public static final Image<FloatType> inFloats(IFunction op) throws Exception
IFunction
, which runs for each pixel,
and store the results in an Image
of type FloatType
.
Uses as many concurrent threads as CPUs, defined by Runtime.availableProcessors()
.public static final Image<FloatType> inFloats(int numThreads, IFunction op) throws Exception
public static final Image<DoubleType> inDoubles(int numThreads, IFunction op) throws Exception
IFunction
, which runs for each pixel,
and store the results in an Image
of type DoubleType
with
as many threads as desired.public static final Image<DoubleType> inDoubles(IFunction op) throws Exception
IFunction
, which runs for each pixel,
and store the results in an Image
of type DoubleType
.
Uses as many concurrent threads as CPUs, defined by Runtime.availableProcessors()
.public static final Image<RGBALegacyType> inRGBA(int numThreads, IFunction op) throws Exception
IFunction
, which runs for each pixel,
and store the results in an Image
of type RGBALegacyType
with
as many threads as desired.public static final Image<RGBALegacyType> inRGBA(IFunction op) throws Exception
IFunction
, which runs for each pixel,
and store the results in an Image
of type RGBALegacyType
with
as many threads as desired.
Uses as many concurrent threads as CPUs, defined by Runtime.availableProcessors()
.public static final Image<FloatType> inFloats(Image<? extends RealType<?>> img) throws Exception
Image
rather than IFunction
; this method ends up creating a copy of the image, in FloatType
.Exception
public static final Image<DoubleType> inDoubles(Image<? extends RealType<?>> img) throws Exception
Image
rather than IFunction
; this method ends up creating a copy of the image, in DoubleType
.Exception
public static final Image<RGBALegacyType> inRGBA(Image<? extends RealType<?>> img) throws Exception
Image
rather than IFunction
; this method ends up creating a copy of the image, in RGBALegacyType
.
This method transforms an IFunction
operation that returns a double
for every pixel
into an RGBA image, by casting each double to an int
.Exception
Copyright © 2015–2021 Fiji. All rights reserved.