use of ij.plugin.filter.RankFilters in project imagingbook-common by imagingbook.
the class BernsenThresholder method getThreshold.
@Override
public ByteProcessor getThreshold(ByteProcessor I) {
final int M = I.getWidth();
final int N = I.getHeight();
ByteProcessor Imin = (ByteProcessor) I.duplicate();
ByteProcessor Imax = (ByteProcessor) I.duplicate();
RankFilters rf = new RankFilters();
rf.rank(Imin, params.radius, RankFilters.MIN);
rf.rank(Imax, params.radius, RankFilters.MAX);
int q = (params.bgMode == BackgroundMode.DARK) ? 256 : 0;
ByteProcessor Q = new ByteProcessor(M, N);
for (int v = 0; v < N; v++) {
for (int u = 0; u < M; u++) {
int gMin = Imin.get(u, v);
int gMax = Imax.get(u, v);
int c = gMax - gMin;
if (c >= params.cmin)
Q.set(u, v, (gMin + gMax) / 2);
else
Q.set(u, v, q);
}
}
return Q;
}
use of ij.plugin.filter.RankFilters in project imagingbook-common by imagingbook.
the class SauvolaThresholder method getThreshold.
@Override
public ByteProcessor getThreshold(ByteProcessor I) {
FloatProcessor mean = (FloatProcessor) I.convertToFloat();
FloatProcessor var = (FloatProcessor) mean.duplicate();
RankFilters rf = new RankFilters();
rf.rank(mean, params.radius, RankFilters.MEAN);
Imean = mean;
rf.rank(var, params.radius, RankFilters.VARIANCE);
var.sqrt();
Isigma = var;
int width = I.getWidth();
int height = I.getHeight();
final double kappa = params.kappa;
final double sigmaMax = params.sigmaMax;
final boolean darkBg = (params.bgMode == BackgroundMode.DARK);
ByteProcessor Q = new ByteProcessor(width, height);
for (int v = 0; v < height; v++) {
for (int u = 0; u < width; u++) {
final double sigma = Isigma.getf(u, v);
final double mu = Imean.getf(u, v);
final double diff = kappa * (sigma / sigmaMax - 1);
int q = (int) Math.rint((darkBg) ? mu * (1 - diff) : mu * (1 + diff));
if (q < 0)
q = 0;
if (q > 255)
q = 255;
Q.set(u, v, q);
}
}
return Q;
}
use of ij.plugin.filter.RankFilters in project TrakEM2 by trakem2.
the class RankFilter method process.
@Override
public ImageProcessor process(ImageProcessor ip) {
RankFilters rf = new RankFilters();
rf.rank(ip, radius, RankFilters.MEDIAN);
return ip;
}
Aggregations