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

The following examples show how to use ij.process.FloatProcessor#getWidth() . 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
/**
 * 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 3
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 4
Source File: Max_Project.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static < T extends RealType< T > & NativeType< T > > boolean maxProject(
		final List< ? extends ViewDescription > vds,
		final ImgLoader imgLoader,
		final T type )
{
	Collections.sort( vds );

	final ArrayList< TimePoint > tps = SpimData2.getAllTimePointsSorted( vds );
	final ArrayList< ViewSetup > setups = SpimData2.getAllViewSetups( vds );

	for ( final ViewSetup setup : setups )
	{
		ImageStack stack = null;

		for ( final TimePoint t : tps )
			for ( final ViewDescription vd : vds )
				if ( vd.getTimePointId() == t.getId() && vd.getViewSetupId() == setup.getId() )
				{
					IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + "): Loading image for timepoint " + t.getId() + " viewsetup " + vd.getViewSetupId() );

					final RandomAccessibleInterval< T > img = ProcessFusion.getImage( type, imgLoader, vd, false );

					final FloatProcessor fp =
							toProcessor( ExtractPSF.computeMaxProjection( img, new ArrayImgFactory< T >(), 2 ) );

					if ( stack == null )
						stack = new ImageStack( fp.getWidth(), fp.getHeight() );

					stack.addSlice( "Timepoint=" + t.getId(), fp);
				}

		final ImagePlus imp = new ImagePlus( "ViewSetupId=" + setup.getId(), stack );
		imp.setDimensions( 1, 1, stack.getSize() );
		imp.show();
	}

	return true;
}
 
Example 5
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relGt(Double val, FloatProcessor mat) {
    float v = val.floatValue();
    FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight());
    for(int x = 0; x < mat.getWidth(); x++) {
        for(int y = 0; y < mat.getHeight(); y++) {
            res.setf(x, y, ((v > mat.getf(x, y)) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 6
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relEq(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 7
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 8
Source File: DownsamplerTest.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final private static void testFloat( FloatProcessor ipFloat )
{
	final double min = ipFloat.getMin();
	final double max = ipFloat.getMax();
	
	while( ipFloat.getWidth() > 32 )
	{
		ipFloat = Downsampler.downsampleFloatProcessor( ipFloat );
		ipFloat.setMinAndMax( min, max );
	}
}
 
Example 9
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Divide values of one image by values of the other image.
 * 
 * The images are required to be of the same size.
 *
 * @param fp1 an input image which the other input image ({@code fp2}) will be divided by
 * @param fp2 another input image which will divide the {@code fp1}
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fp3 = fp1 / fp2}
 */
public static FloatProcessor divide(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: 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 11
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor modulo(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());
    float tmp;
    for (int i = 0, im = a.getWidth(); i < im; i++) {
        for (int j = 0, jm = a.getHeight(); j < jm; j++) {
            tmp = a.getf(i, j) / b.getf(i, j);
            res.setf(i, j, a.getf(i, j) - (((float)((int)tmp)) * b.getf(i, j)));
        }
    }
    return res;
}
 
Example 12
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 13
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add a scalar value to an image.
 * 
 * @param val an input value will be added to the input image ({@code fp})
 * @param fp an input image
 * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fpv = val + fp}
 */
public static FloatProcessor add(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 14
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relNeq(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 15
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static FloatProcessor relLt(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, ((v < mat.getf(x, y)) ? 1.0f : 0.0f));
        }
    }
    return res;
}
 
Example 16
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 17
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 18
Source File: EmitterModel.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public void generate(FloatProcessor img) {
    double [] params = new double[molecule.values.length];
    for(int i = 0; i < params.length; i++) {
        params[i] = molecule.values[i];
    }
    //
    int width = img.getWidth(), height = img.getHeight();
    for(int x = (int)(molecule.getX() - region), xm = (int)(molecule.getX() + region); x <= xm; x++) {
        if((x < 0) || (x >= width)) continue;
        for(int y = (int)(molecule.getY() - region), ym = (int)(molecule.getY() + region); y <= ym; y++) {
            if((y < 0) || (y >= height)) continue;
            img.setf(x, y, img.getf(x, y) + (float)model.getValue(params, x+0.5, y+0.5));
        }
    }
}
 
Example 19
Source File: FullImageFitting.java    From thunderstorm with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<Molecule> estimateParameters(FloatProcessor image, List<Point> detections) throws StoppedByUserException {
    List<Molecule> results = new ArrayList<Molecule>();
    try {
        int w = image.getWidth();
        int h = image.getHeight();
        int x0 = w / 2;
        int y0 = h / 2;
        initializeGrid(x0, y0, w, h);
        int maxI = getBestDetection(detections);
        SubImage subImage = new SubImage(
                image.getWidth(), image.getHeight(),
                xgrid, ygrid, getImageData(image),
                detections.get(maxI).x.doubleValue() - x0,
                detections.get(maxI).y.doubleValue() - y0);

        Molecule psf = fitter.fit(subImage);
        if(psf.isSingleMolecule()) {
            if(checkIsInSubimage(psf.getX(), psf.getY(), image.getWidth(), image.getHeight())) {
                psf.setX(psf.getX() + x0 + 0.5);
                psf.setY(psf.getY() + y0 + 0.5);
                psf.setDetections(null);
                MultipleLocationsImageFitting.appendGoodnessOfFit(psf, fitter, subImage);
                MultipleLocationsImageFitting.appendCalculatedUncertainty(psf);
                results.add(psf);
            }
        } else {
            for(Molecule m : psf.getDetections()) {
                if(checkIsInSubimage(m.getX(), m.getY(), image.getWidth(), image.getHeight())) {
                    m.setX(m.getX() + x0 + 0.5);
                    m.setY(m.getY() + y0 + 0.5);
                    MultipleLocationsImageFitting.appendGoodnessOfFit(m, fitter, subImage);
                    MultipleLocationsImageFitting.appendCalculatedUncertainty(m);
                    results.add(m);
                }
            }
            psf.setDetections(null);
        }
    } catch(Exception ex) {
        //
    }
    return results;
}
 
Example 20
Source File: ImageMath.java    From thunderstorm with GNU General Public License v3.0 4 votes vote down vote up
public static FloatProcessor abs(FloatProcessor mat) {
    FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight(), (float [])mat.getPixelsCopy(), null);
    res.abs();
    res.setMask(mat.getMask());
    return res;
}