/** * Construct with the given support region for selecting pixels to take the * median from. The support mask is a set of <code>n</code> relative x, y * offsets from the pixel currently being processed, and can be created * using the methods or constants in the {@link FilterSupport} class. * * @param support * the support coordinates */ public MinMaxAnalyser(Set<Pixel> support) { this.support = support; if (FilterSupport.isBlockSupport(support)) { blockWidth = FilterSupport.getSupportWidth(support); blockHeight = FilterSupport.getSupportHeight(support); } }
/** * Test whether the given support is a centred block * * @param support * the support * @return true if block, false otherwise */ public final static boolean isBlockSupport(final Set<Pixel> support) { final int sw = getSupportWidth(support); final int sh = getSupportHeight(support); return sw * sh == support.size() && isCentred(support); }
@Override public void processImage(FImage image) { final MinMaxAnalyser minimax = new MinMaxAnalyser(FilterSupport.createBlockSupport(sizeX, sizeY)); minimax.analyseImage(image); final float[][] minpix = minimax.min.pixels; final float[][] maxpix = minimax.max.pixels; final float[][] ipix = image.pixels; for (int y = 0; y < image.height; y++) for (int x = 0; x < image.width; x++) ipix[y][x] = (ipix[y][x] - minpix[y][x]) > (maxpix[y][x] - ipix[y][x]) ? 1 : 0; } }
@Override public void processImage(FImage image) { final MinMaxAnalyser minimax = new MinMaxAnalyser(FilterSupport.createBlockSupport(sizeX, sizeY)); minimax.analyseImage(image); final float[][] minpix = minimax.min.pixels; final float[][] maxpix = minimax.max.pixels; final float[][] ipix = image.pixels; for (int y = 0; y < image.height; y++) for (int x = 0; x < image.width; x++) ipix[y][x] = (ipix[y][x] - minpix[y][x]) > (maxpix[y][x] - ipix[y][x]) ? 1 : 0; } }
/** * Construct with the given support region for selecting pixels to take the * median from. The support mask is a set of <code>n</code> relative x, y * offsets from the pixel currently being processed, and can be created * using the methods or constants in the {@link FilterSupport} class. * * @param support * the support coordinates */ public MinFilter(Set<Pixel> support) { this.support = support; if (FilterSupport.isBlockSupport(support)) { blockWidth = FilterSupport.getSupportWidth(support); blockHeight = FilterSupport.getSupportHeight(support); } }
@Override public void processImage(FImage image) { final FImage tmp = image.process(new MedianFilter(FilterSupport.createBlockSupport(sizeX, sizeY))); final float[][] tpix = tmp.pixels; final float[][] ipix = image.pixels; for (int y = 0; y < image.height; y++) for (int x = 0; x < image.width; x++) tpix[y][x] = ipix[y][x] < (tpix[y][x] - offset) ? 0f : 1f; image.internalAssign(tmp); } }
/** * Test whether the given support is a centred block * * @param support * the support * @return true if block, false otherwise */ public final static boolean isBlockSupport(final Set<Pixel> support) { final int sw = getSupportWidth(support); final int sh = getSupportHeight(support); return sw * sh == support.size() && isCentred(support); }
/** * Construct with the given support region for selecting pixels to take the * median from. The support mask is a set of <code>n</code> relative x, y * offsets from the pixel currently being processed, and can be created * using the methods or constants in the {@link FilterSupport} class. * * @param support * the support coordinates */ public MinMaxAnalyser(Set<Pixel> support) { this.support = support; if (FilterSupport.isBlockSupport(support)) { blockWidth = FilterSupport.getSupportWidth(support); blockHeight = FilterSupport.getSupportHeight(support); } }
@Override public void processImage(FImage image) { final FImage tmp = image.process(new MedianFilter(FilterSupport.createBlockSupport(sizeX, sizeY))); final float[][] tpix = tmp.pixels; final float[][] ipix = image.pixels; for (int y = 0; y < image.height; y++) for (int x = 0; x < image.width; x++) tpix[y][x] = ipix[y][x] < (tpix[y][x] - offset) ? 0f : 1f; image.internalAssign(tmp); } }
/** * Construct with the given support region for selecting pixels to take the * median from. The support mask is a set of <code>n</code> relative x, y * offsets from the pixel currently being processed, and can be created * using the methods or constants in the {@link FilterSupport} class. * * @param support * the support coordinates */ public MinFilter(Set<Pixel> support) { this.support = support; if (FilterSupport.isBlockSupport(support)) { blockWidth = FilterSupport.getSupportWidth(support); blockHeight = FilterSupport.getSupportHeight(support); } }
@Override public void processImage(FImage image) { final FImage contrast = image.process(new LocalContrastFilter(FilterSupport.createBlockSupport(sizeX, sizeY))); final FImage avg = image.process(new AverageBoxFilter(sizeX, sizeY)); final float[][] cpix = contrast.pixels; final float[][] mpix = avg.pixels; final float[][] ipix = image.pixels; for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { if (cpix[y][x] < threshold) ipix[y][x] = (mpix[y][x] >= 128) ? 1 : 0; else ipix[y][x] = (ipix[y][x] >= mpix[y][x]) ? 1 : 0; } } } }
/** * Construct with the given support region for selecting pixels to take the * median from. The support mask is a set of <code>n</code> relative x, y * offsets from the pixel currently being processed, and can be created * using the methods or constants in the {@link FilterSupport} class. * * @param support * the support coordinates */ public MaxFilter(Set<Pixel> support) { this.support = support; if (FilterSupport.isBlockSupport(support)) { blockWidth = FilterSupport.getSupportWidth(support); blockHeight = FilterSupport.getSupportHeight(support); } }
@Override public void processImage(FImage image) { final FImage contrast = image.process(new LocalContrastFilter(FilterSupport.createBlockSupport(sizeX, sizeY))); final FImage avg = image.process(new AverageBoxFilter(sizeX, sizeY)); final float[][] cpix = contrast.pixels; final float[][] mpix = avg.pixels; final float[][] ipix = image.pixels; for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { if (cpix[y][x] < threshold) ipix[y][x] = (mpix[y][x] >= 128) ? 1 : 0; else ipix[y][x] = (ipix[y][x] >= mpix[y][x]) ? 1 : 0; } } } }
/** * Construct with the given support region for selecting pixels to take the * median from. The support mask is a set of <code>n</code> relative x, y * offsets from the pixel currently being processed, and can be created * using the methods or constants in the {@link FilterSupport} class. * * @param support * the support coordinates */ public MaxFilter(Set<Pixel> support) { this.support = support; if (FilterSupport.isBlockSupport(support)) { blockWidth = FilterSupport.getSupportWidth(support); blockHeight = FilterSupport.getSupportHeight(support); } }
static MBFImage diff(FImage bg, FImage fg) { final FImage df = new FImage(bg.getWidth(), bg.getHeight()); final float[][] dff = df.pixels; final float[][] bgfr = bg.pixels; final float[][] fgfr = fg.pixels; for (int y = 0; y < df.getHeight(); y++) { for (int x = 0; x < df.getWidth(); x++) { final float dr = bgfr[y][x] - fgfr[y][x]; final float ssd = dr * dr; if (ssd < 0.03) { dff[y][x] = 0; } else { dff[y][x] = 1; } } } // Dilate.dilate(df, 1); // Erode.erode(df, 2); df.processInplace(new MedianFilter(FilterSupport.createBlockSupport(3, 3))); df.processInplace(new MedianFilter(FilterSupport.createBlockSupport(3, 3))); return df.toRGB(); } }
static MBFImage diff(FImage bg, FImage fg) { final FImage df = new FImage(bg.getWidth(), bg.getHeight()); final float[][] dff = df.pixels; final float[][] bgfr = bg.pixels; final float[][] fgfr = fg.pixels; for (int y = 0; y < df.getHeight(); y++) { for (int x = 0; x < df.getWidth(); x++) { final float dr = bgfr[y][x] - fgfr[y][x]; final float ssd = dr * dr; if (ssd < 0.03) { dff[y][x] = 0; } else { dff[y][x] = 1; } } } // Dilate.dilate(df, 1); // Erode.erode(df, 2); df.processInplace(new MedianFilter(FilterSupport.createBlockSupport(3, 3))); df.processInplace(new MedianFilter(FilterSupport.createBlockSupport(3, 3))); return df.toRGB(); } }