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

The following examples show how to use ij.gui.GenericDialog#addDialogListener() . 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: SetLabelMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
public GenericDialog showDialog()
{

	// Create a new generic dialog with appropriate options
	GenericDialog gd = new GenericDialog("Set Label Map");
	gd.addChoice("Colormap", CommonLabelMaps.getAllLabels(), CommonLabelMaps.GOLDEN_ANGLE.getLabel());
	gd.addChoice("Background", CommonColors.getAllLabels(), CommonColors.WHITE.toString());
	gd.addCheckbox("Shuffle", true);

	gd.addPreviewCheckbox(null);
	gd.addDialogListener(this);
	parseDialogParameters(gd);
	gd.showDialog();

	return gd;
}
 
Example 2
Source File: GrayscaleAreaOpeningPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
{
	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Gray Scale Area Opening");

	gd.addNumericField("Pixel Number", 100, 0, 10, "pixels");
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled())
       	return DONE;
		
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 3
Source File: GrayscaleBoxDiameterOpeningPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
{
	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Gray Scale Box Diagonal Opening");

	gd.addNumericField("Diagonal Min.", 100, 0, 10, "pixels");
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled())
       	return DONE;
		
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 4
Source File: AreaOpeningPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
{
	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Area Opening");

	gd.addNumericField("Pixel Number", 100, 0, 10, "pixels");
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled())
       	return DONE;
		
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 5
Source File: Define_Multi_View_Dataset.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected void addListeners( final GenericDialog gd, final Choice choice, final MyMultiLineLabel label, final ArrayList< MultiViewDatasetDefinition > datasetDefinitions )
{
	gd.addDialogListener( new DialogListener()
	{
		@Override
		public boolean dialogItemChanged( final GenericDialog dialog, final AWTEvent e )
		{
			if ( e instanceof ItemEvent && e.getID() == ItemEvent.ITEM_STATE_CHANGED && e.getSource() == choice )
			{
				label.setText( formatEntry( datasetDefinitions.get( choice.getSelectedIndex() ).getExtendedDescription(), numCharacters, numLinesDocumentation ) );
			}
			return true;
		}
	} );
	
}
 
Example 6
Source File: ShenCastan.java    From Scripts with GNU General Public License v3.0 6 votes vote down vote up
/** Displays the dialog prompt. */
@Override
public int showDialog(final ImagePlus imp, final String command, final PlugInFilterRunner pfr) {
	this.pfr = pfr;

	final String msg = "<html><div WIDTH=350>"
			+ "<a href='https://github.com/tferr/Scripts/blob/master/Segmentation/README.md#shen-castan-edge-detector'>"
			+ "Shen-Castan</a> filtering is an edge detection technique. It is an alternative "
			+ "to other popular approaches such as "
			+ "<a href='http://en.wikipedia.org/wiki/Canny_edge_detector'>Canny</a>-"
			+ "<a href='http://en.wikipedia.org/wiki/Deriche_edge_detector'>Deriche</a> filtering.</p>"
			+ "<p>The Shen-Castan coefficient corresponds to a smooting factor <i>alpha</i>. "
			+ "<i>Alpha</i> can vary between 0 (high smoothing, suitable for noisy images) "
			+ "and 1 (no smoothing, suitable for non-noisy images).</p></div></html>";

	final GenericDialog gd = new GenericDialog(command);
	gd.addSlider("Coefficient:", 0.0001d, 1.0001d, f);
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
	gd.addHelp(msg);
	gd.showDialog();
	if (gd.wasCanceled() || !dialogItemChanged(gd, null)) // read parameters
		return DONE;
	return IJ.setupDialog(imp, flags);
}
 
Example 7
Source File: BinaryOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public int showDialog (ImagePlus imp, String command, PlugInFilterRunner pfr) {
	if (doOptions) {
		this.imp = imp;
		this.pfr = pfr;
		GenericDialog gd = new GenericDialog("Binary Options");
		gd.addNumericField("Iterations (1-"+MAX_ITERATIONS+"):", iterations, 0, 3, "");
		gd.addNumericField("Count (1-8):", count, 0, 3, "");
		gd.addCheckbox("Black background", Prefs.blackBackground);
		gd.addCheckbox("Pad edges when eroding", Prefs.padEdges);
		gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]);
		if (imp != null) {
			gd.addChoice("Do:", operations, operation);
			gd.addPreviewCheckbox(pfr);
			gd.addDialogListener(this);
			previewing = true;
		}
		gd.addHelp(IJ.URL+"/docs/menus/process.html#options");
		gd.showDialog();
		previewing = false;
		if (gd.wasCanceled()) return DONE;
		if (imp==null) {                 //options dialog only, no do/preview
			dialogItemChanged(gd, null); //read dialog result
			return DONE;
		}
		return operation.equals(NO_OPERATION) ? DONE : IJ.setupDialog(imp, flags);
	} else {   //no dialog, 'arg' is operation type
		if (!imp.getProcessor().isBinary()) {
			IJ.error("8-bit binary (black and white only) image required.");
			return DONE;
		}
		return IJ.setupDialog(imp, flags);
	}
}
 
Example 8
Source File: SkeletonPlugin.java    From SNT with GNU General Public License v3.0 5 votes vote down vote up
private boolean showDialog() {

		gd = new GenericDialog("Render Paths as Topographic Skeletons");
		final String[] pwScopes = { "Render all paths", "Render only selected paths" };
		gd.addRadioButtonGroup("Path selection:", pwScopes, 2, 1, pwScopes[useOnlySelectedPaths ? 1 : 0]);
		final String[] roiScopes = { "None", "Render only segments contained by ROI" };
		gd.addRadioButtonGroup("ROI filtering:", roiScopes, 2, 1, roiScopes[restrictByRoi ? 1 : 0]);

		// Assemble SWC choices
		final ArrayList<String> swcTypeNames = Path.getSWCtypeNames();
		final int nTypes = swcTypeNames.size();
		final String[] typeNames = swcTypeNames.toArray(new String[nTypes]);
		final boolean[] typeChoices = new boolean[nTypes];
		for (int i = 0; i < nTypes; i++)
			typeChoices[i] = typeNames[i].contains("dendrite");
		final String[] swcScopes = { "None", "Include only the following SWC types:" };
		gd.addRadioButtonGroup("SWC filtering:", swcScopes, 2, 1, swcScopes[restrictBySWCType ? 1 : 0]);
		gd.setInsets(0, 40, 0);
		gd.addCheckboxGroup(nTypes / 2, 2, typeNames, typeChoices);

		final String[] analysisScopes = { "None", "Obtain summary", "Run \"Analyze Skeleton\" plugin" };
		gd.addRadioButtonGroup("Analysis of rendered paths:", analysisScopes, 3, 1, analysisScopes[0]);
		gd.addDialogListener(this);
		dialogItemChanged(gd, null);
		gd.showDialog();
		if (gd.wasCanceled())
			return false;
		else if (gd.wasOKed()) {
			return dialogItemChanged(gd, null);
		}
		return false;

	}
 
Example 9
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 10
Source File: GrayscaleAttributeFilteringPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
{
	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Gray Scale Attribute Filtering");

	gd.addChoice("Operation", Operation.getAllLabels(), Operation.OPENING.label);
	gd.addChoice("Attribute", Attribute.getAllLabels(), Attribute.AREA.label);
	gd.addNumericField("Minimum Value", 100, 0, 10, "pixels");
	gd.addChoice("Connectivity", connectivityLabels, connectivityLabels[0]);
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
	gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled())
       {
       	resetPreview();
       	return DONE;
       }	
       parseDialogParameters(gd);

       // clean up an return
	gd.dispose();
	return flags;
}
 
Example 11
Source File: MorphologicalFilterPlugin.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)
{
	// Normal setup
   	this.imagePlus = imp;
   	this.baseImage = imp.getProcessor().duplicate();

	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Morphological Filters");
	
	gd.addChoice("Operation", Operation.getAllLabels(), 
			this.op.toString());
	gd.addChoice("Element", Strel.Shape.getAllLabels(), 
			this.shape.toString());
	gd.addNumericField("Radius (in pixels)", this.radius, 0);
	gd.addCheckbox("Show Element", false);
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
	gd.addHelp("http://imagej.net/MorphoLibJ#Morphological_filters");
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled()) 
       {
       	resetPreview();
       	return DONE;
       }	
       
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 12
Source File: RegionalMinAndMaxPlugin.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) {
	// Normal setup
   	this.imagePlus = imp;
   	this.baseImage = imp.getProcessor().duplicate();

	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Regional Min & Max");
	
	gd.addChoice("Operation", Operation.getAllLabels(), 
			Operation.REGIONAL_MINIMA.label);
	gd.addChoice("Connectivity", connectivityLabels, connectivityLabels[0]);
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
       gd.addHelp("https://imagej.net/MorphoLibJ");
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled())
       	return DONE;
		
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 13
Source File: ExtendedMinAndMaxPlugin.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) {
	// Normal setup
   	this.imagePlus = imp;
   	this.baseImage = imp.getProcessor().duplicate();

	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Extended Min & Max");
	
	gd.addChoice("Operation", Operation.getAllLabels(), Operation.EXTENDED_MINIMA.label);
	boolean isGray8 = (this.baseImage instanceof ByteProcessor);
	double minValue = isGray8 ? 1 : this.baseImage.getMin();
	double maxValue = isGray8 ? 255 : this.baseImage.getMax();
	gd.addSlider("Dynamic", minValue, maxValue, 10);
	gd.addChoice("Connectivity", connectivityLabels, connectivityLabels[0]);
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
       gd.addHelp("https://imagej.net/MorphoLibJ");
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled()) {
		return DONE;
       }
       
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 14
Source File: DirectionalFilteringPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
	{
		// Normal setup
    	this.imagePlus = imp;
    	this.baseImage = imp.getProcessor().duplicate();

		// Create the configuration dialog
		GenericDialog gd = new GenericDialog("Directional Filtering");
		
		gd.addChoice("Type", Type.getAllLabels(), this.type.toString());
		gd.addChoice("Operation", Operation.getAllLabels(), this.op.toString());
		gd.addNumericField("Line Length", this.lineLength, 0, 8, "pixels");
		gd.addNumericField("Direction Number", this.nDirections, 0);
		
		gd.addPreviewCheckbox(pfr);
		gd.addDialogListener(this);
        previewing = true;
//		gd.addHelp("http://imagejdocu.tudor.lu/doku.php?id=plugin:morphology:fast_morphological_filters:start");
        gd.showDialog();
        previewing = false;
        
        if (gd.wasCanceled()) 
        {
			return DONE;
        }
        
    	parseDialogParameters(gd);
			
		// clean up an return 
		gd.dispose();
		return flags;
	}
 
Example 15
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
private void setPlotFont() {

		if (plot == null)
			return;

		final String[] FONTS = new String[] { Font.SANS_SERIF, Font.MONOSPACED, Font.SERIF };
		final String[] STYLES = { "Plain", "Bold", "Italic", "Bold+Italic" };
		final String[] JUSTIFICATIONS = { "Left", "Center", "Right" };
		final String[] SCOPES = { "Plot", "Both Axes Titles", "X-axis Title", "Y-axis Title" };
		final String[] CHOICE_DEFAULTS = { FONTS[0], STYLES[0], JUSTIFICATIONS[0], SCOPES[0] };
		final int[] INT_STYLES = { Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD + Font.ITALIC };
		final int[] INT_JUSTIFICATIONS = { Plot.LEFT, Plot.CENTER, Plot.RIGHT };
		final int DEF_SIZE = 12;
		final boolean DEF_ANTIALISED = true;

		final GenericDialog fgd = new GenericDialog("Font Options");
		fgd.addChoice("Type:", FONTS, CHOICE_DEFAULTS[0]);
		fgd.addChoice("Style:", STYLES, CHOICE_DEFAULTS[1]);
		fgd.addChoice("Justification:", JUSTIFICATIONS, CHOICE_DEFAULTS[2]);
		fgd.addSlider("Size:", 9, 24, DEF_SIZE);
		fgd.setInsets(0, 20, 15);
		fgd.addCheckbox("Antialiased text", DEF_ANTIALISED);
		fgd.addChoice("Apply to:", SCOPES, CHOICE_DEFAULTS[3]);
		fgd.hideCancelButton();
		fgd.addHelp("");
		fgd.setHelpLabel("Apply Defaults");
		fgd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					for (final Choice choice : nChoices)
						choice.select(CHOICE_DEFAULTS[nChoices.indexOf(choice)]);
					((TextField) gd.getNumericFields().get(0)).setText(Integer.toString(DEF_SIZE));
					((Checkbox) gd.getCheckboxes().get(0)).setState(DEF_ANTIALISED);
				}

				final String type = FONTS[fgd.getNextChoiceIndex()];
				final int style = INT_STYLES[fgd.getNextChoiceIndex()];
				final int justification = INT_JUSTIFICATIONS[fgd.getNextChoiceIndex()];
				final int size = (int) fgd.getNextNumber();
				final int scopeIdx = fgd.getNextChoiceIndex();

				plot.setJustification(justification);
				plot.setAntialiasedText(fgd.getNextBoolean());
				final Font font = new Font(type, style, size);
				switch (scopeIdx) {
				case 1: // SCOPES[1]
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				case 2: // SCOPES[2]
					plot.setXLabelFont(font);
					break;
				case 3: // SCOPES[3]
					plot.setYLabelFont(font);
					break;
				default:
					plot.setFont(font);
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				}

				plot.updateImage();
				return true;
			}
		});
		showAsSubDialog(fgd);
		if (!fgd.wasOKed())
			return;
	}
 
Example 16
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
private void setPlotOptions() {

		if (plot == null)
			return;

		final int DEF_LINE_WIDTH = 1;
		final int DEF_MAX_INTERVALS = 12;
		final int DEF_TICK_LENGTH = 7;
		final int DEF_MINOR_TICK_LENGTH = 3;
		final int[] NUM_DEFAULTS = { DEF_LINE_WIDTH, DEF_MAX_INTERVALS, DEF_TICK_LENGTH, DEF_MINOR_TICK_LENGTH };
		final String DEF_BACKGROUND_COLOR = "white";
		final String title = plot.getTitle();
		final GenericDialog ogd = new GenericDialog("Options for " + title);
		ogd.setInsets(0, 10, 10);
		ogd.addMessage("This prompt allows you access customizations that\n"
				+ "are not accessible through the plot's \"More \u00bb\" menu");
		if (!pwClosed)
			ogd.addStringField("Plot title:", title, 27);
		ogd.addSlider("Line width:", 1, 20, 1);
		ogd.addSlider("Max. n. of intervals:", 1, 40, 12);
		ogd.addSlider("Major ticks length:", 1, 14, 7);
		ogd.addSlider("Minor ticks length:", 1, 14, 3);
		ogd.addChoice("Backgrond color:", Colors.colors, DEF_BACKGROUND_COLOR);
		final Panel buttonPanel = new Panel();
		final Button fontButton = new Button("  Text & Font...  ");
		fontButton.addActionListener(ogd);
		buttonPanel.add(fontButton);
		final Button templateButton = new Button("Apply Template...");
		templateButton.addActionListener(ogd);
		buttonPanel.add(templateButton);
		ogd.addPanel(buttonPanel, GridBagConstraints.EAST, new Insets(0, 0, 0, 0));
		ogd.hideCancelButton();
		ogd.addHelp("");
		ogd.setHelpLabel("Apply Defaults");
		ogd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {

				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<TextField> nFields = gd.getNumericFields();
					for (final TextField field : nFields)
						field.setText(Integer.toString(NUM_DEFAULTS[nFields.indexOf(field)]));
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					nChoices.firstElement().select(DEF_BACKGROUND_COLOR);
				} else if (e != null && e.toString().contains("Font")) {
					setPlotFont();
					return true;
				} else if (e != null && e.toString().contains("Template")) {
					setTemplate();
					return true;
				}

				plot.setLineWidth((int) ogd.getNextNumber());
				plot.setMaxIntervals((int) ogd.getNextNumber());
				plot.setTickLength((int) ogd.getNextNumber());
				plot.setBackgroundColor(Colors.colors[ogd.getNextChoiceIndex()]);
				plot.updateImage();
				return true;

			}
		});
		showAsSubDialog(ogd);
		if (!ogd.wasOKed())
			return;
		if (!pwClosed)
			plot.getImagePlus().setTitle(WindowManager.makeUniqueName(ogd.getNextString()));

	}
 
Example 17
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 18
Source File: RankFiltersOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
	if (filterType == DESPECKLE) {
		filterType = MEDIAN;
		radius = 1.0;
	} else {
		GenericDialog gd = new GenericDialog(command+"...");
		radius = lastRadius[filterType]<=0 ? 2 :  lastRadius[filterType];
		gd.addNumericField("Radius", radius, 1, 6, "pixels");
		int digits = imp.getType() == ImagePlus.GRAY32 ? 2 : 0;
		if (filterType==OUTLIERS) {
			gd.addNumericField("Threshold", lastThreshold, digits);
			gd.addChoice("Which outliers", outlierStrings, outlierStrings[lastWhichOutliers]);
			gd.addHelp(IJ.URL+"/docs/menus/process.html#outliers");
		} else if (filterType==REMOVE_NAN)
			gd.addHelp(IJ.URL+"/docs/menus/process.html#nans");
		gd.addPreviewCheckbox(pfr);		//passing pfr makes the filter ready for preview
		gd.addDialogListener(this);		//the DialogItemChanged method will be called on user input
		gd.showDialog();				//display the dialog; preview runs in the  now
		if (gd.wasCanceled()) return DONE;
		IJ.register(this.getClass());	//protect static class variables (filter parameters) from garbage collection
		if (Macro.getOptions() == null) { //interactive only: remember parameters entered
			lastRadius[filterType] = radius;
			if (filterType == OUTLIERS) {
				lastThreshold = threshold;
				lastWhichOutliers = whichOutliers;
			}
		}
	}
	this.pfr = pfr;
	flags = IJ.setupDialog(imp, flags); //ask whether to process all slices of stack (if a stack)
	if ((flags&DOES_STACKS)!=0) {
		int size = imp.getWidth() * imp.getHeight();
		Roi roi = imp.getRoi();
		if (roi != null) {
			Rectangle roiRect = roi.getBounds();
			size = roiRect.width * roiRect.height;
		}
		double workToDo = size*(double)radius;	//estimate computing time (arb. units)
		if (filterType==MEAN || filterType==VARIANCE) workToDo *= 0.5;
		else if (filterType==MEDIAN) workToDo *= radius*0.5;
		if (workToDo < 1e6 && imp.getImageStackSize()>=numThreads) {
			numThreads = 1;				//for fast operations, avoid overhead of multi-threading in each image
			flags |= PARALLELIZE_STACKS;
		}
	}
	return flags;
}