bunwarpj
Class MiscTools

java.lang.Object
  extended by bunwarpj.MiscTools

public class MiscTools
extends java.lang.Object

Different tools for the bUnwarpJ interface.


Nested Class Summary
private static class MiscTools.ColorApplyTransformTile
          Class to apply transformation to color images in a concurrent way
private static class MiscTools.GrayscaleApplyTransformTile
          Class to apply transformation to grayscale images in a concurrent way
 
Constructor Summary
MiscTools()
           
 
Method Summary
static void adaptCoefficients(double xScale, double yScale, int intervals, double[][] cx, double[][] cy)
          Adapt B-spline coefficients to a scale factor
static void applyRawTransformationToSource(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel source, double[][] transformation_x, double[][] transformation_y)
          Apply a given raw transformation to the source image.
static ij.process.ImageProcessor applyTransformationMT(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel source, int intervals, double[][] cx, double[][] cy)
          Apply a given B-spline transformation to the source (gray-scale) image.
static void applyTransformationToSource(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel sourceR, BSplineModel sourceG, BSplineModel sourceB, int intervals, double[][] cx, double[][] cy)
          Deprecated.  
static void applyTransformationToSource(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel source, int intervals, double[][] cx, double[][] cy)
          Deprecated.  
static void applyTransformationToSourceMT(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel source, int intervals, double[][] cx, double[][] cy)
          Apply a given B-spline transformation to the source (gray-scale) image.
static void applyTransformationToSourceMT(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, int intervals, double[][] cx, double[][] cy)
          Apply a given B-spline transformation to the source (gray-scale) image.
static void composeElasticTransformations(ij.ImagePlus targetImp, int intervals, double[][] cx1, double[][] cy1, double[][] cx2, double[][] cy2, double[][] outputTransformation_x, double[][] outputTransformation_y)
          Compose two elastic deformations into a raw deformation.
static void composeElasticTransformationsAtPixelLevel(ij.ImagePlus targetImp, int intervals, double[][] cx1, double[][] cy1, double[][] cx2, double[][] cy2, double[][] outputTransformation_x, double[][] outputTransformation_y)
          Compose two elastic deformations into a raw deformation at pixel level.
static void composeRawElasticTransformations(ij.ImagePlus targetImp, int intervals, double[][] transformation_x_1, double[][] transformation_y_1, double[][] cx2, double[][] cy2, double[][] outputTransformation_x, double[][] outputTransformation_y)
          Compose a raw deformation and an elastic deformation into a raw deformation.
static void composeRawTransformations(int width, int height, double[][] transformation_x_1, double[][] transformation_y_1, double[][] transformation_x_2, double[][] transformation_y_2, double[][] outputTransformation_x, double[][] outputTransformation_y)
          Compose two raw transformations (Bilinear interpolation)
static void convertElasticTransformationToRaw(ij.ImagePlus targetImp, int intervals, double[][] cx, double[][] cy, double[][] transformation_x, double[][] transformation_y)
          Calculate the raw transformation mapping from B-spline coefficients.
static void convertRawTransformationToBSpline(ij.ImagePlus targetImp, int intervals, double[][] transformation_x, double[][] transformation_y, double[][] cx, double[][] cy)
          Convert the raw transformation mapping to B-spline coefficients.
static ij.process.ImageProcessor createDownsampled(ij.process.ImageProcessor source, float scale, float sourceSigma, float targetSigma)
          Create a downsampled ImageProcessor.
static void drawArrow(double[][] canvas, int x1, int y1, int x2, int y2, double color, int arrow_size)
          Draw an arrow between two points.
static void drawLine(double[][] canvas, int x1, int y1, int x2, int y2, double color)
          Draw a line between two points.
static void extractImage(ij.process.ImageProcessor ip, double[] image)
          Put the image from an ImageProcessor into a double array.
static void extractImage(ij.process.ImageProcessor ip, double[][] image)
          Put the image from an ImageProcessor into a double[][].
static void invertRawTransformation(ij.ImagePlus targetImp, double[][] transformation_x, double[][] transformation_y, double[][] inv_x, double[][] inv_y)
           
static void loadAffineMatrix(java.lang.String filename, double[][] affineMatrix)
          Load an affine matrix from a file.
static void loadPointRoiAsLandmarks(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, java.util.Stack<java.awt.Point> sourceStack, java.util.Stack<java.awt.Point> targetStack)
          Load point rois in the source and target images as landmarks.
static void loadPoints(java.lang.String filename, java.util.Stack<java.awt.Point> sourceStack, java.util.Stack<java.awt.Point> targetStack)
          Load landmarks from file.
static void loadRawTransformation(java.lang.String filename, double[][] transformation_x, double[][] transformation_y)
          Load a raw transformation from a file.
static void loadRawTransformation(java.lang.String filename, double[] transformation_x, double[] transformation_y)
          Load a raw transformation from a file.
static void loadTransformation(java.lang.String filename, double[][] cx, double[][] cy)
          Load a transformation from a file.
static int numberOfIntervalsOfTransformation(java.lang.String filename)
          Read the number of intervals of a transformation from a file.
static void Point(double[][] canvas, int y, int x, double color)
          Plot a point in a canvas.
static void printMatrix(java.lang.String title, double[][] array)
          Print a matrix in the command line.
static double rawWarpingIndex(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, double[][] transformation_x_1, double[][] transformation_y_1, double[][] transformation_x_2, double[][] transformation_y_2)
          Warping index for comparing two raw deformations (both transformations having same direction).
static double rawWarpingIndex(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, int intervals, double[][] cx_direct, double[][] cy_direct, double[][] transformation_x, double[][] transformation_y)
          Warping index for comparing elastic deformations with any kind of deformation (both transformations having same direction).
static void saveElasticTransformation(int intervals, double[][] cx, double[][] cy, java.lang.String filename)
          Save the elastic transformation.
static void saveRawTransformation(java.lang.String filename, int width, int height, double[][] transformation_x, double[][] transformation_y)
          Save a raw transformation
static ij.process.ImageProcessor scale(ij.process.ImageProcessor source, float scale)
          Scale an image with good quality in both up and down direction
static void showImage(java.lang.String title, double[][] array)
          Show an image in a new bUnwarpJ window.
static void showImage(java.lang.String title, double[] array, int Ydim, int Xdim)
          Show an image in a new bUnwarpJ window.
static void smoothForScale(ij.process.ImageProcessor source, float scale, float sourceSigma, float targetSigma)
          Smooth with a Gaussian kernel that represents downsampling at a given scale factor and sourceSigma.
static double warpingIndex(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, int intervals, double[][] cx_direct, double[][] cy_direct, double[][] cx_inverse, double[][] cy_inverse)
          Calculate the warping index between two opposite elastic deformations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MiscTools

public MiscTools()
Method Detail

applyTransformationToSource

public static void applyTransformationToSource(ij.ImagePlus sourceImp,
                                               ij.ImagePlus targetImp,
                                               BSplineModel source,
                                               int intervals,
                                               double[][] cx,
                                               double[][] cy)
Deprecated. 

Apply a given B-spline transformation to the source (gray-scale) image. The source image is modified. The target image is used to know the output size.

Parameters:
sourceImp - source image representation
targetImp - target image representation
source - source image model
intervals - intervals in the deformation
cx - x- B-spline coefficients
cy - y- B-spline coefficients

applyTransformationToSource

public static void applyTransformationToSource(ij.ImagePlus sourceImp,
                                               ij.ImagePlus targetImp,
                                               BSplineModel sourceR,
                                               BSplineModel sourceG,
                                               BSplineModel sourceB,
                                               int intervals,
                                               double[][] cx,
                                               double[][] cy)
Deprecated. 

Apply a given splines transformation to the source (RGB color) image. The source image is modified. The target image is used to know the output size.

Parameters:
sourceImp - source image representation
targetImp - target image representation
sourceR - image model of the source red channel
sourceG - image model of the source green channel
sourceB - image model of the source blue channel
intervals - intervals in the deformation
cx - x- B-spline coefficients
cy - y- B-spline coefficients

applyRawTransformationToSource

public static void applyRawTransformationToSource(ij.ImagePlus sourceImp,
                                                  ij.ImagePlus targetImp,
                                                  BSplineModel source,
                                                  double[][] transformation_x,
                                                  double[][] transformation_y)
Apply a given raw transformation to the source image. The source image is modified. The target image is used to know the output size.

Parameters:
sourceImp - source image representation
targetImp - target image representation
source - source image
transformation_x - x- mapping coordinates
transformation_y - y- mapping coordinates

warpingIndex

public static double warpingIndex(ij.ImagePlus sourceImp,
                                  ij.ImagePlus targetImp,
                                  int intervals,
                                  double[][] cx_direct,
                                  double[][] cy_direct,
                                  double[][] cx_inverse,
                                  double[][] cy_inverse)
Calculate the warping index between two opposite elastic deformations. Note: the only difference between the warping index and the consistency term formulae is a squared root: warping index = sqrt(consistency error).

Parameters:
sourceImp - source image representation
targetImp - target image representation
intervals - intervals in the deformation
cx_direct - direct transformation x- B-spline coefficients
cy_direct - direct transformation y- B-spline coefficients
cx_inverse - inverse transformation x- B-spline coefficients
cy_inverse - inverse transformation y- B-spline coefficients
Returns:
geometric error (warping index) between both deformations.

convertElasticTransformationToRaw

public static void convertElasticTransformationToRaw(ij.ImagePlus targetImp,
                                                     int intervals,
                                                     double[][] cx,
                                                     double[][] cy,
                                                     double[][] transformation_x,
                                                     double[][] transformation_y)
Calculate the raw transformation mapping from B-spline coefficients.

Parameters:
targetImp - target image representation
intervals - intervals in the deformation
cx - transformation x- B-spline coefficients
cy - transformation y- B-spline coefficients
transformation_x - raw transformation in x- axis (output)
transformation_y - raw transformation in y- axis (output)

convertRawTransformationToBSpline

public static void convertRawTransformationToBSpline(ij.ImagePlus targetImp,
                                                     int intervals,
                                                     double[][] transformation_x,
                                                     double[][] transformation_y,
                                                     double[][] cx,
                                                     double[][] cy)
Convert the raw transformation mapping to B-spline coefficients.

Parameters:
targetImp - target image representation
intervals - intervals in the deformation
transformation_x - raw transformation in x- axis
transformation_y - raw transformation in y- axis
cx - transformation in x- by B-spline coefficients (output)
cy - transformation in y- by B-spline coefficients (output)

invertRawTransformation

public static void invertRawTransformation(ij.ImagePlus targetImp,
                                           double[][] transformation_x,
                                           double[][] transformation_y,
                                           double[][] inv_x,
                                           double[][] inv_y)

rawWarpingIndex

public static double rawWarpingIndex(ij.ImagePlus sourceImp,
                                     ij.ImagePlus targetImp,
                                     int intervals,
                                     double[][] cx_direct,
                                     double[][] cy_direct,
                                     double[][] transformation_x,
                                     double[][] transformation_y)
Warping index for comparing elastic deformations with any kind of deformation (both transformations having same direction).

Parameters:
sourceImp - source image representation
targetImp - target image representation
intervals - intervals in the deformation
cx_direct - direct transformation x- B-spline coefficients
cy_direct - direct transformation y- B-spline coefficients
transformation_x - raw direct transformation in x- axis
transformation_y - raw direct transformation in y- axis

rawWarpingIndex

public static double rawWarpingIndex(ij.ImagePlus sourceImp,
                                     ij.ImagePlus targetImp,
                                     double[][] transformation_x_1,
                                     double[][] transformation_y_1,
                                     double[][] transformation_x_2,
                                     double[][] transformation_y_2)
Warping index for comparing two raw deformations (both transformations having same direction).

Parameters:
sourceImp - source image representation
targetImp - target image representation
transformation_x_1 - raw first transformation in x- axis
transformation_y_1 - raw first transformation in y- axis
transformation_x_2 - raw second transformation in x- axis
transformation_y_2 - raw second transformation in y- axis

drawArrow

public static void drawArrow(double[][] canvas,
                             int x1,
                             int y1,
                             int x2,
                             int y2,
                             double color,
                             int arrow_size)
Draw an arrow between two points. The arrow head is in (x2,y2)

Parameters:
canvas - canvas where we are painting
x1 - x- coordinate for the arrow origin
y1 - y- coordinate for the arrow origin
x2 - x- coordinate for the arrow head
y2 - y- coordinate for the arrow head
color - arrow color
arrow_size - arrow size

drawLine

public static void drawLine(double[][] canvas,
                            int x1,
                            int y1,
                            int x2,
                            int y2,
                            double color)
Draw a line between two points. Bresenham's algorithm.

Parameters:
canvas - canvas where we are painting
x1 - x- coordinate for first point
y1 - y- coordinate for first point
x2 - x- coordinate for second point
y2 - y- coordinate for second point
color - line color

extractImage

public static void extractImage(ij.process.ImageProcessor ip,
                                double[] image)
Put the image from an ImageProcessor into a double array.

Parameters:
ip - input, origin of the image
image - output, the image in a double array

extractImage

public static void extractImage(ij.process.ImageProcessor ip,
                                double[][] image)
Put the image from an ImageProcessor into a double[][].

Parameters:
ip - input, origin of the image
image - output, the image in a double[][]

loadPoints

public static void loadPoints(java.lang.String filename,
                              java.util.Stack<java.awt.Point> sourceStack,
                              java.util.Stack<java.awt.Point> targetStack)
Load landmarks from file.

Parameters:
filename - landmarks file name
sourceStack - stack of source related points (output)
targetStack - stack of target related points (output)

loadPointRoiAsLandmarks

public static void loadPointRoiAsLandmarks(ij.ImagePlus sourceImp,
                                           ij.ImagePlus targetImp,
                                           java.util.Stack<java.awt.Point> sourceStack,
                                           java.util.Stack<java.awt.Point> targetStack)
Load point rois in the source and target images as landmarks.

Parameters:
sourceImp - source image plus
targetImp - target image plus
sourceStack - stack of source related points (output)
targetStack - stack of target related points (output)

loadTransformation

public static void loadTransformation(java.lang.String filename,
                                      double[][] cx,
                                      double[][] cy)
Load a transformation from a file.

Parameters:
filename - transformation file name
cx - x- B-spline coefficients
cy - y- B-spline coefficients

loadRawTransformation

public static void loadRawTransformation(java.lang.String filename,
                                         double[][] transformation_x,
                                         double[][] transformation_y)
Load a raw transformation from a file.

Parameters:
filename - transformation file name
transformation_x - output x- transformation coordinates
transformation_y - output y- transformation coordinates

loadRawTransformation

public static void loadRawTransformation(java.lang.String filename,
                                         double[] transformation_x,
                                         double[] transformation_y)
Load a raw transformation from a file.

Parameters:
filename - transformation file name
transformation_x - output x- transformation coordinates
transformation_y - output y- transformation coordinates

loadAffineMatrix

public static void loadAffineMatrix(java.lang.String filename,
                                    double[][] affineMatrix)
Load an affine matrix from a file.

Parameters:
filename - matrix file name
affineMatrix - output affine matrix

composeElasticTransformations

public static void composeElasticTransformations(ij.ImagePlus targetImp,
                                                 int intervals,
                                                 double[][] cx1,
                                                 double[][] cy1,
                                                 double[][] cx2,
                                                 double[][] cy2,
                                                 double[][] outputTransformation_x,
                                                 double[][] outputTransformation_y)
Compose two elastic deformations into a raw deformation.

Parameters:
targetImp - target image representation
intervals - intervals in the deformation
cx1 - first transformation x- B-spline coefficients
cy1 - first transformation y- B-spline coefficients
cx2 - second transformation x- B-spline coefficients
cy2 - second transformation y- B-spline coefficients
outputTransformation_x - output transformation coordinates in x-axis
outputTransformation_y - output transformation coordinates in y-axis

composeRawElasticTransformations

public static void composeRawElasticTransformations(ij.ImagePlus targetImp,
                                                    int intervals,
                                                    double[][] transformation_x_1,
                                                    double[][] transformation_y_1,
                                                    double[][] cx2,
                                                    double[][] cy2,
                                                    double[][] outputTransformation_x,
                                                    double[][] outputTransformation_y)
Compose a raw deformation and an elastic deformation into a raw deformation.

Parameters:
targetImp - target image representation
intervals - intervals in the deformation
transformation_x_1 - first transformation coordinates in x-axis
transformation_y_1 - first transformation coordinates in y-axis
cx2 - second transformation x- B-spline coefficients
cy2 - second transformation y- B-spline coefficients
outputTransformation_x - output transformation coordinates in x-axis
outputTransformation_y - output transformation coordinates in y-axis

composeElasticTransformationsAtPixelLevel

public static void composeElasticTransformationsAtPixelLevel(ij.ImagePlus targetImp,
                                                             int intervals,
                                                             double[][] cx1,
                                                             double[][] cy1,
                                                             double[][] cx2,
                                                             double[][] cy2,
                                                             double[][] outputTransformation_x,
                                                             double[][] outputTransformation_y)
Compose two elastic deformations into a raw deformation at pixel level.

Parameters:
targetImp - target image representation
intervals - intervals in the deformation
cx1 - first transformation x- B-spline coefficients
cy1 - first transformation y- B-spline coefficients
cx2 - second transformation x- B-spline coefficients
cy2 - second transformation y- B-spline coefficients
outputTransformation_x - output transformation coordinates in y-axis
outputTransformation_y - output transformation coordinates in y-axis

composeRawTransformations

public static void composeRawTransformations(int width,
                                             int height,
                                             double[][] transformation_x_1,
                                             double[][] transformation_y_1,
                                             double[][] transformation_x_2,
                                             double[][] transformation_y_2,
                                             double[][] outputTransformation_x,
                                             double[][] outputTransformation_y)
Compose two raw transformations (Bilinear interpolation)

Parameters:
width - image width
height - image height
transformation_x_1 - first transformation coordinates in x-axis
transformation_y_1 - first transformation coordinates in y-axis
transformation_x_2 - second transformation coordinates in x-axis
transformation_y_2 - second transformation coordinates in y-axis
outputTransformation_x - output transformation coordinates in y-axis
outputTransformation_y - output transformation coordinates in y-axis

saveElasticTransformation

public static void saveElasticTransformation(int intervals,
                                             double[][] cx,
                                             double[][] cy,
                                             java.lang.String filename)
Save the elastic transformation.

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
filename - transformation file name

saveRawTransformation

public static void saveRawTransformation(java.lang.String filename,
                                         int width,
                                         int height,
                                         double[][] transformation_x,
                                         double[][] transformation_y)
Save a raw transformation

Parameters:
filename - raw transformation file name
width - image width
height - image height
transformation_x - transformation coordinates in x-axis
transformation_y - transformation coordinates in y-axis

numberOfIntervalsOfTransformation

public static int numberOfIntervalsOfTransformation(java.lang.String filename)
Read the number of intervals of a transformation from a file.

Parameters:
filename - transformation file name
Returns:
number of intervals

Point

public static void Point(double[][] canvas,
                         int y,
                         int x,
                         double color)
Plot a point in a canvas.

Parameters:
canvas - canvas where we are painting
x - x- coordinate for the point
y - y- coordinate for the point
color - point color

printMatrix

public static void printMatrix(java.lang.String title,
                               double[][] array)
Print a matrix in the command line.

Parameters:
title - matrix title
array - matrix to be printed

showImage

public static void showImage(java.lang.String title,
                             double[] array,
                             int Ydim,
                             int Xdim)
Show an image in a new bUnwarpJ window.

Parameters:
title - image title
array - image in a double array
Ydim - image height
Xdim - image width

showImage

public static void showImage(java.lang.String title,
                             double[][] array)
Show an image in a new bUnwarpJ window.

Parameters:
title - image title
array - image in a double array

adaptCoefficients

public static void adaptCoefficients(double xScale,
                                     double yScale,
                                     int intervals,
                                     double[][] cx,
                                     double[][] cy)
Adapt B-spline coefficients to a scale factor

Parameters:
xScale -
yScale -
intervals -
cx -
cy -

applyTransformationToSourceMT

public static void applyTransformationToSourceMT(ij.ImagePlus sourceImp,
                                                 ij.ImagePlus targetImp,
                                                 int intervals,
                                                 double[][] cx,
                                                 double[][] cy)
Apply a given B-spline transformation to the source (gray-scale) image. The source image is modified. The target image is used to know the output size (Multi-thread version).

Parameters:
sourceImp - source image representation
targetImp - target image representation
intervals - intervals in the deformation
cx - x- B-spline coefficients
cy - y- B-spline coefficients

applyTransformationToSourceMT

public static void applyTransformationToSourceMT(ij.ImagePlus sourceImp,
                                                 ij.ImagePlus targetImp,
                                                 BSplineModel source,
                                                 int intervals,
                                                 double[][] cx,
                                                 double[][] cy)
Apply a given B-spline transformation to the source (gray-scale) image. The source image is modified. The target image is used to know the output size (Multi-thread version).

Parameters:
sourceImp - source image representation
targetImp - target image representation
source - source image model
intervals - intervals in the deformation
cx - x- B-spline coefficients
cy - y- B-spline coefficients

applyTransformationMT

public static ij.process.ImageProcessor applyTransformationMT(ij.ImagePlus sourceImp,
                                                              ij.ImagePlus targetImp,
                                                              BSplineModel source,
                                                              int intervals,
                                                              double[][] cx,
                                                              double[][] cy)
Apply a given B-spline transformation to the source (gray-scale) image. The result image is return. The target image is used to know the output size (Multi-thread version).

Parameters:
sourceImp - source image representation
targetImp - target image representation
source - source image model
intervals - intervals in the deformation
cx - x- B-spline coefficients
cy - y- B-spline coefficients
Returns:
result transformed image

smoothForScale

public static final void smoothForScale(ij.process.ImageProcessor source,
                                        float scale,
                                        float sourceSigma,
                                        float targetSigma)
Smooth with a Gaussian kernel that represents downsampling at a given scale factor and sourceSigma.


createDownsampled

public static final ij.process.ImageProcessor createDownsampled(ij.process.ImageProcessor source,
                                                                float scale,
                                                                float sourceSigma,
                                                                float targetSigma)
Create a downsampled ImageProcessor.

Parameters:
source - the source image
scale - scaling factor
sourceSigma - the Gaussian at which the source was sampled (guess 0.5 if you do not know)
targetSigma - the Gaussian at which the target will be sampled
Returns:
a new FloatProcessor

scale

public static final ij.process.ImageProcessor scale(ij.process.ImageProcessor source,
                                                    float scale)
Scale an image with good quality in both up and down direction