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

The following examples show how to use ij.gui.GenericDialog#wasCanceled() . 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: AnimationEditor.java    From 3Dscript with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void runTextFromTo(boolean selection) {
	final TextEditorTab tab = getTab();
	tab.showOutput();
	tab.prepare();

	String text = tab.editorPane.getText();

	GenericDialog gd = new GenericDialog("Run from ... to ...");
	gd.addNumericField("From frame", -1, 0);
	gd.addNumericField("To frame", -1, 0);
	gd.showDialog();
	if(gd.wasCanceled())
		return;

	int from = (int)gd.getNextNumber();
	int to   = (int)gd.getNextNumber();

	try {
		animator.render(text, from, to);
	} catch(Exception ex) {
		handleException(ex);
		tab.restore();
		throw new RuntimeException("Error reading animations", ex);
	}
}
 
Example 2
Source File: TransformationModel.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public boolean queryRegularizedModel()
{
	final GenericDialog gd = new GenericDialog( "Regularization Parameters" );

	gd.addChoice( "Model_to_regularize_with", regularizationModelChoice, regularizationModelChoice[ defaultRegularizationModelIndex ] );
	gd.addNumericField( "Lamba", defaultLambda, 2 );

	gd.showDialog();

	if ( gd.wasCanceled() )
	{
		this.regularize = false;
		return false;
	}

	this.regularizedModelIndex = gd.getNextChoiceIndex();
	this.lambda = gd.getNextNumber();
	this.regularize = true;

	return true;
}
 
Example 3
Source File: EfficientBayesianBased.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected boolean getDebug()
{
	if ( weightType == WeightType.WEIGHTS_ONLY )
		return true;

	if ( debugMode )
	{
		GenericDialog gdDebug = new GenericDialog( "Debug options" );
		gdDebug.addNumericField( "Show debug output every n'th frame, n = ", defaultDebugInterval, 0 );
		gdDebug.showDialog();
		
		if ( gdDebug.wasCanceled() )
			return false;
		
		defaultDebugInterval = debugInterval = (int)Math.round( gdDebug.getNextNumber() );
	}
	
	return true;
}
 
Example 4
Source File: ContrastEnhancerWrapper.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Uses the @param reference Patch as the one to extract the reference histogram from.
 *  Otherwise will use the stack histogram.
 *  @return false when canceled. */
public boolean showDialog() {
	GenericDialog gd = new GenericDialog("Enhance Contrast");
	gd.addNumericField("Saturated Pixels:", saturated, 1, 4, "%");
	gd.addCheckbox("Normalize", normalize);
	gd.addCheckbox("Equalize Histogram", equalize);
	final String[] choices = getChoices();
	gd.addChoice("Use:", choices, choices[stats_mode]);
	gd.addCheckbox("Use full stack", use_full_stack);
	gd.addCheckbox("From existing min and max", from_existing_min_and_max);
	gd.addCheckbox("Visible images only", visible_only);

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

	try {
		set(gd.getNextNumber(), gd.getNextBoolean(), gd.getNextBoolean(),
		    gd.getNextChoiceIndex(), gd.getNextBoolean(), gd.getNextBoolean(),
		    gd.getNextBoolean());
	} catch (Exception e) {
		IJError.print(e);
		return false;
	}
	return true;
}
 
Example 5
Source File: WhiteHatJ_.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
private boolean showDialog() {

        GenericDialog gd = new GenericDialog("White Hat Kernel");
        gd.addNumericField("X size", xSize, 1);
        gd.addNumericField("Y size", ySize, 1);
        //gd.addNumericField("Gaussian Kernel width:", gaussianKernelWidth, 0);

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

        xSize = (int) gd.getNextNumber();
        if (xSize < 1) {
            xSize = 1;
        }
        ySize = (int) gd.getNextNumber();
        if (ySize < 1) {
            ySize = 1;
        }

        return true;
    }
 
Example 6
Source File: BlackHatJ_.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
private boolean showDialog() {

        GenericDialog gd = new GenericDialog("Black Hat Kernel");
        gd.addNumericField("X size", xSize, 1);
        gd.addNumericField("Y size", ySize, 1);
        //gd.addNumericField("Gaussian Kernel width:", gaussianKernelWidth, 0);

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

        xSize = (int) gd.getNextNumber();
        if (xSize < 1) {
            xSize = 1;
        }
        ySize = (int) gd.getNextNumber();
        if (ySize < 1) {
            ySize = 1;
        }

        return true;
    }
 
Example 7
Source File: LabelEdition.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Remove labels under a certain size
 */
void labelSizeOpening()
{
	String title = inputIs2D ? "Area Opening" : "Volume Opening";
	GenericDialog gd = new GenericDialog( title );
       String label = inputIs2D ? "Min Pixel Number:" :
       	"Min Voxel Number:";
       gd.addNumericField( label, 100, 0 );
       gd.showDialog();

       // If cancel was clicked, do nothing
       if ( gd.wasCanceled() )
           return;

       int nPixelMin = (int) gd.getNextNumber();

       // Apply size opening
       ImagePlus res = LabelImages.sizeOpening( displayImage, nPixelMin );
       displayImage.setStack( res.getImageStack() );
       displayImage.updateAndDraw();
}
 
Example 8
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 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: AlignTask.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** @return the chosen mode, or -1 when canceled. */
final static private int chooseAlignmentMode()
{
	final GenericDialog gdMode = new GenericDialog( "Montage mode" );
	gdMode.addChoice( "mode :", modeStrings, modeStrings[ mode ] );
	gdMode.showDialog();
	if ( gdMode.wasCanceled() )
		return -1;

	final int m = gdMode.getNextChoiceIndex();
	// Set the static for future use
	mode = m;
	return m;
}
 
Example 11
Source File: Ball.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void adjustProperties() {
	final GenericDialog gd = makeAdjustPropertiesDialog(); // in superclass
	gd.addCheckbox("Paint as outlines", !fill_paint);
	gd.addCheckbox("Apply paint mode to all Ball instances", false);
	gd.showDialog();
	if (gd.wasCanceled()) return;
	// superclass processing
	final Displayable.DoEdit prev = processAdjustPropertiesDialog(gd);
	// local proccesing
	final boolean fp = !gd.getNextBoolean();
	final boolean to_all = gd.getNextBoolean();
	if (to_all) {
		for (final ZDisplayable zd : layer_set.getZDisplayables()) {
			if (zd.getClass() == Ball.class) {
				final Ball b = (Ball)zd;
				b.fill_paint = fp;
				b.updateInDatabase("fill_paint");
			}
		}
		Display.repaint(layer_set);
	} else if (fill_paint != fp) {
		prev.add("fill_paint", fp);
		this.fill_paint = fp; // change it after storing state in DoEdit
		updateInDatabase("fill_paint");
	}

	// Add current step, with the same modified keys
	final DoEdit current = new DoEdit(this).init(prev);
	if (isLinked()) current.add(new Displayable.DoTransforms().addAll(getLinkedGroup(null)));
	getLayerSet().addEditStep(current);
}
 
Example 12
Source File: AbstractLayerAlignmentParam.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean setupSIFT( final String title )
{
	/* SIFT */
	final GenericDialog gdSIFT = new GenericDialog( title + "SIFT parameters" );

	SIFT.addFields( gdSIFT, ppm.sift );

	gdSIFT.addMessage( "Local Descriptor Matching:" );
	gdSIFT.addNumericField( "closest/next_closest_ratio :", ppm.rod, 2 );

	gdSIFT.addMessage( "Miscellaneous:" );
	gdSIFT.addCheckbox( "clear_cache", ppm.clearCache );
	gdSIFT.addNumericField( "feature_extraction_threads :", ppm.maxNumThreadsSift, 0 );

	gdSIFT.showDialog();

	if ( gdSIFT.wasCanceled() )
		return false;

	SIFT.readFields( gdSIFT, ppm.sift );

	ppm.rod = ( float )gdSIFT.getNextNumber();
	ppm.clearCache = gdSIFT.getNextBoolean();
	ppm.maxNumThreadsSift = ( int )gdSIFT.getNextNumber();

	return true;
}
 
Example 13
Source File: AlignTask.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param patches: the list of Patch instances to align, all belonging to the same Layer.
 * @param fixedPatches: the list of Patch instances to keep locked in place, if any.
 * @param m: {@link AlignTask#LINEAR_SIFT_CORRESPONDENCES}, {@link AlignTask#LINEAR_PHASE_CORRELATION} or {@link AlignTask#ELASTIC_BLOCK_CORRESPONDENCES}.
 */
final static public void alignPatches(
		final List< Patch > patches,
		final Set< Patch > fixedPatches,
		final int m
	) throws Exception
{
	if ( patches.size() < 2 )
	{
		Utils.log("No images to align.");
		return;
	}

	for ( final Patch patch : fixedPatches )
	{
		if ( !patches.contains( patch ) )
		{
			Utils.log("The list of fixed patches contains at least one Patch not included in the list of patches to align!");
			return;
		}
	}

	//final Align.ParamOptimize p = Align.paramOptimize;

	if ( ELASTIC_BLOCK_CORRESPONDENCES == m )
		new ElasticMontage().exec( patches, fixedPatches );
	else if (LINEAR_PHASE_CORRELATION == m) {
		// Montage all given patches, fixedPatches is ignored!
		if (!fixedPatches.isEmpty()) Utils.log("Ignoring " + fixedPatches.size() + " fixed patches.");
		StitchingTEM.montageWithPhaseCorrelation(patches);
	}
	else if (LINEAR_SIFT_CORRESPONDENCES == m)
	{
		if ( !Align.paramOptimize.setup( "Montage Selection" ) )
			return;

		final GenericDialog gd = new GenericDialog( "Montage Selection: Miscellaneous" );

		gd.addCheckbox( "tiles are roughly in place", tilesAreInPlace );
		gd.addCheckbox( "sloppy overlap test (fast)", sloppyOverlapTest );
		gd.addCheckbox( "consider largest graph only", largestGraphOnly );
		gd.addCheckbox( "hide tiles from non-largest graph", hideDisconnectedTiles );
		gd.addCheckbox( "delete tiles from non-largest graph", deleteDisconnectedTiles );

		gd.showDialog();
		if ( gd.wasCanceled() ) return;

		tilesAreInPlace = gd.getNextBoolean();
		sloppyOverlapTest = gd.getNextBoolean();
		largestGraphOnly = gd.getNextBoolean();
		hideDisconnectedTiles = gd.getNextBoolean();
		deleteDisconnectedTiles = gd.getNextBoolean();

		final Align.ParamOptimize p = Align.paramOptimize.clone();
		alignPatches( p, patches, fixedPatches, tilesAreInPlace, largestGraphOnly, hideDisconnectedTiles, deleteDisconnectedTiles, sloppyOverlapTest );
	}
	else
		Utils.log( "Don't know how to align with mode " + m );
}
 
Example 14
Source File: EfficientBayesianBased.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected boolean getBlending()
{
	if ( adjustBlending )
	{
		final GenericDialog gd = new GenericDialog( "Adjust blending parameters" );
		
		if ( defaultBlendingBorder == null || defaultBlendingBorder.length < 3 )
			defaultBlendingBorder = new int[]{ defaultBlendingBorderNumber, defaultBlendingBorderNumber, Math.round( defaultBlendingBorderNumber/2.5f ) };
		
		if ( defaultBlendingRange == null || defaultBlendingRange.length < 3 )
			defaultBlendingRange =  new int[]{ defaultBlendingRangeNumber, defaultBlendingRangeNumber, defaultBlendingRangeNumber };
		
		gd.addSlider( "Boundary_pixels_X", -50, 50, defaultBlendingBorder[ 0 ] );
		gd.addSlider( "Boundary_pixels_Y", -50, 50, defaultBlendingBorder[ 1 ] );
		gd.addSlider( "Boundary_pixels_Z", -50, 50, defaultBlendingBorder[ 2 ] );
		gd.addSlider( "Blending_range_X", 0, 100, defaultBlendingRange[ 0 ] );
		gd.addSlider( "Blending_range_Y", 0, 100, defaultBlendingRange[ 1 ] );
		gd.addSlider( "Blending_range_Z", 0, 100, defaultBlendingRange[ 2 ] );
		
		gd.addMessage( "" );
		gd.addMessage( "Note: both sizes are in local coordinates of the input views. Increase one or both of those values if stripy artifacts\n" +
					   "are visible in the deconvolution result.\n" +
					   "The boundary pixels describe a range of pixels at the edge of each input view that are discarded because of the PSF size,\n" +
					   "it should typically correspond to half the size of the extracted PSF.\n" +
					   "The blending range defines in which outer part of each view the cosine blending is performed. You can manually inspect\n" +
					   "the results of these operations by choosing 'Illustrate overlap of views per pixel (do not deconvolve)' in the previous\n" +
					   "dialog. Choose just one input view to get an idea of what is cut off for individual stacks.", GUIHelper.mediumstatusfont );
		
		gd.showDialog();
		
		if ( gd.wasCanceled() )
			return false;
		
		blendingBorderX = defaultBlendingBorder[ 0 ] = (int)Math.round( gd.getNextNumber() );
		blendingBorderY = defaultBlendingBorder[ 1 ] = (int)Math.round( gd.getNextNumber() );
		blendingBorderZ = defaultBlendingBorder[ 2 ] = (int)Math.round( gd.getNextNumber() );
		blendingRangeX = defaultBlendingRange[ 0 ] = (int)Math.round( gd.getNextNumber() );
		blendingRangeY = defaultBlendingRange[ 1 ] = (int)Math.round( gd.getNextNumber() );
		blendingRangeZ = defaultBlendingRange[ 2 ] = (int)Math.round( gd.getNextNumber() );
	}
	else
	{
		if ( defaultBlendingBorder != null && defaultBlendingBorder.length >= 3 )
		{
			blendingBorderX = defaultBlendingBorder[ 0 ];
			blendingBorderY = defaultBlendingBorder[ 1 ];
			blendingBorderZ = defaultBlendingBorder[ 2 ];
		}
		else
		{
			blendingBorderX = defaultBlendingBorderNumber;
			blendingBorderY = defaultBlendingBorderNumber;
			blendingBorderZ = Math.round( defaultBlendingBorderNumber/2.5f );
		}
		
		if ( defaultBlendingRange != null && defaultBlendingRange.length >= 3 )
		{
			blendingRangeX = defaultBlendingRange[ 0 ];
			blendingRangeY = defaultBlendingRange[ 1 ];
			blendingRangeZ = defaultBlendingRange[ 2 ];
		}
		else
		{
			blendingRangeX = defaultBlendingRangeNumber;
			blendingRangeY = defaultBlendingRangeNumber;
			blendingRangeZ = defaultBlendingRangeNumber;
		}
	}
	
	return true;
}
 
Example 15
Source File: SNTPrefs.java    From SNT with GNU General Public License v3.0 4 votes vote down vote up
protected void promptForOptions() {

		final int startupOptions = 7;
		final int pluginOptions = 2;

		final String[] startupLabels = new String[startupOptions];
		final int[] startupItems = new int[startupOptions];
		final boolean[] startupStates = new boolean[startupOptions];
		int idx = 0;

		startupItems[idx] = ENFORCE_LUT;
		startupLabels[idx] = "Enforce non-inverted grayscale LUT";
		startupStates[idx++] = snt.forceGrayscale;

		startupItems[idx] = USE_THREE_PANE;
		startupLabels[idx] = "Use_three-pane view";
		startupStates[idx++] = !snt.getSinglePane();

		startupItems[idx] = USE_3D_VIEWER;
		startupLabels[idx] = "Use_3D Viewer";
		startupStates[idx++] = snt.use3DViewer;

		startupItems[idx] = LOOK_FOR_TUBES;
		startupLabels[idx] = "Load_Tubeness \".tubes.tif\" pre-processed file (if present)";
		startupStates[idx++] = snt.look4tubesFile;

		startupItems[idx] = LOOK_FOR_OOF;
		startupLabels[idx] = "Load_Tubular_Geodesics \".oof.ext\" pre-processed file (if present)";
		startupStates[idx++] = snt.look4oofFile;

		startupItems[idx] = LOOK_FOR_TRACES;
		startupLabels[idx] = "Load_default \".traces\" file (if present)";
		startupStates[idx++] = snt.look4tracesFile;

		startupItems[idx] = STORE_WIN_LOCATIONS;
		startupLabels[idx] = "Remember window locations across restarts";
		startupStates[idx++] = isSaveWinLocations();

		final String[] pluginLabels = new String[pluginOptions];
		final int[] pluginItems = new int[pluginOptions];
		final boolean[] pluginStates = new boolean[pluginOptions];
		idx = 0;

		pluginItems[idx] = COMPRESSED_XML;
		pluginLabels[idx] = "Use compression when saving traces";
		pluginStates[idx++] = snt.useCompressedXML;

		pluginItems[idx] = DEBUG;
		pluginLabels[idx] = "Enable_debug mode";
		pluginStates[idx++] = SimpleNeuriteTracer.verbose;

		final GenericDialog gd = new GenericDialog("SNT v" + SNT.VERSION + " Preferences");
		final Font font = new Font("SansSerif", Font.BOLD, 12);
		gd.setInsets(0, 0, 0);
		gd.addMessage("Startup Options:", font);
		gd.setInsets(0, 0, 0);
		gd.addCheckboxGroup(startupOptions, 1, startupLabels, startupStates);
		gd.setInsets(20, 0, 0);
		gd.addMessage("Advanced Options:", font);
		gd.setInsets(0, 0, 0);
		gd.addCheckboxGroup(pluginOptions, 1, pluginLabels, pluginStates);

		gd.enableYesNoCancel("OK", "Revert to Defaults");
		gd.showDialog();
		if (gd.wasCanceled()) {
			return;
		} else if (gd.wasOKed()) {

			for (int i = 0; i < startupOptions; i++) {
				if (gd.getNextBoolean())
					currentBooleans |= startupItems[i];
				else
					currentBooleans &= ~startupItems[i];
			}
			for (int i = 0; i < pluginOptions; i++) {
				if (gd.getNextBoolean())
					currentBooleans |= pluginItems[i];
				else
					currentBooleans &= ~pluginItems[i];
			}
			Prefs.set(BOOLEANS, currentBooleans);

		} else {
			resetOptions();
		}

		Prefs.savePreferences();
		loadPluginPrefs();

	}
 
Example 16
Source File: ExtendedMinAndMax3DPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
	public void run(String arg) {
		
		if ( IJ.getVersion().compareTo("1.48a") < 0 )
		{
			IJ.error( "Regional Minima and Maxima", "ERROR: detected ImageJ version " + IJ.getVersion()  
					+ ".\nThis plugin requires version 1.48a or superior, please update ImageJ!" );
			return;
		}
		
		ImagePlus imagePlus = IJ.getImage();
		
		if (imagePlus.getStackSize() == 1) {
			IJ.error("Requires a Stack");
			return;
		}
		
		ImageStack stack = imagePlus.getStack();
		int sizeX = stack.getWidth();
		int sizeY = stack.getHeight();
		int sizeZ = stack.getSize();
		boolean isGray8 = stack.getBitDepth() == 8;
		double minValue, maxValue;
		if (isGray8) {
			minValue = 1;
			maxValue = 255;
		} else {
			minValue = Double.MAX_VALUE;
			maxValue = Double.MIN_VALUE;
			for (int z = 0; z < sizeZ; z++) {
				for (int y = 0; y < sizeY; y++) {
					for (int x = 0; x < sizeX; x++) {
						double val = stack.getVoxel(x, y, z);
						minValue = Math.min(minValue, val);
						maxValue = Math.max(maxValue, val);
					}
				}
			}
		}
		
		// Create the configuration dialog
		GenericDialog gd = new GenericDialog("Extended Min & Max 3D");
		gd.addChoice("Operation", Operation.getAllLabels(), 
				Operation.EXTENDED_MINIMA.label);
		gd.addSlider("Dynamic", minValue, maxValue, 10);		
		gd.addChoice("Connectivity", connectivityLabels, connectivityLabels[0]);
//		gd.addHelp("http://imagejdocu.tudor.lu/doku.php?id=plugin:morphology:fast_morphological_filters:start");
        gd.showDialog();
        if (gd.wasCanceled())
        	return;
        
		long t0 = System.currentTimeMillis();
		
		// extract chosen parameters
		Operation op = Operation.fromLabel(gd.getNextChoice());
		int dynamic = (int) gd.getNextNumber();
		int conn = connectivityValues[gd.getNextChoiceIndex()];
        
		ImageStack result = op.apply(stack, dynamic, conn);
		
		String newName = createResultImageName(imagePlus, op);
		ImagePlus resultPlus = new ImagePlus(newName, result);
		resultPlus.copyScale(imagePlus);
				
		resultPlus.show();
		
		resultPlus.setSlice(imagePlus.getCurrentSlice());

		long t1 = System.currentTimeMillis();
		IJUtils.showElapsedTime(op.toString(), t1 - t0, imagePlus);
	}
 
Example 17
Source File: BoundingBoxPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void run(String args)
{
	// Open a dialog to choose:
	// - a label image
	// - a 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();
	}
	
	// name of selected image
	String selectedImageName = IJ.getImage().getTitle();

	// create the dialog
	GenericDialog gd = new GenericDialog("Bounding Box");
	gd.addChoice("Label Image:", imageNames, selectedImageName);
	gd.addCheckbox("Show Overlay Result", true);
	gd.addChoice("Image to overlay:", imageNames, selectedImageName);
	gd.showDialog();
	
	if (gd.wasCanceled())
		return;
	
	// set up current parameters
	int labelImageIndex = gd.getNextChoiceIndex();
	ImagePlus labelImage = WindowManager.getImage(labelImageIndex + 1);
	boolean showOverlay = gd.getNextBoolean();
	int resultImageIndex = gd.getNextChoiceIndex();
	
	// check if image is a label image
	if (!LabelImages.isLabelImageType(labelImage))
	{
           IJ.showMessage("Input image should be a label image");
           return;
       }

       // Execute the plugin
	BoundingBox op = new BoundingBox();
	Map<Integer, Box2D> boxes = op.analyzeRegions(labelImage);
       ResultsTable results = op.createTable(boxes);
       
	// show result
   	String tableName = labelImage.getShortTitle() + "-BBox"; 
   	results.show(tableName);
   	
	// Check if results must be displayed on an image
	if (showOverlay)
	{
		// find image for displaying geometric overlays
		ImagePlus resultImage = WindowManager.getImage(resultImageIndex + 1);
		showResultsAsOverlay(boxes, resultImage);
	}
   }
 
Example 18
Source File: DistortionCorrectionTask.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public boolean setupSIFT( final String title )
{
	/* SIFT */
	final GenericDialog gdSIFT = new GenericDialog( title + "SIFT parameters" );

	SIFT.addFields( gdSIFT, sift );

	gdSIFT.addMessage( "Local Descriptor Matching:" );
	gdSIFT.addNumericField( "closest/next_closest_ratio :", rod, 2 );

	gdSIFT.addMessage( "Miscellaneous:" );
	gdSIFT.addNumericField( "feature_extraction_threads :", maxNumThreadsSift, 0 );

	gdSIFT.showDialog();

	if ( gdSIFT.wasCanceled() )
		return false;

	SIFT.readFields( gdSIFT, sift );

	rod = ( float )gdSIFT.getNextNumber();
	maxNumThreadsSift = ( int )gdSIFT.getNextNumber();

	return true;
}
 
Example 19
Source File: Align.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
final public boolean setup( final String title )
{
	/* SIFT */
	final GenericDialog gdSIFT = new GenericDialog( title + ": SIFT parameters" );
	addSIFTFields( gdSIFT );
	do
	{
		gdSIFT.showDialog();
		if ( gdSIFT.wasCanceled() ) return false;
	}
	while ( !readSIFTFields( gdSIFT ) );

	/* Geometric consensus */
	final GenericDialog gdGeometricConsensusFilter = new GenericDialog( title + ": Geometric Consensus Filter" );
	addGeometricConsensusFilterFields( gdGeometricConsensusFilter );
	do
	{
		gdGeometricConsensusFilter.showDialog();
		if ( gdGeometricConsensusFilter.wasCanceled() ) return false;
	}
	while ( !readGeometricConsensusFilterFields( gdGeometricConsensusFilter ) );

	/* Alignment */
	final GenericDialog gdAlignment = new GenericDialog( title + ": Alignment parameters" );
	addAlignmentFields( gdAlignment );
	do
	{
		gdAlignment.showDialog();
		if ( gdAlignment.wasCanceled() ) return false;
	}
	while ( !readAlignmentFields( gdAlignment ) );

	/* Regularization */
	if ( regularize )
	{
		final GenericDialog gdRegularization = new GenericDialog( title + ": Regularization parameters" );
		addRegularizationFields( gdRegularization );
		do
		{
			gdRegularization.showDialog();
			if ( gdRegularization.wasCanceled() ) return false;
		}
		while ( !readRegularizationFields( gdRegularization ) );
	}

	return true;
}
 
Example 20
Source File: MaxInscribedCirclePlugin.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:
		// - a label image
		// - a 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();
		}
		
		// name of selected image
		String selectedImageName = IJ.getImage().getTitle();

		// create the dialog
		GenericDialog gd = new GenericDialog("Max. Inscribed Circle");
		gd.addChoice("Label Image:", imageNames, selectedImageName);
//		// Set Chessknight weights as default
//		gd.addChoice("Distances", ChamferWeights.getAllLabels(), 
//				ChamferWeights.CHESSKNIGHT.toString());
		gd.addCheckbox("Show Overlay Result", true);
		gd.addChoice("Image to overlay:", imageNames, selectedImageName);
		gd.showDialog();
		
		if (gd.wasCanceled())
			return;
		
		// set up current parameters
		int labelImageIndex = gd.getNextChoiceIndex();
		ImagePlus labelImage = WindowManager.getImage(labelImageIndex+1);
//		ChamferWeights weights = ChamferWeights.fromLabel(gd.getNextChoice());
		boolean showOverlay = gd.getNextBoolean();
		int resultImageIndex = gd.getNextChoiceIndex();
		
		// check if image is a label image
		if (!LabelImages.isLabelImageType(labelImage))
		{
            IJ.showMessage("Input image should be a label image");
            return;
        }
        
		// Execute the plugin
    	LargestInscribedCircle op = new LargestInscribedCircle();
		Map<Integer, Circle2D> results = op.analyzeRegions(labelImage);
       
        // Display plugin result as table
		ResultsTable table = op.createTable(results);
		String tableName = labelImage.getShortTitle() + "-MaxInscribedCircle"; 
		table.show(tableName);
		
		// Check if results must be displayed on an image
		if (showOverlay)
		{
			// find image for displaying geometric overlays
			ImagePlus resultImage = WindowManager.getImage(resultImageIndex + 1);
			showResultsAsOverlay(results, resultImage);
		}
	}