@Override public ImageProcessor process(ImageProcessor ip) { RankFilters rf = new RankFilters(); rf.rank(ip, radius, RankFilters.MEDIAN); return ip; }
max = getAreaMax(cache, x, cachePointers, 0, -Float.MAX_VALUE, minMaxOutliersSign); if (minOrMax) { values[valuesP] = max*minMaxOutliersSign; getAreaSums(cache, x, cachePointers, sums); } else { if (minOrMaxOrOutliers) { float newPointsMax = getSideMax(cache, x, cachePointers, true, minMaxOutliersSign); if (newPointsMax >= max) { //compare with previous maximum 'max' max = newPointsMax; } else { float removedPointsMax = getSideMax(cache, x, cachePointers, false, minMaxOutliersSign); if (removedPointsMax >= max) max = getAreaMax(cache, x, cachePointers, 1, newPointsMax, minMaxOutliersSign); addSideSums(cache, x, cachePointers, sums); if (Double.isNaN(sums[0])) //avoid perpetuating NaNs into remaining line fullCalculation = true; median = getNaNAwareMedian(cache, x, cachePointers, medianBuf1, medianBuf2, kNPoints, median); } else median = getMedian(cache, x, cachePointers, medianBuf1, medianBuf2, kNPoints, median); values[valuesP] = median; } else if (filterType == OUTLIERS) { float v = cache[cacheLineP+x]; if (v*minMaxOutliersSign+threshold < max) { //for low outliers: median can't be higher than max (minMaxOutliersSign is +1) median = getMedian(cache, x, cachePointers, medianBuf1, medianBuf2, kNPoints, median); if (v*minMaxOutliersSign+threshold < median*minMaxOutliersSign)
int kHeight = kHeight(lineRadii); int kRadius = kRadius(lineRadii); int kNPoints = kNPoints(lineRadii); int[]cachePointers = makeCachePointers(lineRadii, cacheWidth); int y = arrayMax(yForThread) + 1; // y of the next line that needs processing yForThread[threadNumber] = y; if (time-lastTime>100) { lastTime = time; showProgress((y-roi.y)/(double)(roi.height), rgb); if (Thread.currentThread().isInterrupted() || (imp!= null && IJ.escapePressed())) { aborted[0] = true; int slowestThreadY = arrayMinNonNegative(yForThread); // non-synchronized check to avoid overhead if (y - slowestThreadY + kHeight > cacheHeight) { // we would overwrite data needed by another thread synchronized(this) { slowestThreadY = arrayMinNonNegative(yForThread); //recheck whether we have to wait if (y - slowestThreadY + kHeight > cacheHeight) { do { slowestThreadY = arrayMinNonNegative(yForThread); } while (y - slowestThreadY + kHeight > cacheHeight); int yStartReading = y==roi.y ? Math.max(roi.y-kHeight/2, 0) : y+kHeight/2; for (int yNew = yStartReading; yNew<=y+kHeight/2; yNew++) { //only 1 line except at start readLineToCacheOrPad(pixels, width, height, roi.y, xminInside, widthInside, cache, cacheWidth, cacheHeight, padLeft, padRight, colorChannel, kHeight, yNew);
/** Filters an image by any method except 'despecle' or 'remove outliers'. * @param ip The ImageProcessor that should be filtered (all 4 types supported) * @param radius Determines the kernel size, see Process>Filters>Show Circular Masks. * Must not be negative. No checking is done for large values that would * lead to excessive computing times. * @param filterType May be MEAN, MIN, MAX, VARIANCE, or MEDIAN. */ public void rank(ImageProcessor ip, double radius, int filterType) { rank(ip, radius, filterType, 0, 50f); }
ImageProcessor mask = ip.getMask(); Rectangle roi1 = null; int[] lineRadii = makeLineRadii(radius); for (int ch=0; ch<ip.getNChannels(); ch++) { int filterType1 = filterType; if (isMultiStepFilter(filterType)) { filterType1 = (filterType==OPEN) ? MIN : MAX; if (isImagePart) { //composite filters ('open maxima' etc.) need larger area in first step int kRadius = kRadius(lineRadii); int kHeight = kHeight(lineRadii); Rectangle roiClone = (Rectangle)roi.clone(); roiClone.grow(kRadius, kHeight/2); doFiltering(ip, lineRadii, filterType1, minMaxOutliersSign, threshold, ch, aborted); if (aborted[0]) break; if (isMultiStepFilter(filterType)) { ip.setRoi(roi); ip.setMask(mask); int filterType2 = (filterType==OPEN) ? MAX : MIN; doFiltering(ip, lineRadii, filterType2, minMaxOutliersSign, threshold, ch, aborted); if (aborted[0]) break; if (isImagePart) resetRoiBoundary(ip, roi, roi1);
return; int kHeight = kHeight(lineRadii); int kRadius = kRadius(lineRadii); final int cacheWidth = roi.width+2*kRadius; final int cacheHeight = kHeight + (numThreads>1 ? 2*numThreads : 0); doFiltering(ip, lineRadii, cache, cacheWidth, cacheHeight, filterType, minMaxOutliersSign, threshold, colorChannel, yForThread, 0, aborted); showProgress(1.0, ip instanceof ColorProcessor); pass++;
int kHeight = kHeight(lineRadii); int kRadius = kRadius(lineRadii); int kNPoints = kNPoints(lineRadii); int[]cachePointers = makeCachePointers(lineRadii, cacheWidth); int y = arrayMax(yForThread) + 1; // y of the next line that needs processing yForThread[threadNumber] = y; if (time-lastTime>100) { lastTime = time; showProgress((y-roi.y)/(double)(roi.height), rgb); if (Thread.currentThread().isInterrupted() || (imp!= null && IJ.escapePressed())) { aborted[0] = true; int slowestThreadY = arrayMinNonNegative(yForThread); // non-synchronized check to avoid overhead if (y - slowestThreadY + kHeight > cacheHeight) { // we would overwrite data needed by another thread synchronized(this) { slowestThreadY = arrayMinNonNegative(yForThread); //recheck whether we have to wait if (y - slowestThreadY + kHeight > cacheHeight) { do { slowestThreadY = arrayMinNonNegative(yForThread); } while (y - slowestThreadY + kHeight > cacheHeight); int yStartReading = y==roi.y ? Math.max(roi.y-kHeight/2, 0) : y+kHeight/2; for (int yNew = yStartReading; yNew<=y+kHeight/2; yNew++) { //only 1 line except at start readLineToCacheOrPad(pixels, width, height, roi.y, xminInside, widthInside, cache, cacheWidth, cacheHeight, padLeft, padRight, colorChannel, kHeight, yNew);
/** Filters an image by any method except 'despecle' or 'remove outliers'. * @param ip The ImageProcessor that should be filtered (all 4 types supported) * @param radius Determines the kernel size, see Process>Filters>Show Circular Masks. * Must not be negative. No checking is done for large values that would * lead to excessive computing times. * @param filterType May be MEAN, MIN, MAX, VARIANCE, or MEDIAN. */ public void rank(ImageProcessor ip, double radius, int filterType) { rank(ip, radius, filterType, 0, 50f); }
ImageProcessor mask = ip.getMask(); Rectangle roi1 = null; int[] lineRadii = makeLineRadii(radius); for (int ch=0; ch<ip.getNChannels(); ch++) { int filterType1 = filterType; if (isMultiStepFilter(filterType)) { filterType1 = (filterType==OPEN) ? MIN : MAX; if (isImagePart) { //composite filters ('open maxima' etc.) need larger area in first step int kRadius = kRadius(lineRadii); int kHeight = kHeight(lineRadii); Rectangle roiClone = (Rectangle)roi.clone(); roiClone.grow(kRadius, kHeight/2); doFiltering(ip, lineRadii, filterType1, minMaxOutliersSign, threshold, ch, aborted); if (aborted[0]) break; if (isMultiStepFilter(filterType)) { ip.setRoi(roi); ip.setMask(mask); int filterType2 = (filterType==OPEN) ? MAX : MIN; doFiltering(ip, lineRadii, filterType2, minMaxOutliersSign, threshold, ch, aborted); if (aborted[0]) break; if (isImagePart) resetRoiBoundary(ip, roi, roi1);
return; int kHeight = kHeight(lineRadii); int kRadius = kRadius(lineRadii); final int cacheWidth = roi.width+2*kRadius; final int cacheHeight = kHeight + (numThreads>1 ? 2*numThreads : 0); doFiltering(ip, lineRadii, cache, cacheWidth, cacheHeight, filterType, minMaxOutliersSign, threshold, colorChannel, yForThread, 0, aborted); showProgress(1.0, ip instanceof ColorProcessor); pass++;
/** * Performs in-place dilation with a disk structuring element by calling the * ImageJ native RankFilters algorithm, using RankFilters.MAX option. * * @param image the image to process */ @Override public void inPlaceDilation(ImageProcessor image) { new RankFilters().rank(image, radius, RankFilters.MAX); }
public void run(ImageProcessor ip) { rank(ip, radius, filterType, whichOutliers, (float)threshold); if (IJ.escapePressed()) // interrupted by user? ip.reset(); }
max = getAreaMax(cache, x, cachePointers, 0, -Float.MAX_VALUE, minMaxOutliersSign); if (minOrMax) { values[valuesP] = max*minMaxOutliersSign; getAreaSums(cache, x, cachePointers, sums); } else { if (minOrMaxOrOutliers) { float newPointsMax = getSideMax(cache, x, cachePointers, true, minMaxOutliersSign); if (newPointsMax >= max) { //compare with previous maximum 'max' max = newPointsMax; } else { float removedPointsMax = getSideMax(cache, x, cachePointers, false, minMaxOutliersSign); if (removedPointsMax >= max) max = getAreaMax(cache, x, cachePointers, 1, newPointsMax, minMaxOutliersSign); addSideSums(cache, x, cachePointers, sums); if (Double.isNaN(sums[0])) //avoid perpetuating NaNs into remaining line fullCalculation = true; median = getNaNAwareMedian(cache, x, cachePointers, medianBuf1, medianBuf2, kNPoints, median); } else median = getMedian(cache, x, cachePointers, medianBuf1, medianBuf2, kNPoints, median); values[valuesP] = median; } else if (filterType == OUTLIERS) { float v = cache[cacheLineP+x]; if (v*minMaxOutliersSign+threshold < max) { //for low outliers: median can't be higher than max (minMaxOutliersSign is +1) median = getMedian(cache, x, cachePointers, medianBuf1, medianBuf2, kNPoints, median); if (v*minMaxOutliersSign+threshold < median*minMaxOutliersSign)
/** * Performs in-place erosion with a disk structuring element by calling the * ImageJ native RankFilters algorithm, using RankFilters.MIN option. * * @param image the image to process */ @Override public void inPlaceErosion(ImageProcessor image) { new RankFilters().rank(image, radius, RankFilters.MIN); } }
public void run(ImageProcessor ip) { rank(ip, radius, filterType, whichOutliers, (float)threshold); if (IJ.escapePressed()) // interrupted by user? ip.reset(); }
/** * Add mean filter to current stack * @param radius radius to use */ public void addMean(float radius) { final ImageProcessor ip = originalImage.getProcessor().duplicate(); final RankFilters filter = new RankFilters(); filter.rank(ip, radius, RankFilters.MEAN); wholeStack.addSlice(availableFeatures[MEAN]+ "_" + radius, ip); }
public ImagePlus call(){ final ImageProcessor ip = originalImage.getProcessor().duplicate(); final RankFilters filter = new RankFilters(); filter.rank(ip, radius, RankFilters.MIN); return new ImagePlus (availableFeatures[MINIMUM]+ "_" + radius, ip); } };
public ImagePlus call(){ final ImageProcessor ip = originalImage.getProcessor().duplicate(); final RankFilters filter = new RankFilters(); filter.rank(ip, radius, RankFilters.MAX); return new ImagePlus (availableFeatures[MAXIMUM]+ "_" + radius, ip); } };
public ImagePlus call(){ final ImageProcessor ip = originalImage.getProcessor().duplicate(); final RankFilters filter = new RankFilters(); filter.rank(ip, radius, RankFilters.MEAN); return new ImagePlus (availableFeatures[MEAN]+ "_" + radius, ip); } };
public ImagePlus call(){ final ImageProcessor ip = originalImage.getProcessor().duplicate(); final RankFilters filter = new RankFilters(); filter.rank(ip, radius, RankFilters.MEDIAN); return new ImagePlus (availableFeatures[MEDIAN]+ "_" + radius, ip); } };