Java Code Examples for ij.process.ImageProcessor#getRoi()

The following examples show how to use ij.process.ImageProcessor#getRoi() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RankFiltersOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
/** Filters an image by any method except 'despecle' (for 'despeckle', use 'median' and radius=1)
 * @param ip The image subject to filtering
 * @param radius The kernel radius
 * @param filterType as defined above; DESPECKLE is not a valid type here; use median and
 *		  a radius of 1.0 instead
 * @param whichOutliers BRIGHT_OUTLIERS or DARK_OUTLIERS for 'outliers' filter
 * @param threshold Threshold for 'outliers' filter
 */
public void rank(ImageProcessor ip, double radius, int filterType, int whichOutliers, float threshold) {
	Rectangle roi = ip.getRoi();
	ImageProcessor mask = ip.getMask();
	Rectangle roi1 = null;
	int[] lineRadii = makeLineRadii(radius);

	float minMaxOutliersSign = filterType==MIN ? -1f : 1f;
	if (filterType == OUTLIERS)		//sign is -1 for high outliers: compare number with minimum
		minMaxOutliersSign = (ip.isInvertedLut()==(whichOutliers==DARK_OUTLIERS)) ? -1f : 1f;

	boolean isImagePart = (roi.width<ip.getWidth()) || (roi.height<ip.getHeight());
	boolean[] aborted = new boolean[1];						// returns whether interrupted during preview or ESC pressed
	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);
				roi1 = roiClone.intersection(new Rectangle(ip.getWidth(), ip.getHeight()));
				ip.setRoi(roi1);
			}
		}
		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);
		}
	}
}