Java Code Examples for ij.process.FloatProcessor#getf()
The following examples show how to use
ij.process.FloatProcessor#getf() .
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: ImageMath.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
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 2
Source File: ValueToNoise.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
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 3
Source File: ValueToNoise.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
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: ValueToNoise.java From render with GNU General Public License v2.0 | 5 votes |
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 5
Source File: ValueToNoise.java From render with GNU General Public License v2.0 | 5 votes |
private static 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 6
Source File: DataGenerator.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
public Vector<EmitterModel> generateMolecules(int width, int height, FloatProcessor mask, double density, Range intensity_photons, IPsfUI psf) { MoleculeDescriptor descriptor = null; double[] params = new double[PSFModel.Params.PARAMS_LENGTH]; Vector<EmitterModel> molist = new Vector<EmitterModel>(); double gPpx = Units.NANOMETER_SQUARED.convertTo(Units.MICROMETER_SQUARED, sqr(CameraSetupPlugIn.getPixelSize())*width*height/(mask.getWidth()*mask.getHeight())) * density, p_px, p, fwhm0; double zFrom = psf.getZRange().from, zTo = psf.getZRange().to; for(int x = 0; x < mask.getWidth(); x++) { for(int y = 0; y < mask.getHeight(); y++) { p_px = gPpx * mask.getf(x, y); //expected number of molecules inside a pixel int nMols = p_px > 0 ? (int) rand.nextPoisson(p_px) : 0; //actual number of molecules inside a pixel for(int i = 0; i < nMols; i++) { double z = getNextUniform(zFrom, zTo); params[PSFModel.Params.X] = (x + 0.5 + getNextUniform(-0.5, +0.5)) * width / mask.getWidth(); params[PSFModel.Params.Y] = (y + 0.5 + getNextUniform(-0.5, +0.5)) * height / mask.getHeight(); params[PSFModel.Params.SIGMA] = psf.getSigma1(z); params[PSFModel.Params.SIGMA1] = psf.getSigma1(z); params[PSFModel.Params.SIGMA2] = psf.getSigma2(z); params[PSFModel.Params.INTENSITY] = getNextUniform(intensity_photons.from, intensity_photons.to); params[PSFModel.Params.ANGLE] = psf.getAngle(); PSFModel model = psf.getImplementation(); Molecule mol = model.newInstanceFromParams(params, Units.PHOTON, false); if(psf.is3D()) { mol.addParam(PSFModel.Params.LABEL_Z, Units.NANOMETER, z); } //set a common MoleculeDescriptor for all molecules in a frame to save memory if(descriptor != null){ mol.descriptor = descriptor; }else{ descriptor = mol.descriptor; } molist.add(new EmitterModel(model, mol)); } } } return molist; }
Example 7
Source File: ImageMath.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
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 8
Source File: ImageMath.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
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 9
Source File: CorrelationDriftEstimator.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
private static void multiplyImageByGaussianMask(Point2D.Double gaussianCenter, double gaussianSigma, FloatProcessor image) { for(int y = 0; y < image.getHeight(); y++) { for(int x = 0; x < image.getWidth(); x++) { double maskValue = MathProxy.exp(-(MathProxy.sqr(x - gaussianCenter.x) + MathProxy.sqr(y - gaussianCenter.y)) / (2 * gaussianSigma * gaussianSigma)); float newValue = (float) (image.getf(x, y) * maskValue); image.setf(x, y, newValue); } } }
Example 10
Source File: DataGenerator.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
/** * Replaces each pixel value with a sample from a Gamma distribution with shape equal to the original pixel value and scale equal to the gain parameter. */ FloatProcessor sampleGamma(FloatProcessor fp, double gain){ for(int i = 0; i < fp.getPixelCount(); i ++){ double value = fp.getf(i); value = rand.nextGamma(value + 1e-10, gain); fp.setf(i, (float)value); } return fp; }
Example 11
Source File: DataGenerator.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
/** * Replaces each pixel value with a sample from a poisson distribution with mean value equal to the pixel original value. */ FloatProcessor samplePoisson(FloatProcessor fp){ for(int i = 0; i < fp.getPixelCount(); i ++){ float mean = fp.getf(i); double value = mean > 0 ? (rand.nextPoisson(mean)) : 0; fp.setf(i, (float)value); } return fp; }
Example 12
Source File: ImageMath.java From thunderstorm with GNU General Public License v3.0 | 4 votes |
/** * 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 13
Source File: DistanceTransform5x5Float.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
private void forwardScan(FloatProcessor distMap, ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Forward Scan")); // Initialize pairs of offset and weights int[] dx = new int[]{-1, +1, -2, -1, 0, +1, +2, -1}; int[] dy = new int[]{-2, -2, -1, -1, -1, -1, -1, 0}; float[] dw = new float[] { weights[2], weights[2], weights[2], weights[1], weights[0], weights[1], weights[2], weights[0] }; // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // Iterate over pixels for (int y = 0; y < sizeY; y++) { this.fireProgressChanged(this, y, sizeY); for (int x = 0; x < sizeX; x++) { // get current label int label = (int) labelImage.getf(x, y); // do not process background pixels if (label == 0) continue; // current distance value float currentDist = distMap.getf(x, y); float newDist = currentDist; // iterate over neighbors for (int i = 0; i < dx.length; i++) { // compute neighbor coordinates int x2 = x + dx[i]; int y2 = y + dy[i]; // check bounds if (x2 < 0 || x2 >= sizeX) continue; if (y2 < 0 || y2 >= sizeY) continue; if ((int) labelImage.getf(x2, y2) != label) { // Update with distance to nearest different label newDist = Math.min(newDist, dw[i]); } else { // Increment distance newDist = Math.min(newDist, distMap.getf(x2, y2) + dw[i]); } } if (newDist < currentDist) { distMap.setf(x, y, newDist); } } } this.fireProgressChanged(this, sizeY, sizeY); }
Example 14
Source File: DistanceTransform5x5Float.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
private void backwardScan(FloatProcessor distMap, ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Backward Scan")); int[] dx = new int[]{+1, -1, +2, +1, 0, -1, -2, +1}; int[] dy = new int[]{+2, +2, +1, +1, +1, +1, +1, 0}; float[] dw = new float[] { weights[2], weights[2], weights[2], weights[1], weights[0], weights[1], weights[2], weights[0] }; // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // Iterate over pixels for (int y = sizeY-1; y >= 0; y--) { this.fireProgressChanged(this, sizeY-1-y, sizeY); for (int x = sizeX-1; x >= 0; x--) { // get current label int label = (int) labelImage.getf(x, y); // do not process background pixels if (label == 0) continue; // current distance value float currentDist = distMap.getf(x, y); float newDist = currentDist; // iterate over neighbors for (int i = 0; i < dx.length; i++) { // compute neighbor coordinates int x2 = x + dx[i]; int y2 = y + dy[i]; // check bounds if (x2 < 0 || x2 >= sizeX) continue; if (y2 < 0 || y2 >= sizeY) continue; if ((int) labelImage.getf(x2, y2) != label) { // Update with distance to nearest different label newDist = Math.min(newDist, dw[i]); } else { // Increment distance newDist = Math.min(newDist, distMap.getf(x2, y2) + dw[i]); } } if (newDist < currentDist) { distMap.setf(x, y, newDist); } } } this.fireProgressChanged(this, sizeY, sizeY); }
Example 15
Source File: DistanceTransform3x3Float.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
private void forwardScan(FloatProcessor distMap, ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Forward Scan")); // Initialize pairs of offset and weights int[] dx = new int[]{-1, 0, +1, -1}; int[] dy = new int[]{-1, -1, -1, 0}; float[] dw = new float[]{weights[1], weights[0], weights[1], weights[0]}; // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // Iterate over pixels for (int y = 0; y < sizeY; y++) { this.fireProgressChanged(this, y, sizeY); for (int x = 0; x < sizeX; x++) { // get current label int label = (int) labelImage.getf(x, y); // do not process background pixels if (label == 0) continue; // current distance value float currentDist = distMap.getf(x, y); float newDist = currentDist; // iterate over neighbors for (int i = 0; i < dx.length; i++) { // compute neighbor coordinates int x2 = x + dx[i]; int y2 = y + dy[i]; // check bounds if (x2 < 0 || x2 >= sizeX) continue; if (y2 < 0 || y2 >= sizeY) continue; if ((int) labelImage.getf(x2, y2) != label) { // Update with distance to nearest different label newDist = Math.min(newDist, dw[i]); } else { // Increment distance newDist = Math.min(newDist, distMap.getf(x2, y2) + dw[i]); } } if (newDist < currentDist) { distMap.setf(x, y, newDist); } } } this.fireProgressChanged(this, sizeY, sizeY); }
Example 16
Source File: DistanceTransform3x3Float.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
private void backwardScan(FloatProcessor distMap, ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Backward Scan")); // Initialize pairs of offset and weights int[] dx = new int[]{+1, 0, -1, +1}; int[] dy = new int[]{+1, +1, +1, 0}; float[] dw = new float[]{weights[1], weights[0], weights[1], weights[0]}; // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // Iterate over pixels for (int y = sizeY-1; y >= 0; y--) { this.fireProgressChanged(this, sizeY-1-y, sizeY); for (int x = sizeX-1; x >= 0; x--) { // get current label int label = (int) labelImage.getf(x, y); // do not process background pixels if (label == 0) continue; // current distance value float currentDist = distMap.getf(x, y); float newDist = currentDist; // iterate over neighbors for (int i = 0; i < dx.length; i++) { // compute neighbor coordinates int x2 = x + dx[i]; int y2 = y + dy[i]; // check bounds if (x2 < 0 || x2 >= sizeX) continue; if (y2 < 0 || y2 >= sizeY) continue; if ((int) labelImage.getf(x2, y2) != label) { // Update with distance to nearest different label newDist = Math.min(newDist, dw[i]); } else { // Increment distance newDist = Math.min(newDist, distMap.getf(x2, y2) + dw[i]); } } if (newDist < currentDist) { distMap.setf(x, y, newDist); } } } this.fireProgressChanged(this, sizeY, sizeY); }
Example 17
Source File: CentroidOfConnectedComponentsDetector.java From thunderstorm with GNU General Public License v3.0 | 3 votes |
/** * Detection algorithm works simply by setting all values lower than a * threshold to zero, splitting close peaks by watershed and finding * centroids of connected components. * * In more detail this is how it is done: * <ol> * <li>apply the threshold to get thresholded binary image</li> * <li>in the original image, set intensity to zero, where the thresholded * image is zero. Leave the grayscale value otherwise. * </li> * <li> * perform a watershed transform (this is the trick for recognition of more * connected molecules * </li> * <li>AND the thresholded image with watershed image</li> * <li> * then we think of the resulting image as an undirected graph with * 8-connectivity and find all connected components with the same id * </li> * <li> * finally, positions of molecules are calculated as centroids of components * with the same id * </li> * </ol> * * @param image an input image * @return a {@code Vector} of {@code Points} containing positions of * detected molecules */ @Override public List<Point> detectMoleculeCandidates(FloatProcessor image) throws FormulaParserException { //keep a local threshold value so the method remains thread safe float localThresholdValue = Thresholder.getThreshold(threshold); thresholdValue = localThresholdValue; //publish the calculated threshold,(not thread safe but only used for preview logging) FloatProcessor thresholdedImage = (FloatProcessor) image.duplicate(); threshold(thresholdedImage, localThresholdValue, 0.0f, 255.0f); FloatProcessor maskedImage = applyMask(image, thresholdedImage); if(useWatershed) { ImageJ_MaximumFinder watershedImpl = new ImageJ_MaximumFinder(); ByteProcessor watershedImage = watershedImpl.findMaxima(maskedImage, 0, ImageProcessor.NO_THRESHOLD, MaximumFinder.SEGMENTED, false, false); FloatProcessor thresholdImageANDWatershedImage = applyMask(thresholdedImage, (FloatProcessor) watershedImage.convertToFloat()); maskedImage = thresholdImageANDWatershedImage; } // finding a center of gravity (with subpixel precision) Vector<Point> detections = new Vector<Point>(); for(Graph.ConnectedComponent c : Graph.getConnectedComponents((ImageProcessor) maskedImage, Graph.CONNECTIVITY_8)) { Point pt = c.centroid(); pt.val = new Double(image.getf((int)Math.round(pt.x.doubleValue()), (int)Math.round(pt.y.doubleValue()))); detections.add(pt); } return detections; }