/** Returns the value of the pixel at (x,y) in a one element int array. iArray is an optiona preallocated array. */ public int[] getPixel(int x, int y, int[] iArray) { if (iArray==null) iArray = new int[1]; iArray[0] = (int)getPixelValue(x, y); return iArray; }
/** Returns the value of the pixel at (x,y) in a one element int array. iArray is an optiona preallocated array. */ public int[] getPixel(int x, int y, int[] iArray) { if (iArray==null) iArray = new int[1]; iArray[0] = (int)getPixelValue(x, y); return iArray; }
@Override public double getValue(int row, int col) { return floatProcessor.getPixelValue(col, row); }
int[] smooth(int[] a, int n) { FloatProcessor fp = new FloatProcessor(n, 1); for (int i=0; i<n; i++) fp.putPixelValue(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] = (int)Math.round(fp.getPixelValue(i, 0)); return a; }
int[] smooth(int[] a, int n) { FloatProcessor fp = new FloatProcessor(n, 1); for (int i=0; i<n; i++) fp.putPixelValue(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] = (int)Math.round(fp.getPixelValue(i, 0)); return a; }
/** * Apply a binary {@code threshold} to the {@code image}. * * Instead of implicitly setting the pixels in thresholded image to 0 and 1, * the pixels with their values equal or greater than threshold are set * to {@code high_val}. The rest is res to {@code low_value}. * * Note that this method <strong>modifies</strong> the input image. * * @param image an input image * @param threshold a threshold value * @param low_val value that the pixels with values lesser then {@code threshold} are set to * @param high_val value that the pixels with values equal or greater then {@code threshold} are set to */ public static void threshold(FloatProcessor image, float threshold, float low_val, float high_val) { for (int i = 0, im = image.getWidth(); i < im; i++) { for (int j = 0, jm = image.getHeight(); j < jm; j++) { if (image.getPixelValue(i, j) >= threshold) { image.setf(i, j, high_val); } else { image.setf(i, j, low_val); } } } }
/** * Detection is performed by applying a grayscale dilation with square * uniform kernel of specified radius and then selecting points with their * intensity same before and after the dilation and at the same time at * least as high as a specified threshold. * * @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 { MaxFilterDetector detector = new MaxFilterDetector(RADIUS.getValue(), Thresholder.getThreshold(THRESHOLD.getValue())); return detector .detect(new GrayScaleImageImpl(image)) .stream() .map(point2D -> new Point<Double>( point2D.getX(), point2D.getY(), (double) image.getPixelValue((int) point2D.getX(), (int) point2D.getY()))) .collect(Collectors.toList()); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Multiply an image by a scalar value. * * @param val an input value which the input image ({@code fp}) will be multiplied with * @param fp an input image * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fpv = val * fp} */ public static FloatProcessor multiply(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; }
/** * 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; }
/** * 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; }
/** * 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; }
for (int x = 0; x < fp.getWidth(); x++) final float newValue = fp.getPixelValue(x, y); final float oldValue = out.getPixelValue(x - startX + Math.round(iI.offset[0]), y - startY + Math.round(iI.offset[1])); out.putPixelValue(x - startX + Math.round(iI.offset[0]), y - startY + Math.round(iI.offset[1]), Math.max(newValue, oldValue));
/** * Calculate a {@code val}-th power of an image {@code fp}. * * @param val {@code val}-th power of {@code fp} * @param fp an input image * @return a <strong>new instance</strong> of FloatProcessor: {@mathjax fpv = fp ^ val} */ public static FloatProcessor power(FloatProcessor fp, float val) { 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, (float)pow((double)fp.getPixelValue(i, j), (double)val)); } } return out; }