ImageProcessor

public class ImageProcessor

ImageProcessor is a helper class for preprocessing and postprocessing TensorImage. It could transform a TensorImage to another by executing a chain of ImageOperator.

Example Usage:

   ImageProcessor processor = new ImageProcessor.Builder()
       .add(new ResizeOp(224, 224, ResizeMethod.NEAREST_NEIGHBOR)
       .add(new Rot90Op())
       .add(new NormalizeOp(127.5f, 127.5f))
       .build();
   TensorImage anotherTensorImage = processor.process(tensorImage);
 

WARNING: Instances of an ImageProcessor are not thread-safe with updateNumberOfRotations(int). Updating the number of rotations and then processing images (using SequentialProcessor.process(T)) must be protected from concurrent access. It is recommended to create separate ImageProcessor instances for each thread. If multiple threads access a ImageProcessor concurrently, it must be synchronized externally.

Nested Classes

class ImageProcessor.Builder The Builder to create an ImageProcessor, which could be executed later. 

Public Methods

RectF
inverseTransform(RectF rect, int inputImageHeight, int inputImageWidth)
Transforms a rectangle from coordinates system of the result image back to the one of the input image.
PointF
inverseTransform(PointF point, int inputImageHeight, int inputImageWidth)
Transforms a point from coordinates system of the result image back to the one of the input image.
TensorImage
process(TensorImage image)
Processes a TensorImage object with prepared TensorOperator.
void
updateNumberOfRotations(int k)
Updates the number of rotations for the first Rot90Op in this ImageProcessor.
synchronized void
updateNumberOfRotations(int k, int occurrence)
Updates the number of rotations for the Rot90Op specified by occurrence in this ImageProcessor.

Inherited Methods

Public Methods

public RectF inverseTransform (RectF rect, int inputImageHeight, int inputImageWidth)

Transforms a rectangle from coordinates system of the result image back to the one of the input image.

Parameters
rect the rectangle from the result coordinates system.
inputImageHeight the height of input image.
inputImageWidth the width of input image.
Returns
  • the rectangle with the coordinates from the coordinates system of the input image.

public PointF inverseTransform (PointF point, int inputImageHeight, int inputImageWidth)

Transforms a point from coordinates system of the result image back to the one of the input image.

Parameters
point the point from the result coordinates system.
inputImageHeight the height of input image.
inputImageWidth the width of input image.
Returns
  • the point with the coordinates from the coordinates system of the input image.

public TensorImage process (TensorImage image)

Processes a TensorImage object with prepared TensorOperator.

Parameters
image
Throws
IllegalArgumentException if the image is not supported by any op.

public void updateNumberOfRotations (int k)

Updates the number of rotations for the first Rot90Op in this ImageProcessor.

WARNING:this method is not thread-safe. Updating the number of rotations and then processing images (using SequentialProcessor.process(T)) must be protected from concurrent access with additional synchronization.

Parameters
k the number of rotations
Throws
IllegalStateException if Rot90Op has not been added to this ImageProcessor

public synchronized void updateNumberOfRotations (int k, int occurrence)

Updates the number of rotations for the Rot90Op specified by occurrence in this ImageProcessor.

WARNING:this method is not thread-safe. Updating the number of rotations and then processing images (using SequentialProcessor.process(T)) must be protected from concurrent access with additional synchronization.

Parameters
k the number of rotations
occurrence the index of perticular Rot90Op in this ImageProcessor. For example, if the second Rot90Op needs to be updated, occurrence should be set to 1.
Throws
IndexOutOfBoundsException if occurrence is negative or is not less than the number of Rot90Op in this ImageProcessor
IllegalStateException if Rot90Op has not been added to this ImageProcessor