Java Code Examples for ij.gui.GenericDialog#getNextChoice()

The following examples show how to use ij.gui.GenericDialog#getNextChoice() . 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: Adaptive_ThresholdJ_.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
private boolean showDialog() {

        GenericDialog gd = new GenericDialog("Adaptive Threshold");
        String[] items = {"Mean", "Gaussian"};
        String[] itemsThreshold = {"Binary", "Binary Inv"};
        gd.addChoice("Method", items, items[0]);
        gd.addChoice("Threshold Type", itemsThreshold, itemsThreshold[0]);
        gd.addNumericField("Max Value", maxValue, 0);
        gd.addNumericField("Block size", blockSize, 0);
        //gd.addNumericField("Gaussian Kernel width:", gaussianKernelWidth, 0);

        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }

        method = gd.getNextChoice();
        thresholdmethod = gd.getNextChoice();
        maxValue = (int) gd.getNextNumber();
        blockSize = (int) gd.getNextNumber();
        return true;
    }
 
Example 2
Source File: BinaryOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public boolean dialogItemChanged (GenericDialog gd, AWTEvent e) {
	iterations = (int)gd.getNextNumber();
	count = (int)gd.getNextNumber();
	boolean bb = Prefs.blackBackground;
	Prefs.blackBackground = gd.getNextBoolean();
	if ( Prefs.blackBackground!=bb)
		ThresholdAdjuster.update();
	Prefs.padEdges = gd.getNextBoolean();
	EDM.setOutputType(gd.getNextChoiceIndex());
	boolean isInvalid = gd.invalidNumber();
	if (iterations<1) {iterations = 1; isInvalid = true;}
	if (iterations>MAX_ITERATIONS) {iterations = MAX_ITERATIONS; isInvalid = true;}
	if (count < 1)    {count = 1; isInvalid = true;}
	if (count > 8)    {count = 8; isInvalid = true;}
	if (isInvalid) return false;
	if (imp != null) {
		operation = gd.getNextChoice();
		arg = operation.toLowerCase();
	}
	return true;
}
 
Example 3
Source File: LayerSet.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Returns false if the dialog was canceled or there wasn't any tag to remove. */
protected boolean askToRemoveTag(final int keyCode) {
	TreeSet<Tag> ts = getTags(keyCode);
	if (null == ts || ts.isEmpty()) return false;
	String[] tags = new String[ts.size()];
	int next = 0;
	for (Tag t : ts) tags[next++] = t.toString();
	GenericDialog gd = new GenericDialog("Remove tag");
	gd.addMessage("Remove a tag for key: " + ((char)keyCode));
	gd.addChoice("Remove:", tags, tags[0]);
	gd.showDialog();
	if (gd.wasCanceled()) return false;
	String tag = gd.getNextChoice();
	removeTag(tag, keyCode);
	return true;
}
 
Example 4
Source File: DistanceTransformWatershed.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Called when a dialog widget has been modified: recomputes option values
 * from dialog content.
 */
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt)
{
	synchronized (this){
		// set up current parameters
		weightLabel = gd.getNextChoice();
		floatProcessing = gd.getNextChoiceIndex() == 0;
		normalize = gd.getNextBoolean();
		dynamic = (int) gd.getNextNumber();
		connLabel = gd.getNextChoice();
		connectivity = Conn2D.fromLabel( connLabel ).getValue();

		// identify which weights should be used
		weights = ChamferWeights.fromLabel( weightLabel );
	}
	return true;
}
 
Example 5
Source File: KeyPointDetectorJ_.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {

    GenericDialog gd = new GenericDialog("Select Keypoint detector");
    gd.addChoice("Method", methods, method);
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    method = gd.getNextChoice();
    PointRoi res = keyPointDetection(method);
    imp.setRoi(res);

}
 
Example 6
Source File: LabelToRgbPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void run(String arg)
{
	ImagePlus imagePlus = IJ.getImage();

	int maxLabel = computeMaxLabel(imagePlus);
	
	// Create a new generic dialog with appropriate options
   	GenericDialog gd = new GenericDialog("Labels To RGB");
   	gd.addChoice("Colormap", CommonLabelMaps.getAllLabels(), 
   			CommonLabelMaps.GOLDEN_ANGLE.getLabel());
   	gd.addChoice("Background", CommonColors.getAllLabels(), CommonColors.WHITE.getLabel());
   	gd.addCheckbox("Shuffle", true);
   	gd.showDialog();
	
   	// test cancel  
   	if (gd.wasCanceled()) 
   		return;

   	// Create a new LUT from info in dialog
	String lutName = gd.getNextChoice();
	String bgColorName = gd.getNextChoice();
	Color bgColor = CommonColors.fromLabel(bgColorName).getColor();
	boolean shuffleLut = gd.getNextBoolean();

	// Create a new LUT from info in dialog
	byte[][] lut = CommonLabelMaps.fromLabel(lutName).computeLut(maxLabel, shuffleLut);
   	
	// Create a new RGB image from index image and LUT options
	ImagePlus resPlus = LabelImages.labelToRgb(imagePlus, lut, bgColor);
   	
	// dispay result image
	resPlus.copyScale(imagePlus);
	resPlus.show();
   	if (imagePlus.getStackSize() > 1) 
   	{
   		resPlus.setSlice(imagePlus.getCurrentSlice());
   	}
}
 
Example 7
Source File: ChamferDistanceMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Called when a dialog widget has been modified: recomputes option values
 * from dialog content. 
 */
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt)
{
	// set up current parameters
	String weightLabel = gd.getNextChoice();
	floatProcessing = gd.getNextChoiceIndex() == 0;
	normalize = gd.getNextBoolean();

	// identify which weights should be used
	weights = ChamferWeights.fromLabel(weightLabel);
    return true;
}
 
Example 8
Source File: ChamferDistanceMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) 
  {
  	// Store user data
  	this.imagePlus = imp;
  	this.baseImage = imp.getProcessor().duplicate();
  	this.pfr = pfr;

  	// Create a new generic dialog with appropriate options
  	GenericDialog gd = new GenericDialog("Chamfer Distance Map");
  	gd.addChoice("Distances", ChamferWeights.getAllLabels(), 
  			ChamferWeights.BORGEFORS.toString());			
  	String[] outputTypes = new String[]{"32 bits", "16 bits"};
  	gd.addChoice("Output Type", outputTypes, outputTypes[0]);
  	gd.addCheckbox("Normalize weights", true);	
  	gd.addPreviewCheckbox(pfr);
  	gd.addDialogListener(this);
      previewing = true;
gd.addHelp("https://imagej.net/MorphoLibJ");
      gd.showDialog();
      previewing = false;
      
  	// test cancel  
  	if (gd.wasCanceled())
  		return DONE;

  	// set up current parameters
  	String weightLabel = gd.getNextChoice();
  	floatProcessing = gd.getNextChoiceIndex() == 0;
  	normalize = gd.getNextBoolean();

  	// identify which weights should be used
  	weights = ChamferWeights.fromLabel(weightLabel);

  	return flags;
  }
 
Example 9
Source File: SetLabelMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void parseDialogParameters(GenericDialog gd)
{
	lutName = gd.getNextChoice();
	String bgColorName = gd.getNextChoice();
	bgColor = CommonColors.fromLabel(bgColorName).getColor();
	shuffleLut = gd.getNextBoolean();

	// I could not use more than 256 colors for the LUT with ShortProcessor,
	// problem at
	// ij.process.ShortProcessor.createBufferedImage(ShortProcessor.java:135)
	colorMap = CommonLabelMaps.fromLabel(lutName).computeLut(255, shuffleLut);
}
 
Example 10
Source File: SelectIlluminationPopup.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static ViewSelection< ViewId > getViewSelectionResult( final GenericDialog gd, final AbstractSequenceDescription< ?, ?, ? > sd )
{
	String choice = gd.getNextChoice();
	if (choice.equals( "Pick brightest" ))
		return new BrightestViewSelection( sd );
	else if (choice.equals("Pick highest mean gradient magnitude"))
		return new MeanGradientMagnitudeViewSelection(sd);
	else if (choice.equals("Relative Fourier Ring Correlation"))
	{
		final GenericDialog gd1 = new GenericDialog( "Relative FRC Parameters" );

		gd1.addCheckbox( "Relative_FRC", QualityGUI.defaultUseRelativeFRC );
		gd1.addCheckbox( "Smooth_Local_FRC", QualityGUI.defaultSmoothLocalFRC );
		gd1.addNumericField( "FRC_FFT_Size", QualityGUI.defaultFFTSize, 0 );
		gd1.addNumericField( "FRC_Stepsize (z)", QualityGUI.defaultFRCStepSize, 0 );

		gd1.showDialog();

		if ( gd1.wasCanceled() )
			return null;

		final boolean useRelativeFRC = QualityGUI.defaultUseRelativeFRC = gd1.getNextBoolean();
		final boolean useSmoothLocalFRC = QualityGUI.defaultSmoothLocalFRC = gd1.getNextBoolean();
		final int fftSize = QualityGUI.defaultFFTSize = Math.max( 16, (int)Math.round( gd1.getNextNumber() ) );
		final int frcStepSize = QualityGUI.defaultFRCStepSize = Math.max( 1, (int)Math.round( gd1.getNextNumber() ) );

		return new RelativeFRCSelection( sd, frcStepSize, fftSize, useRelativeFRC, useSmoothLocalFRC );
	}
	else
		return null;
	
}
 
Example 11
Source File: GeodesicDistanceMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run(String arg0)
{
	// Open a dialog to choose:
	// - marker image
	// - mask image
	// - set of weights
	int[] indices = WindowManager.getIDList();
	if (indices == null)
	{
		IJ.error("No image", "Need at least one image to work");
		return;
	}

	// create the list of image names
	String[] imageNames = new String[indices.length];
	for (int i = 0; i < indices.length; i++)
	{
		imageNames[i] = WindowManager.getImage(indices[i]).getTitle();
	}

	// create the dialog
	GenericDialog gd = new GenericDialog("Geodesic Distance Map");

	gd.addChoice("Marker Image", imageNames, IJ.getImage().getTitle());
	gd.addChoice("Mask Image", imageNames, IJ.getImage().getTitle());
	// Set Chessknight weights as default
	gd.addChoice("Distances", ChamferWeights.getAllLabels(),
			ChamferWeights.CHESSKNIGHT.toString());
	String[] outputTypes = new String[] { "32 bits", "16 bits" };
	gd.addChoice("Output Type", outputTypes, outputTypes[0]);
	gd.addCheckbox("Normalize weights", true);

	gd.showDialog();

	if (gd.wasCanceled())
		return;

	// set up current parameters
	int markerImageIndex = gd.getNextChoiceIndex();
	ImagePlus markerImage = WindowManager.getImage(markerImageIndex + 1);
	int maskImageIndex = gd.getNextChoiceIndex();
	ImagePlus maskImage = WindowManager.getImage(maskImageIndex + 1);
	String weightLabel = gd.getNextChoice();
	
	// identify which weights should be used
	ChamferWeights weights = ChamferWeights.fromLabel(weightLabel);
	boolean resultAsFloat = gd.getNextChoiceIndex() == 0;
	boolean normalizeWeights = gd.getNextBoolean();

	// check image types
	if (markerImage.getType() != ImagePlus.GRAY8)
	{
		IJ.showMessage("Marker image should be binary");
		return;
	}
	if (maskImage.getType() != ImagePlus.GRAY8)
	{
		IJ.showMessage("Mask image should be binary");
		return;
	}

	// Execute core of the plugin
	String newName = createResultImageName(maskImage);
	ImagePlus res;
	if (resultAsFloat)
	{
		res = process(markerImage, maskImage, newName,
				weights.getFloatWeights(), normalizeWeights);
	} else
	{
		res = process(markerImage, maskImage, newName,
				weights.getShortWeights(), normalizeWeights);
	}

	res.show();
}
 
Example 12
Source File: DistanceTransformWatershed.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int showDialog(
		ImagePlus imp,
		String command,
		PlugInFilterRunner pfr )
{
	if( !BinaryImages.isBinaryImage( imp ) )
	{
		IJ.error( "Distance Transform Watershed", "Input image is not"
				+ " binary (8-bit with only 0 or 255 values)" );
		return DONE;
	}
	// Store user data
	this.imagePlus = imp;
	this.baseImage = imp.getProcessor().duplicate();
	this.pfr = pfr;

	// Create a new generic dialog with appropriate options
	GenericDialog gd = new GenericDialog( "Distance Transform Watershed" );
	gd.setInsets( 0, 0, 0 );
	gd.addMessage( "Distance map options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addChoice( "Distances", ChamferWeights.getAllLabels(), weightLabel );
	String[] outputTypes = new String[]{"32 bits", "16 bits"};
	gd.addChoice( "Output Type", outputTypes, outputTypes[ floatProcessing ? 0:1 ]);
	gd.setInsets( 0, 0, 0 );
	gd.addCheckbox( "Normalize weights", normalize );
	gd.setInsets( 20, 0, 0 );
	gd.addMessage( "Watershed options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addNumericField( "Dynamic", dynamic, 2 );
	gd.addChoice( "Connectivity", Conn2D.getAllLabels(), connLabel );
	gd.setInsets( 20, 0, 0 );
	gd.addPreviewCheckbox( pfr );
	gd.addDialogListener(this);
	previewing = true;
	gd.addHelp( "http://imagej.net/MorphoLibJ#Utilities_for_binary_images" );
	gd.showDialog();
	previewing = false;

	// test cancel
	if (gd.wasCanceled())
		return DONE;

	// set up current parameters
	weightLabel = gd.getNextChoice();
	floatProcessing = gd.getNextChoiceIndex() == 0;
	normalize = gd.getNextBoolean();
	dynamic = (int) gd.getNextNumber();
	connLabel = gd.getNextChoice();
	connectivity = Conn2D.fromLabel( connLabel ).getValue();

	// identify which weights should be used
	weights = ChamferWeights.fromLabel( weightLabel );

	return flags;
}
 
Example 13
Source File: GeodesicDistanceMap3DPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
	public void run(String arg0)
	{
		// Open a dialog to choose:
		// - marker image
		// - mask image
		// - set of weights
		int[] indices = WindowManager.getIDList();
		if (indices == null)
		{
			IJ.error("No image", "Need at least one image to work");
			return;
		}

		// create the list of image names
		String[] imageNames = new String[indices.length];
		for (int i = 0; i < indices.length; i++)
		{
			imageNames[i] = WindowManager.getImage(indices[i]).getTitle();
		}

		// create the dialog
		GenericDialog gd = new GenericDialog("Geodesic Distance Map 3D");

		gd.addChoice("Marker Image", imageNames, IJ.getImage().getTitle());
		gd.addChoice("Mask Image", imageNames, IJ.getImage().getTitle());
		// Set default weights
		gd.addChoice("Distances", ChamferWeights3D.getAllLabels(),
				ChamferWeights3D.WEIGHTS_3_4_5_7.toString());
//		String[] outputTypes = new String[] { "32 bits", "16 bits" };
//		gd.addChoice("Output Type", outputTypes, outputTypes[0]);
		gd.addCheckbox("Normalize weights", true);

		gd.showDialog();

		if (gd.wasCanceled())
			return;

		// set up current parameters
		int markerImageIndex = gd.getNextChoiceIndex();
		ImagePlus markerImage = WindowManager.getImage(markerImageIndex + 1);
		int maskImageIndex = gd.getNextChoiceIndex();
		ImagePlus maskImage = WindowManager.getImage(maskImageIndex + 1);
		String weightLabel = gd.getNextChoice();
		
		// identify which weights should be used
		ChamferWeights3D weights = ChamferWeights3D.fromLabel(weightLabel);
//		boolean resultAsFloat = gd.getNextChoiceIndex() == 0;
		boolean normalizeWeights = gd.getNextBoolean();

		// check image types
		if (markerImage.getType() != ImagePlus.GRAY8)
		{
			IJ.showMessage("Marker image should be binary");
			return;
		}
		if (maskImage.getType() != ImagePlus.GRAY8)
		{
			IJ.showMessage("Mask image should be binary");
			return;
		}

		// Execute core of the plugin
		String newName = createResultImageName(maskImage);
		ImagePlus res;
//		if (resultAsFloat)
//		{
			res = process(markerImage, maskImage, newName,
					weights.getFloatWeights(), normalizeWeights);
//		} else
//		{
//			res = process(markerImage, maskImage, newName,
//					weights.getShortWeights(), normalizeWeights);
//		}

		res.show();
	}
 
Example 14
Source File: BinaryOverlayPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void run(String arg) {
	// Open a dialog to choose:
	// - a reference image (grayscale, binary, or color)
	// - a binary image (coded as uint8)
	// - a target color
	int[] indices = WindowManager.getIDList();
	if (indices==null) {
		IJ.error("No image", "Need at least one image to work");
		return;
	}
	
	// create the list of image names
	String[] imageNames = new String[indices.length];
	for (int i = 0; i < indices.length; i++) {
		imageNames[i] = WindowManager.getImage(indices[i]).getTitle();
	}
	
	// name of selected image
	String selectedImageName = IJ.getImage().getTitle();
	
	// create the dialog
	GenericDialog gd = new GenericDialog("Binary Overlay");
	gd.addChoice("Reference Image:", imageNames, selectedImageName);
	gd.addChoice("Binary Mask:", imageNames, selectedImageName);
	gd.addChoice("Overlay Color:", CommonColors.getAllLabels(), CommonColors.RED.getLabel());
	
	gd.showDialog();
	
	if (gd.wasCanceled())
		return;
	
	// Extract reference image
	int refImageIndex = gd.getNextChoiceIndex();
	ImagePlus refImage = WindowManager.getImage(refImageIndex+1);
	
	// Extract mask image
	int maskIndex = gd.getNextChoiceIndex();
	ImagePlus maskImage = WindowManager.getImage(maskIndex+1);

	// Extract overlay color
	String colorName = gd.getNextChoice();
	Color color = CommonColors.fromLabel(colorName).getColor();
	
	// Call binary overlay conversion
	ImagePlus resultPlus = ColorImages.binaryOverlay(refImage, maskImage, color);
	resultPlus.show();
	
	// set up display 
	if (refImage.getStackSize() > 1) {
		resultPlus.setSlice(refImage.getCurrentSlice());
	}
}
 
Example 15
Source File: GeodesicDistanceMap3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
	public void run(String arg0)
	{
		// Open a dialog to choose:
		// - marker image
		// - mask image
		// - set of weights
		int[] indices = WindowManager.getIDList();
		if (indices == null)
		{
			IJ.error("No image", "Need at least one image to work");
			return;
		}

		// create the list of image names
		String[] imageNames = new String[indices.length];
		for (int i = 0; i < indices.length; i++)
		{
			imageNames[i] = WindowManager.getImage(indices[i]).getTitle();
		}

		// create the dialog
		GenericDialog gd = new GenericDialog("Geodesic Distance Map 3D");

		gd.addChoice("Marker Image", imageNames, IJ.getImage().getTitle());
		gd.addChoice("Mask Image", imageNames, IJ.getImage().getTitle());
		// Set Chessknight weights as default
		gd.addChoice("Distances", ChamferWeights3D.getAllLabels(),
				ChamferWeights3D.BORGEFORS.toString());
//		String[] outputTypes = new String[] { "32 bits", "16 bits" };
//		gd.addChoice("Output Type", outputTypes, outputTypes[0]);
		gd.addCheckbox("Normalize weights", true);

		gd.showDialog();

		if (gd.wasCanceled())
			return;

		// set up current parameters
		int markerImageIndex = gd.getNextChoiceIndex();
		ImagePlus markerImage = WindowManager.getImage(markerImageIndex + 1);
		int maskImageIndex = gd.getNextChoiceIndex();
		ImagePlus maskImage = WindowManager.getImage(maskImageIndex + 1);
		String weightLabel = gd.getNextChoice();
		
		// identify which weights should be used
		ChamferWeights3D weights = ChamferWeights3D.fromLabel(weightLabel);
//		boolean resultAsFloat = gd.getNextChoiceIndex() == 0;
		boolean normalizeWeights = gd.getNextBoolean();

		// check image types
		if (markerImage.getType() != ImagePlus.GRAY8)
		{
			IJ.showMessage("Marker image should be binary");
			return;
		}
		if (maskImage.getType() != ImagePlus.GRAY8)
		{
			IJ.showMessage("Mask image should be binary");
			return;
		}

		// Execute core of the plugin
		String newName = maskImage.getShortTitle() + "-geodDist";
		ImagePlus res;
//		if (resultAsFloat)
//		{
			res = process(markerImage, maskImage, newName,
					weights.getFloatWeights(), normalizeWeights);
//		} else
//		{
//			res = process(markerImage, maskImage, newName,
//					weights.getShortWeights(), normalizeWeights);
//		}

		res.show();
	}
 
Example 16
Source File: DistanceTransformWatershed3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Plugin run method
 */
public void run(String arg) {
	
	ImagePlus image = WindowManager.getCurrentImage();
	if ( image == null ) 
	{
		IJ.error("Distance Transform Watershed 3D",
				"Need at least one image to work");
		return;
	}

	if( !BinaryImages.isBinaryImage( image ) )
	{
		IJ.error( "Distance Transform Watershed 3D", "Input image is not"
				+ " binary (8-bit with only 0 or 255 values)" );
	}

	// Create a new generic dialog with appropriate options
	GenericDialog gd = new GenericDialog( "Distance Transform Watershed 3D" );
	gd.setInsets( 0, 0, 0 );
	gd.addMessage( "Distance map options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addChoice( "Distances", ChamferWeights3D.getAllLabels(), weightLabel );
	String[] outputTypes = new String[]{"32 bits", "16 bits"};
	gd.addChoice( "Output Type", outputTypes, outputTypes[ floatProcessing ? 0:1 ]);
	gd.setInsets( 0, 0, 0 );
	gd.addCheckbox( "Normalize weights", normalize );
	gd.setInsets( 20, 0, 0 );
	gd.addMessage( "Watershed options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addNumericField( "Dynamic", dynamic, 2 );
	gd.addChoice( "Connectivity", Conn3D.getAllLabels(),
			connectivity.label );
	gd.addHelp( "http://imagej.net/MorphoLibJ#Utilities_for_binary_images" );
	gd.showDialog();

	// test cancel
	if ( gd.wasCanceled() )
		return;

	// set up current parameters
	weightLabel = gd.getNextChoice();
	floatProcessing = gd.getNextChoiceIndex() == 0;
	normalize = gd.getNextBoolean();
	dynamic = (int) gd.getNextNumber();
	connectivity = Conn3D.fromLabel( gd.getNextChoice() );

	// identify which weights should be used
	weights = ChamferWeights3D.fromLabel( weightLabel );

	long t0 = System.currentTimeMillis();

	final ImagePlus result;
	if (floatProcessing)
		result = processFloat( image, weights.getFloatWeights(), normalize );
	else
		result = processShort( image, weights.getShortWeights(), normalize );

	Images3D.optimizeDisplayRange( result );

	// Display the result image
	result.show();
	result.setSlice( image.getCurrentSlice() );

	// Display elapsed time
	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime( "Distance Transform Watershed 3D",
			t1 - t0, image );
}
 
Example 17
Source File: ThresholderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
void convertStack(ImagePlus imp) {
	if (imp.getStack().isVirtual()) {
		IJ.error("Thresholder", "This command does not work with virtual stacks.\nUse Image>Duplicate to convert to a normal stack.");
		return;
	}
	boolean thresholdSet = imp.getProcessor().getMinThreshold()!=ImageProcessor.NO_THRESHOLD;
	this.imp = imp;
	if (!IJ.isMacro()) {
		method = staticMethod;
		background = staticBackground;
		useLocal = staticUseLocal;
		if (!thresholdSet)
			updateThreshold(imp);
	}
	if (thresholdSet)
		useLocal = false;
	GenericDialog gd = new GenericDialog("Convert Stack to Binary");
	gd.addChoice("Method:", methods, method);
	gd.addChoice("Background:", backgrounds, background);
	gd.addCheckbox("Calculate threshold for each image", useLocal);
	gd.addCheckbox("Black background (mask)", Prefs.blackBackground);
	choices = gd.getChoices();
	((Choice)choices.elementAt(0)).addItemListener(this);
	((Choice)choices.elementAt(1)).addItemListener(this);
	gd.showDialog();
	if (gd.wasCanceled())
		return;
	this.imp = null;
	method = gd.getNextChoice();
	background = gd.getNextChoice();
	useLocal = gd.getNextBoolean();
	boolean saveBlackBackground = Prefs.blackBackground;
	Prefs.blackBackground = gd.getNextBoolean();
	if (!IJ.isMacro()) {
		staticMethod = method;
		staticBackground = background;
		staticUseLocal = useLocal;
	}
	Undo.reset();
	if (useLocal)
		convertStackToBinary(imp);
	else
		applyThreshold(imp);
	Prefs.blackBackground = saveBlackBackground;
}
 
Example 18
Source File: DLabel.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void adjustProperties() {
	final GenericDialog gd = makeAdjustPropertiesDialog();

	final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	final String[] fonts = ge.getAvailableFontFamilyNames();
	final String[] sizes = {"8","9","10","12","14","18","24","28","36","48","60","72"};
	final String[] styles = {"Plain", "Bold", "Italic", "Bold+Italic"};
	int i = 0;
	final String family = this.font.getFamily();
	for (i = fonts.length -1; i>-1; i--) {
		if (family.equals(fonts[i])) break;
	}
	if (-1 == i) i = 0;
	gd.addChoice("Font Family: ", fonts, fonts[i]);
	final int size = this.font.getSize();
	for (i = sizes.length -1; i>-1; i--) {
		if (Integer.parseInt(sizes[i]) == size) break;
	}
	if (-1 == i) i = 0;
	gd.addChoice("Font Size: ", sizes, sizes[i]);
	gd.addNumericField("or enter size: ", size, 0);
	i=0;
	switch (this.font.getStyle()) {
		case Font.PLAIN: i=0; break;
		case Font.BOLD: i=1; break;
		case Font.ITALIC: i=2; break;
		case Font.BOLD+Font.ITALIC: i=3; break;
	}
	gd.addChoice("Font style: ", styles, styles[i]);

	gd.showDialog();
	if (gd.wasCanceled()) return;
	// superclass processing
	processAdjustPropertiesDialog(gd);
	// local proccesing
	final String new_font = gd.getNextChoice();
	int new_size = Integer.parseInt(gd.getNextChoice());
	final int new_size_2 = (int)gd.getNextNumber();
	if (new_size_2 != size) {
		new_size = new_size_2;
	}
	int new_style = gd.getNextChoiceIndex();
	switch (new_style) {
		case 0: new_style = Font.PLAIN; break;
		case 1: new_style = Font.BOLD; break;
		case 2: new_style = Font.ITALIC; break;
		case 3: new_style = Font.BOLD+Font.ITALIC; break;
	}
	this.font = new Font(new_font, new_style, new_size);
	updateInDatabase("font");
	// update dimensions
	setText(this.title, true);
}