Java Code Examples for ij.process.FloatProcessor#getHeight()

The following examples show how to use ij.process.FloatProcessor#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataGeneratorPlugIn.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
private FloatProcessor readMask(String imagePath) {
    if((imagePath != null) && (imagePath.trim().length() > 0)) {
        ImagePlus imp = IJ.openImage(imagePath);
        if(imp != null) {
            // ensure that the maximum value cannot be more than 1.0 !
            FloatProcessor fmask = (FloatProcessor) imp.getProcessor().convertToFloat();
            float min = 0;
            float max = (float) fmask.getMax();
            if(max > 0) {
                for(int x = 0; x < fmask.getWidth(); x++) {
                    for(int y = 0; y < fmask.getHeight(); y++) {
                        fmask.setf(x, y, (fmask.getf(x, y) - min) / (max - min));
                    }
                }
            }
            return fmask;
        }
    }
    return ImageMath.ones(width, height);
}
 
Example 2
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor modulo(FloatProcessor mat, float val) {
    FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight());
    res.setMask(mat.getMask());
    float tmp;
    for (int i = 0, im = mat.getWidth(); i < im; i++) {
        for (int j = 0, jm = mat.getHeight(); j < jm; j++) {
            tmp = mat.getf(i, j) / val;
            res.setf(i, j, mat.getf(i, j) - (((float)((int)tmp)) * val));
        }
    }
    return res;
}
 
Example 3
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relLt(FloatProcessor a, FloatProcessor b) {
    if((a.getWidth() != b.getWidth()) || (a.getHeight()!= b.getHeight())) {
        throw new IllegalArgumentException("Error during evaluation of `a<b` expression! Both operands must be of the same size!");
    }
    FloatProcessor res = new FloatProcessor(a.getWidth(), a.getHeight());
    res.setMask(a.getMask() != null ? a.getMask(): b.getMask());
    for(int x = 0; x < a.getWidth(); x++) {
        for(int y = 0; y < a.getHeight(); y++) {
            res.setf(x, y, ((a.getf(x, y) < b.getf(x, y)) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 4
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor logAnd(FloatProcessor a, FloatProcessor b) {
    if((a.getWidth() != b.getWidth()) || (a.getHeight()!= b.getHeight())) {
        throw new IllegalArgumentException("Error during evaluation of `a&b` expression! Both operands must be of the same size!");
    }
    FloatProcessor res = new FloatProcessor(a.getWidth(), a.getHeight());
    res.setMask(a.getMask() != null ? a.getMask(): b.getMask());
    for(int x = 0; x < a.getWidth(); x++) {
        for(int y = 0; y < a.getHeight(); y++) {
            res.setf(x, y, (((a.getf(x, y) != 0.0f) && (b.getf(x, y) != 0.0f)) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 5
Source File: ValueToNoise.java    From render with GNU General Public License v2.0 5 votes vote down vote up
private static void processFloat(final FloatProcessor ip,
                                 final float value,
                                 final double min,
                                 final double max) {
    final double scale = max - min;
    final Random rnd = new Random();
    final int n = ip.getWidth() * ip.getHeight();
    for (int i = 0; i < n; ++i) {
        final float v = ip.getf(i);
        if (v == value)
            ip.setf(i, (float) (rnd.nextDouble() * scale + min));
    }
}
 
Example 6
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Divide a scalar value by values from an image.
 * 
 * @param val an input value which the input image ({@code fp}) will divide
 * @param fp an input image
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fpv = val / fp}
 */
public static FloatProcessor divide(float val, FloatProcessor fp) {
    FloatProcessor out = new FloatProcessor(fp.getWidth(), fp.getHeight());
    out.setMask(fp.getMask());
    for (int i = 0, im = fp.getWidth(); i < im; i++) {
        for (int j = 0, jm = fp.getHeight(); j < jm; j++) {
            out.setf(i, j, val / fp.getPixelValue(i, j));
        }
    }

    return out;
}
 
Example 7
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor logOr(FloatProcessor a, FloatProcessor b) {
    if((a.getWidth() != b.getWidth()) || (a.getHeight()!= b.getHeight())) {
        throw new IllegalArgumentException("Error during evaluation of `a|b` expression! Both operands must be of the same size!");
    }
    FloatProcessor res = new FloatProcessor(a.getWidth(), a.getHeight());
    res.setMask(a.getMask() != null ? a.getMask(): b.getMask());
    for(int x = 0; x < a.getWidth(); x++) {
        for(int y = 0; y < a.getHeight(); y++) {
            res.setf(x, y, (((a.getf(x, y) != 0.0f) || (b.getf(x, y) != 0.0f)) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 8
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relEq(Double val, FloatProcessor mat) {
    float v = val.floatValue();
    FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight());
    res.setMask(mat.getMask());
    for(int x = 0; x < mat.getWidth(); x++) {
        for(int y = 0; y < mat.getHeight(); y++) {
            res.setf(x, y, ((mat.getf(x, y) == v) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 9
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Multiply two images.
 * 
 * The images are required to be of the same size.
 *
 * @param fp1 an input image which the other input image ({@code fp2}) will be multiplied with
 * @param fp2 another input image which will be multiplied with {@code fp1}
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fp3 = fp1 * fp2}
 */
public static FloatProcessor multiply(FloatProcessor fp1, FloatProcessor fp2) {
    assert (fp1.getWidth() == fp2.getWidth());
    assert (fp1.getHeight() == fp2.getHeight());

    FloatProcessor out = new FloatProcessor(fp1.getWidth(), fp1.getHeight());
    out.setMask(fp1.getMask() != null ? fp1.getMask(): fp2.getMask());
    for (int i = 0, im = fp1.getWidth(); i < im; i++) {
        for (int j = 0, jm = fp1.getHeight(); j < jm; j++) {
            out.setf(i, j, fp1.getPixelValue(i, j) * fp2.getPixelValue(i, j));
        }
    }

    return out;
}
 
Example 10
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Subtract an image from a scalar.
 * 
 * @param val an input value which the input image ({@code fp}) will be subtracted from
 * @param fp an input image
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fpv = val - fp}
 */
public static FloatProcessor subtract(float val, FloatProcessor fp) {
    FloatProcessor out = new FloatProcessor(fp.getWidth(), fp.getHeight());
    out.setMask(fp.getMask());
    for (int i = 0, im = fp.getWidth(); i < im; i++) {
        for (int j = 0, jm = fp.getHeight(); j < jm; j++) {
            out.setf(i, j, val - fp.getPixelValue(i, j));
        }
    }

    return out;
}
 
Example 11
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Subtract one image to the other.
 * 
 * The images are required to be of the same size.
 *
 * @param fp1 an input image which the other input image ({@code fp2}) will be subtracted from
 * @param fp2 another input image which will be subtracted from {@code fp1}
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fp3 = fp1 - fp2}
 */
public static FloatProcessor subtract(FloatProcessor fp1, FloatProcessor fp2) {
    assert (fp1.getWidth() == fp2.getWidth());
    assert (fp1.getHeight() == fp2.getHeight());

    FloatProcessor out = new FloatProcessor(fp1.getWidth(), fp1.getHeight());
    out.setMask(fp1.getMask() != null ? fp1.getMask(): fp2.getMask());
    for (int i = 0, im = fp1.getWidth(); i < im; i++) {
        for (int j = 0, jm = fp1.getHeight(); j < jm; j++) {
            out.setf(i, j, fp1.getPixelValue(i, j) - fp2.getPixelValue(i, j));
        }
    }

    return out;
}
 
Example 12
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor modulo(float val, FloatProcessor mat) {
    FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight());
    res.setMask(mat.getMask());
    float tmp;
    for (int i = 0, im = mat.getWidth(); i < im; i++) {
        for (int j = 0, jm = mat.getHeight(); j < jm; j++) {
            tmp = val / mat.getf(i, j);
            res.setf(i, j, val - (((float)((int)tmp)) * mat.getf(i, j)));
        }
    }
    return res;
}
 
Example 13
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add two images.
 * 
 * The images are required to be of the same size.
 *
 * @param fp1 an input image which the other input image ({@code fp2}) will be added to
 * @param fp2 another input image which will be added to {@code fp1}
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fp3 = fp1 + fp2}
 */
public static FloatProcessor add(FloatProcessor fp1, FloatProcessor fp2) {
    assert (fp1.getWidth() == fp2.getWidth());
    assert (fp1.getHeight() == fp2.getHeight());

    FloatProcessor out = new FloatProcessor(fp1.getWidth(), fp1.getHeight());
    out.setMask(fp1.getMask() != null ? fp1.getMask(): fp2.getMask());
    for (int i = 0, im = fp1.getWidth(); i < im; i++) {
        for (int j = 0, jm = fp1.getHeight(); j < jm; j++) {
            out.setf(i, j, fp1.getPixelValue(i, j) + fp2.getPixelValue(i, j));
        }
    }

    return out;
}
 
Example 14
Source File: ValueToNoise.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static private void processFloat(final FloatProcessor ip, final float value, final double min, final double max) {
	final double scale = max - min;
	final Random rnd = new Random();
	final int n = ip.getWidth() * ip.getHeight();
	for (int i =0; i < n; ++i) {
		final float v = ip.getf(i);
		if (v == value)
			ip.setf(i, (float)(rnd.nextDouble() * scale + min));
	}
}
 
Example 15
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relLt(FloatProcessor mat, Double val) {
    float v = val.floatValue();
    FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight());
    res.setMask(mat.getMask());
    for(int x = 0; x < mat.getWidth(); x++) {
        for(int y = 0; y < mat.getHeight(); y++) {
            res.setf(x, y, ((mat.getf(x, y) < v) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 16
Source File: LabelRenderer.java    From render with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the processor to a short (16-bit) label image.
 *
 * @param  renderedImageProcessorWithMasks  processor to convert.
 *
 * @return the converted image.
 */
private static BufferedImage targetToLabelImage(final ImageProcessorWithMasks renderedImageProcessorWithMasks) {

    // convert to 16-bit gray-scale
    if (! (renderedImageProcessorWithMasks.ip instanceof FloatProcessor)) {
        throw new IllegalArgumentException("target must be a " + FloatProcessor.class +
                                           " instance but instead is " +
                                           renderedImageProcessorWithMasks.ip.getClass());
    }

    final FloatProcessor fp = (FloatProcessor) renderedImageProcessorWithMasks.ip;
    final float[] pixels = (float[]) renderedImageProcessorWithMasks.ip.getPixels();
    final short[] labelPixels = new short[pixels.length];
    final short emptyPixel = (short) LabelImageProcessorCache.MAX_LABEL_INTENSITY;

    for (int i = 0; i < pixels.length; i++) {
        if (pixels[i] == 0) {
            // map black to white for DMG
            labelPixels[i] = emptyPixel;
        } else {
            // simple cast is sufficient here because the label sources mapped into this target
            // are all 16-bit values with binary masking
            labelPixels[i] = (short) pixels[i];
        }
    }

    final BufferedImage image = new BufferedImage(fp.getWidth(), fp.getHeight(), BufferedImage.TYPE_USHORT_GRAY);
    final WritableRaster raster = image.getRaster();
    raster.setDataElements(0, 0, fp.getWidth(), fp.getHeight(), labelPixels);

    return image;
}
 
Example 17
Source File: ValueToNoise.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static private void processFloatNaN(final FloatProcessor ip, final double min, final double max) {
	final double scale = max - min;
	final Random rnd = new Random();
	final int n = ip.getWidth() * ip.getHeight();
	for (int i =0; i < n; ++i) {
		final float v = ip.getf(i);
		if (Float.isNaN(v))
			ip.setf(i, (float)(rnd.nextDouble() * scale + min));
	}
}
 
Example 18
Source File: MultipleLocationsBiplaneFitting.java    From thunderstorm with GNU General Public License v3.0 4 votes vote down vote up
private boolean isCloseToBorder(FloatProcessor image, Point pos) {
    double x = pos.getX().doubleValue(), y = pos.getY().doubleValue();
    return x < (double)subimageSize || x > (double)(image.getWidth() - subimageSize)
        || y < (double)subimageSize || y > (double)(image.getHeight() - subimageSize);
}
 
Example 19
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Apply a {@code mask} to an input {@code image}.
 * 
 * The masking works simply by checking where is a 0 in the mask image and
 * setting the corresponding pixel in the input image to 0 as well. Hence the
 * mask does not have to be binary.
 * 
 * For example let's have the following input image:
 * <pre>
 * {@code
 * 123
 * 456
 * 789}
 * </pre>
 * and the following mask:
 * <pre>
 * {@code
 * 560
 * 804
 * 032}
 * </pre>
 * Then the result of applying the mask is:
 * <pre>
 * {@code
 * 120
 * 406
 * 089}
 * </pre>
 * 
 * @param image an input image
 * @param mask a mask image
 * @return a <strong>new instance</strong> of FloatProcessor that contains the input image after the mask was applied
 */
public static FloatProcessor applyMask(FloatProcessor image, FloatProcessor mask) {
    assert (image.getWidth() == mask.getWidth());
    assert (image.getHeight() == mask.getHeight());

    FloatProcessor result = new FloatProcessor(image.getWidth(), image.getHeight(), (float[]) image.getPixelsCopy(), null);
    for (int x = 0, xm = image.getWidth(); x < xm; x++) {
        for (int y = 0, ym = image.getHeight(); y < ym; y++) {
            if (mask.getf(x, y) == 0.0f) {
                result.setf(x, y, 0.0f);
            }
        }
    }
    
    return result;
}
 
Example 20
Source File: FloatProcessorT2.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public FloatProcessorT2(final FloatProcessor fp) {
	this(fp.getWidth(), fp.getHeight(), (float[])fp.getPixels(), fp.getColorModel(), fp.getMin(), fp.getMax());
}