public static void drawFeatureDescriptor( final FloatProcessor fp, final Feature f ) { fp.setMinAndMax( 0.0, 1.0 ); final int w = ( int )Math.sqrt( f.descriptor.length ); for ( int y = 0; y < w; ++ y ) for ( int x = 0; x < w; ++x ) fp.setf( x, y, f.descriptor[ y * w + x ] ); }
public static void drawFeatureDescriptor( final FloatProcessor fp, final Feature f ) { fp.setMinAndMax( 0.0, 1.0 ); final int w = ( int )Math.sqrt( f.descriptor.length ); for ( int y = 0; y < w; ++ y ) for ( int x = 0; x < w; ++x ) fp.setf( x, y, f.descriptor[ y * w + x ] ); }
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)); } }
public FloatProcessor generatePoissonNoise(int width, int height, double stddev_photons) { FloatProcessor img = new FloatProcessor(width, height); for(int x = 0; x < width; x++) for(int y = 0; y < height; y++) img.setf(x, y, (float)(rand.nextPoisson(stddev_photons))) ; return img; }
public FloatProcessor generateGaussianNoise(int width, int height, double mean, double variance) { double sigma = sqrt(variance); FloatProcessor img = new FloatProcessor(width, height); for(int x = 0; x < width; x++) for(int y = 0; y < height; y++) img.setf(x, y, (float)rand.nextGaussian(mean, sigma)); return img; }
/** * 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; }
/** * 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; }
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 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 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; }
private static final void iterate( final Cursor< FloatType > c0, final FloatProcessor fp, final int minX, final int minY ) { c0.fwd(); fp.setf( c0.getIntPosition( 0 ) - minX, c0.getIntPosition( 1 ) - minY, c0.get().get() ); }
public FloatProcessor generateBackground(int width, int height, Drift drift, Range bkg) { // padd the background image; crop the center of the image later, after the drift is applied FloatProcessor img = new FloatProcessor(width + 2*(int)ceil(drift.dist), height + 2*(int)ceil(drift.dist)); for(int x = 0, w = img.getWidth(); x < w; x++) for(int y = 0, h = img.getHeight(); y < h; y++) img.setf(x, y, (float)getNextUniform(bkg.from, bkg.to)); IFilter filter = new BoxFilter(1+2*(int)(((double)Math.min(width, width))/8.0)); return filter.filterImage(img); }
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 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; }
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 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 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; }