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)); } }
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)); } }
/** * 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; }
/** * 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; }
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; }
float[] smooth(float[] a, int n) { FloatProcessor fp = new FloatProcessor(n, 1); for (int i=0; i<n; i++) fp.setf(i, 0, a[i]); GaussianBlur gb = new GaussianBlur(); gb.blur1Direction(fp, 2.0, 0.01, true, 0); for (int i=0; i<n; i++) a[i] = fp.getf(i, 0); return a; }
float[] smooth(float[] a, int n) { FloatProcessor fp = new FloatProcessor(n, 1); for (int i=0; i<n; i++) fp.setf(i, 0, a[i]); GaussianBlur gb = new GaussianBlur(); gb.blur1Direction(fp, 2.0, 0.01, true, 0); for (int i=0; i<n; i++) a[i] = fp.getf(i, 0); return a; }
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; }
public static FloatProcessor relGt(FloatProcessor mat, Double val) { 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, ((mat.getf(x, y) > v) ? 1.0f : 0.0f)); } } return res; }
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; }
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; }
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; }
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; }
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; }
public static FloatProcessor relGt(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; }
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; }
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); } } }
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; }
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; }
public double getDiamaterMaximumInscribedCircle() { ImagePlus help = generateBlobImage(this); ImageProcessor ipHelp = help.getProcessor(); ipHelp.invert(); EDM dm = new EDM(); FloatProcessor fp = dm.makeFloatEDM (ipHelp, 0, false); MaximumFinder mf = new MaximumFinder(); ByteProcessor bp = mf.findMaxima(fp, 0.5, ImageProcessor.NO_THRESHOLD, MaximumFinder.SINGLE_POINTS, false, true); Polygon pl = mf.getMaxima(bp, 0, true); return fp.getf(pl.xpoints[0], pl.ypoints[0])*2*cal.getX(1); }