bijnum
Class BIJutil

java.lang.Object
  |
  +--bijnum.BIJutil

public class BIJutil
extends java.lang.Object

Utilities to link BIJ things to ImageJ. Copyright (c) 1999-2004, Michael Abramoff. All rights reserved.


Constructor Summary
BIJutil()
           
 
Method Summary
static void bin(double[] x, int binwidth)
          Bin a vector x.
static float[] center(float[] image0, int width0, float[] image1, int width1, float scaling)
          Center a scaled image1 into the center of a larger image0.
static float[] center(float[] image0, int width0, float[] image1, int width1, float scaling, int offset_x, int offset_y)
          Center a scaled image1 into the center of a larger image0 with offset offset_x and offset_y.
static float[] crop(float[] image, int width, int height, int x, int y, int newwidth, int newheight)
          Crop a float image to the rectangular size of a ROI defined by x,y,newwidth,newheight
static byte[] fit(byte[] image, int width)
          Fit a byte image into a new power of 2 size image of newwidth * newwidth.
static float[] fit(float[] image, int width)
          Fit a float image into a new power of 2 size image of newwidth * newwidth.
static float[] fit(float[] spectrum, int width, int height)
          Fit a square image into a smaller image widthxheight, with the center in the center of the new image.
protected static float[] getFloatPixels(java.lang.Object array)
          Convert the pixels in array into a float vector.
static float[] getMask(ij.gui.Roi roi, int width, int height)
          Make a mask within an image widthxheight for Roi.
static int getMatrixWidth(ij.ImagePlus imp)
          Compute the width of the images in imp, or the ROI if one has been selected.
static int getMatrixWidth(ij.ImagePlus imp, double scaleFactor)
          Compute the width of the images in imp, containing a stack, including scaling.
static ij.ImageStack imageStackFromMatrix(float[][] a, int width)
          Create an ImageJ ImageStack out of a float matrix.
static ij.ImageStack imageStackFromMatrix(short[][] a, int width)
          Create an ImageJ ImageStack out of a float matrix.
static float[] makePower2(float[] v)
          Mirror a vector so that is has power of 2 length and does not contain extra edges.
static float[][] matrixFromImageStack(ij.ImagePlus imp)
          Convert the data in the ImageStack in imp into a float[][] matrix for further processing.
static float[][] matrixFromImageStack(ij.ImagePlus imp, double scaleFactor)
          Convert the data in the ImageStack in imp into a float[][] matrix and scale by scaleFactor on the fly.
static float[][] matrixFromImageStack(ij.ImageStack is)
          Access the data in the ImageStack in imp into a float[][] matrix for further processing.
static float[][] matrixFromImageStackRoi(ij.ImagePlus imp)
          Convert the data only within the rectangular Roi in the ImageStack in imp into a float[][] matrix for further processing.
static int minPower2(int n)
          Find the minimal power of 2 that is larger than n.
static float[] montage(float[][] a, int awidth, int columns)
          Make a montage of all images in a, with columns images per row, so that the width of the returned image will be awidth*columns.
static boolean saveAsText(float[] v, java.lang.String path)
          Save vector v as a text file.
static short[][] shortMatrixFromImageStack(ij.ImagePlus imp)
          Convert the data in the ImageStack in imp into a short [][] matrix for further processing.
static ij.ImagePlus showVectorAsImage(float[] v, int width)
           
static float[] tile(float[] image, int width)
          Fit an image into a new image of newwidth * newwidth, where newwidth is next large power of 2 than width.
static float[] tofloat(double[] v)
           
static java.lang.String toString(double[] m)
           
static java.lang.String toString(double[][] m)
           
static java.lang.String toString(float[] m)
           
static java.lang.String toString(float[][] m)
           
static java.lang.String toString(int[][] m)
           
static float[] vectorFromImageStack(ij.ImagePlus imp, int i)
          Convert the data in the ImagePlus image stack into a float[] vector for further processing.
static float[] vectorFromImageStack(ij.ImagePlus imp, int i, float scaleFactor)
          Convert the data in the ImageStack in imp into a float[][] matrix and scale by scaleFactor on the fly.
static float[] vectorFromImageStackRoi(ij.ImagePlus imp)
          Convert the data in the i'th ImagePlus image into a float[] vector for further processing.
static float[] vectorFromImageStackRoi(ij.ImagePlus imp, int i)
          Convert the data in the i'th ImagePlus image into a float[] vector for further processing.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BIJutil

public BIJutil()
Method Detail

imageStackFromMatrix

public static ij.ImageStack imageStackFromMatrix(float[][] a,
                                                 int width)
Create an ImageJ ImageStack out of a float matrix. width is the width of each image.
Parameters:
a - a float[][] matrix with the images as column vectors.
width - the width of each image in pixels.
Returns:
an ImageStack.

imageStackFromMatrix

public static ij.ImageStack imageStackFromMatrix(short[][] a,
                                                 int width)
Create an ImageJ ImageStack out of a float matrix. width is the width of each image.
Parameters:
a - a float[][] matrix with the images as column vectors.
width - the width of each image in pixels.
Returns:
an ImageStack.

getMatrixWidth

public static int getMatrixWidth(ij.ImagePlus imp)
Compute the width of the images in imp, or the ROI if one has been selected.
Returns:
the width of the images in imp.

getMatrixWidth

public static int getMatrixWidth(ij.ImagePlus imp,
                                 double scaleFactor)
Compute the width of the images in imp, containing a stack, including scaling.
Parameters:
scaleFactor - the scaling factor.
Returns:
the width of the images in imp.

matrixFromImageStack

public static float[][] matrixFromImageStack(ij.ImagePlus imp)
Convert the data in the ImageStack in imp into a float[][] matrix for further processing. Do not use ROI. Uses getFloatPixels(ipp.getPixels()), which converts 16-bit images to
Returns:
a float[][] with the images.

matrixFromImageStack

public static float[][] matrixFromImageStack(ij.ImageStack is)
Access the data in the ImageStack in imp into a float[][] matrix for further processing. Do not use ROI. If the is contains float images, does not convert and the float[][] are the actual pixels. If not, the float[][] are copies of whatever is in the is. Uses getFloatPixels(ipp.getPixels()), which converts 16-bit images to
Returns:
a float[][] with the images.

showVectorAsImage

public static ij.ImagePlus showVectorAsImage(float[] v,
                                             int width)

vectorFromImageStack

public static float[] vectorFromImageStack(ij.ImagePlus imp,
                                           int i)
Convert the data in the ImagePlus image stack into a float[] vector for further processing. Do not use ROI.
Parameters:
imp - the imageplus containing the stack.
i - the image number in the stack, starting with 0.
Returns:
a float[] with the image as a vector.

vectorFromImageStack

public static float[] vectorFromImageStack(ij.ImagePlus imp,
                                           int i,
                                           float scaleFactor)
Convert the data in the ImageStack in imp into a float[][] matrix and scale by scaleFactor on the fly. Do not use Roi.
Parameters:
imp - the imageplus containing the stack.
i - the image number in the stack, starting with 0.
scaleFactor - the scaling factor.
Returns:
a float[] with the image as a vector.

vectorFromImageStackRoi

public static float[] vectorFromImageStackRoi(ij.ImagePlus imp)
Convert the data in the i'th ImagePlus image into a float[] vector for further processing. Use ROI if present.
Returns:
a float[] with the image.

vectorFromImageStackRoi

public static float[] vectorFromImageStackRoi(ij.ImagePlus imp,
                                              int i)
Convert the data in the i'th ImagePlus image into a float[] vector for further processing. Use ROI if present.
Returns:
a float[] with the image.

crop

public static float[] crop(float[] image,
                           int width,
                           int height,
                           int x,
                           int y,
                           int newwidth,
                           int newheight)
Crop a float image to the rectangular size of a ROI defined by x,y,newwidth,newheight
Parameters:
image - a float[] vector image
width - the width in pixels of image
height - the width in pixels of image
x, - y, newwidth, newheight the ROI
Returns:
the cropped image as a float[].

getFloatPixels

protected static float[] getFloatPixels(java.lang.Object array)
Convert the pixels in array into a float vector.

matrixFromImageStack

public static float[][] matrixFromImageStack(ij.ImagePlus imp,
                                             double scaleFactor)
Convert the data in the ImageStack in imp into a float[][] matrix and scale by scaleFactor on the fly. Do not use Roi.
Parameters:
imp - an ImagePlus
scaleFactor - the scalefactor between 100-0.01.
Returns:
a float[][] with the images.

matrixFromImageStackRoi

public static float[][] matrixFromImageStackRoi(ij.ImagePlus imp)
Convert the data only within the rectangular Roi in the ImageStack in imp into a float[][] matrix for further processing.
Returns:
a float[][] with the images. The size of the resulting aray may not conform to that of the imp because it corresponds to the Roi size.

shortMatrixFromImageStack

public static short[][] shortMatrixFromImageStack(ij.ImagePlus imp)
Convert the data in the ImageStack in imp into a short [][] matrix for further processing.
Returns:
a short[][] with the images.

montage

public static float[] montage(float[][] a,
                              int awidth,
                              int columns)
Make a montage of all images in a, with columns images per row, so that the width of the returned image will be awidth*columns. Uses ImageJ library to include lettering etc.
Parameters:
a - a float[][] with the images.
awidth, - the width of each image in pixels.
columns - the number of columns desired.
Returns:
a float[] image containing the montage.

minPower2

public static int minPower2(int n)
Find the minimal power of 2 that is larger than n.
Returns:
the minimal power of 2 that larger than n.

bin

public static void bin(double[] x,
                       int binwidth)
Bin a vector x. By binning is meant add consecutive elements i...i+binwidth and put into elements i...i+binwidth.

makePower2

public static float[] makePower2(float[] v)
Mirror a vector so that is has power of 2 length and does not contain extra edges.

tile

public static float[] tile(float[] image,
                           int width)
Fit an image into a new image of newwidth * newwidth, where newwidth is next large power of 2 than width. The image is centered in the center of the new image and mirrored at the edges to avoid edge artifacts.
Parameters:
image - a float[] with the image
width - the width of image.
Returns:
a float[] with a new tiled image newwidthxnewheight.

fit

public static float[] fit(float[] image,
                          int width)
Fit a float image into a new power of 2 size image of newwidth * newwidth. The image is centered in the center of the new image and NOT mirrored
Parameters:
image - a float[] with the image
width - the width of image.
Returns:
a float[] with a new square image newwidthxnewheight.

fit

public static float[] fit(float[] spectrum,
                          int width,
                          int height)
Fit a square image into a smaller image widthxheight, with the center in the center of the new image.
Parameters:
spectrum - a square image vector.
width - the width in pixels of the new image.
height - the height of the new image.
Returns:
the centered resize spectrum.

fit

public static byte[] fit(byte[] image,
                         int width)
Fit a byte image into a new power of 2 size image of newwidth * newwidth. The image is centered in the center of the new image and NOT mirrored
Parameters:
image - a byte[] with the image
width - the width of image.
Returns:
a byte[] with a new square image newwidthxnewheight.

getMask

public static float[] getMask(ij.gui.Roi roi,
                              int width,
                              int height)
Make a mask within an image widthxheight for Roi. All pixels within Roi will be 1, all others 0. March 2004, update to conform to ImageJ 1.32e and higher, where getMask returns a ByteProcessor.
Parameters:
roi - the roi.
width - the width of the mask.
height - the height of the mask.
Returns:
a float[] containing the mask bytes.

center

public static float[] center(float[] image0,
                             int width0,
                             float[] image1,
                             int width1,
                             float scaling)
Center a scaled image1 into the center of a larger image0. The original image0 will not be modified.
Parameters:
image0 - the base image
width0 - the width in pixels of the base image
image1 - the image to be inserted
width1 - the width in pixels of the new image
scaling - the amount by which image1 will be scaled.
Returns:
a new image of the same size as image0.

center

public static float[] center(float[] image0,
                             int width0,
                             float[] image1,
                             int width1,
                             float scaling,
                             int offset_x,
                             int offset_y)
Center a scaled image1 into the center of a larger image0 with offset offset_x and offset_y. The original image0 will not be modified.
Parameters:
image0 - the base image
width0 - the width in pixels of the base image
image1 - the image to be inserted
width1 - the width in pixels of the new image
scaling - the amount by which image1 will be scaled.
Returns:
a new image of the same size as image0.

saveAsText

public static boolean saveAsText(float[] v,
                                 java.lang.String path)
Save vector v as a text file. Tab separated.
Parameters:
v - the float[] vector
path - a String with the path to save the vector to.
Returns:
true if succesful, false if Exception.

tofloat

public static float[] tofloat(double[] v)

toString

public static java.lang.String toString(float[][] m)

toString

public static java.lang.String toString(double[][] m)

toString

public static java.lang.String toString(int[][] m)

toString

public static java.lang.String toString(float[] m)

toString

public static java.lang.String toString(double[] m)