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

The following examples show how to use ij.gui.GenericDialog#showDialog() . 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: 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 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: PairwiseStitchingParameters.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static PairwiseStitchingParameters askUserForParameters()
{
	// ask user for parameters
	GenericDialog gd = new GenericDialog("Pairwise stitching options");
	addQueriesToGD( gd );

	gd.showDialog();
	return getParametersFromGD( gd );
}
 
Example 4
Source File: Toggle_Cluster_Options.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run( String arg0 )
{
	final GenericDialog gd = new GenericDialog( "Toggle Cluster Processing Options" );
	gd.addCheckbox( "Display_Cluster Processing Options", displayClusterProcessing );
	gd.showDialog();

	if ( gd.wasCanceled() )
		return;

	displayClusterProcessing = gd.getNextBoolean();

	IOFunctions.println( "Cluster processing option: " + ( displayClusterProcessing ? "ON" : "OFF" ) );
}
 
Example 5
Source File: DifferenceOfMean.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected boolean setAdvancedValues( final Channel channel )
{
	final int channelId = channel.getId();
	
	final GenericDialog gd = new GenericDialog( "Advanced values for channel " + channel.getName() );

	String ch;

	if ( this.channelsToProcess.size() > 1 )
		ch = "_" + channel.getName().replace( ' ', '_' );
	else
		ch = "";

	gd.addMessage( "Advanced values for channel " + channel.getName() );
	gd.addNumericField( "Radius_1" + ch, defaultRadius1[ channelId ], 0 );
	gd.addNumericField( "Radius_2" + ch, defaultRadius2[ channelId ], 0 );
	gd.addNumericField( "Threshold" + ch, defaultThreshold[ channelId ], 4 );
	gd.addCheckbox( "Find_minima" + ch, defaultFindMin[ channelId ] );
	gd.addCheckbox( "Find_maxima" + ch, defaultFindMax[ channelId ] );

	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return false;
	
	this.radius1[ channelId ] = defaultRadius1[ channelId ] = (int)Math.round( gd.getNextNumber() );
	this.radius2[ channelId ] = defaultRadius2[ channelId ] = (int)Math.round( gd.getNextNumber() );
	this.threshold[ channelId ] = defaultThreshold[ channelId ] = gd.getNextNumber();
	this.findMin[ channelId ] = defaultFindMin[ channelId ] = gd.getNextBoolean();
	this.findMax[ channelId ] = defaultFindMax[ channelId ] = gd.getNextBoolean();
	
	return true;
}
 
Example 6
Source File: Specify_Calibration.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static boolean queryNewCal( final ArrayList< Cal > calibrations, final Cal maxCal )
{
	final GenericDialog gd = new GenericDialog( "Define new calibration" );
	
	gd.addNumericField( "Calibration_x", maxCal.getCal()[ 0 ], 40, 20, "" );
	// ImageJ cuts of part of the number otherwise
	((TextField)gd.getNumericFields().lastElement()).setText( "" + maxCal.getCal()[ 0 ] );
	gd.addNumericField( "Calibration_y", maxCal.getCal()[ 1 ], 40, 20, "" );
	// ImageJ cuts of part of the number otherwise
	((TextField)gd.getNumericFields().lastElement()).setText( "" + maxCal.getCal()[ 1 ] );
	gd.addNumericField( "Calibration_z", maxCal.getCal()[ 2 ], 40, 20, "" );
	// ImageJ cuts of part of the number otherwise
	((TextField)gd.getNumericFields().lastElement()).setText( "" + maxCal.getCal()[ 2 ] );
	gd.addStringField( "Unit", maxCal.unit() );

	if ( calibrations.size() > 1 )
		gd.addMessage( "WARNING: Calibrations are not the same for all\n" +
					   "view setups! All calibrations will be overwritten\n" +
					   "for all view setups if defined here.",
					   GUIHelper.mediumstatusfont, GUIHelper.warning );

	gd.addMessage( "Note: These values will be applied to selected view\n" +
				   "setups, existing registration are not affected and\n" +
				   "will need to be recomputed if necessary.",
				   GUIHelper.mediumstatusfont );

	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return false;
	
	maxCal.getCal()[ 0 ] = gd.getNextNumber();
	maxCal.getCal()[ 1 ] = gd.getNextNumber();
	maxCal.getCal()[ 2 ] = gd.getNextNumber();
	maxCal.setUnit( gd.getNextString() );

	return true;
}
 
Example 7
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 8
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean setup( final String title )
{
	final GenericDialog gd = new GenericDialog( title );
	addFields( gd );
	do
	{
		gd.showDialog();
		if ( gd.wasCanceled() ) return false;
	}
	while ( !readFields( gd ) );

	return true;
}
 
Example 9
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;
}
 
Example 10
Source File: MorphologicalFilter3DPlugin.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( "Morphological Filter 3D", "ERROR: detected ImageJ version " + IJ.getVersion()  
				+ ".\nThis plugin requires version 1.48a or superior, please update ImageJ!" );
		return;
	}
	
	ImagePlus imagePlus = WindowManager.getCurrentImage();
	if (imagePlus == null) 
	{
		IJ.error("No image", "Need at least one image to work");
		return;
	}
	
	// create the dialog
	GenericDialog gd = new GenericDialog("Morphological Filters (3D)");
	
	gd.addChoice("Operation", Operation.getAllLabels(), 
			Operation.DILATION.toString());
	gd.addChoice("Element Shape", Strel3D.Shape.getAllLabels(), 
			Strel3D.Shape.CUBE.toString());
	gd.addNumericField("X-Radius (in voxels)", 2, 0);
	gd.addNumericField("Y-Radius (in voxels)", 2, 0);
	gd.addNumericField("Z-Radius (in voxels)", 2, 0);
	gd.addCheckbox("Show Element", false);
	
	// Could also add an option for the type of operation
	gd.showDialog();
	
	if (gd.wasCanceled())
		return;
	
	long t0 = System.currentTimeMillis();

	// extract chosen parameters
	Operation op = Operation.fromLabel(gd.getNextChoice());
	Strel3D.Shape strelShape = Strel3D.Shape.fromLabel(gd.getNextChoice());
	int radiusX = (int) gd.getNextNumber();		
	int radiusY = (int) gd.getNextNumber();		
	int radiusZ = (int) gd.getNextNumber();		
	boolean showStrel = gd.getNextBoolean();
	
	// Create structuring element of the given size
	Strel3D strel = strelShape.fromRadiusList(radiusX, radiusY, radiusZ);
	strel.showProgress(true);
	DefaultAlgoListener.monitor(strel);
	
	// Eventually display the structuring element used for processing 
	if (showStrel)
	{
		showStrelImage(strel);
	}
	
	// Execute core of the plugin
	ImagePlus resPlus = process(imagePlus, op, strel);

	if (resPlus == null)
		return;

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

	// Display elapsed time
	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime(op.toString(), t1 - t0, imagePlus);
}
 
Example 11
Source File: LabelingPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run(String arg)
{
	ImagePlus imagePlus = IJ.getImage();
	
	boolean isPlanar = imagePlus.getStackSize() == 1;
	
	// Display dialog options
	GenericDialog gd = new GenericDialog("Connected Components Labeling");
	String[] connLabels = isPlanar ? conn2DLabels : conn3DLabels;
	gd.addChoice("Connectivity", connLabels, connLabels[0]);
	gd.addChoice("Type of result", resultBitDepthLabels, resultBitDepthLabels[1]);
	
	// wait for user answer
	gd.showDialog();
	if (gd.wasCanceled()) 
		return;

	// parses dialog options
	int connIndex = gd.getNextChoiceIndex();
	int bitDepth = resultBitDepthList[gd.getNextChoiceIndex()];
	int conn = isPlanar ? conn2DValues[connIndex] : conn3DValues[connIndex];

	// Compute components labeling
	ImagePlus resultPlus;
	try
	{ 	
		resultPlus = BinaryImages.componentsLabeling(imagePlus, conn, bitDepth);
	} 
	catch(RuntimeException ex)
	{
		IJ.error("Components Labeling Error", ex.getMessage() + "\nTry with larger data type (short or float)");
		return;
	}
	
	// update meta information of result image
	String newName = imagePlus.getShortTitle() + "-lbl";
	resultPlus.setTitle(newName);
	resultPlus.copyScale(imagePlus);
	
	// Display with same settings as original image
	resultPlus.show();
	
	// For 2D images, select the same visible slice as original image
	if (!isPlanar)
	{
		resultPlus.setZ(imagePlus.getZ());
		resultPlus.setSlice(imagePlus.getCurrentSlice());
	}
}
 
Example 12
Source File: LegacyStackImgLoaderIJ.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected static Parameters queryParameters()
{
	final GenericDialog gd = new GenericDialog( "Opening 32bit TIFF as 16bit" );

	gd.addMessage( "You are trying to open 32-bit images as 16-bit (resaving as HDF5 maybe). Please define how to convert to 16bit.", GUIHelper.mediumstatusfont );
	gd.addMessage( "Note: This dialog will only show up once for the first image.", GUIHelper.mediumstatusfont );
	gd.addChoice( "Convert_32bit", Generic_Resave_HDF5.convertChoices, Generic_Resave_HDF5.convertChoices[ Generic_Resave_HDF5.defaultConvertChoice ] );

	gd.showDialog();

	if ( gd.wasCanceled() )
		return null;

	Generic_Resave_HDF5.defaultConvertChoice = gd.getNextChoiceIndex();

	if ( Generic_Resave_HDF5.defaultConvertChoice == 2 )
	{
		if ( Double.isNaN( Generic_Resave_HDF5.defaultMin ) )
			Generic_Resave_HDF5.defaultMin = 0;

		if ( Double.isNaN( Generic_Resave_HDF5.defaultMax ) )
			Generic_Resave_HDF5.defaultMax = 5;

		final GenericDialog gdMinMax = new GenericDialog( "Define min/max" );

		gdMinMax.addNumericField( "Min_Intensity_for_16bit_conversion", Generic_Resave_HDF5.defaultMin, 1 );
		gdMinMax.addNumericField( "Max_Intensity_for_16bit_conversion", Generic_Resave_HDF5.defaultMax, 1 );
		gdMinMax.addMessage( "Note: the typical range for multiview deconvolution is [0 ... 10] & for fusion the same as the input intensities., ",GUIHelper.mediumstatusfont );

		gdMinMax.showDialog();

		if ( gdMinMax.wasCanceled() )
			return null;

		Generic_Resave_HDF5.defaultMin = gdMinMax.getNextNumber();
		Generic_Resave_HDF5.defaultMax = gdMinMax.getNextNumber();
	}
	else
	{
		Generic_Resave_HDF5.defaultMin = Generic_Resave_HDF5.defaultMax = Double.NaN;
	}

	return new Parameters( false, null, null, null, null, false, false, 0, 0, false, 0, Generic_Resave_HDF5.defaultConvertChoice, Generic_Resave_HDF5.defaultMin, Generic_Resave_HDF5.defaultMax );
}
 
Example 13
Source File: GenericLoadParseQueryXML.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Querys a multiple element from the list
 * 
 * @param name - type of elements (e.g. "Timepoints")
 * @param list - list of available elements
 * @param defaultSelection - default selection
 * @return the selection or null if cancelled
 */
public static boolean[] queryMultipleEntries( final String name, final String[] list, boolean[] defaultSelection )
{
	if ( defaultSelection == null || defaultSelection.length != list.length )
	{
		defaultSelection = new boolean[ list.length ];
		defaultSelection[ 0 ] = true;
		for ( int i = 1; i < list.length; ++i )
			defaultSelection[ i ] = false;
		
		// by default select first two
		if ( defaultSelection.length > 1 )
			defaultSelection[ 1 ] = true;
	}
	
	for ( int i = 0; i < list.length; ++i )
		list[ i ] = list[ i ].replace( " ", "_" );
	
	final GenericDialog gd = new GenericDialog( "Select Multiple " + name );
	
	gd.addMessage( "" );
	for ( int i = 0; i < list.length; ++i )
		gd.addCheckbox( list[ i ], defaultSelection[ i ] );
	gd.addMessage( "" );

	GUIHelper.addScrollBars( gd );
	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return null;

	for ( int i = 0; i < list.length; ++i )
	{
		if ( gd.getNextBoolean() )
			defaultSelection[ i ] = true;
		else
			defaultSelection[ i ] = false;
	}

	return defaultSelection;
}
 
Example 14
Source File: Duplicate_Transformation.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run( final String arg0 )
{
	final GenericDialog gd = new GenericDialog( "Define Duplication" );
	gd.addChoice( "Apply transformation of", duplicationChoice, duplicationChoice[ defaultChoice ] );
	gd.showDialog();
	if ( gd.wasCanceled() )
		return;
	
	final int choice = defaultChoice = gd.getNextChoiceIndex();

	final boolean askForTimepoints = choice != 0;
	final boolean askForChannels = choice != 1;
	final boolean askForIllum = choice != 2;
	final boolean askForAngles = choice != 3;

	final LoadParseQueryXML result = new LoadParseQueryXML();
	
	if ( !result.queryXML( "duplicating transformations", "Apply to", askForAngles, askForChannels, askForIllum, askForTimepoints ) )
		return;
	
	if ( !askForTimepoints )
	{
		if ( result.getTimePointsToProcess().size() == 1 )
		{
			IOFunctions.println( "Only one timepoint available, cannot apply to another timepoint." );
			return;
		}
		else
		{
			if ( !applyTimepoints( result ) )
				return;
		}
	}
	else if ( !askForChannels )
	{
		if ( result.getChannelsToProcess().size() == 1 )
		{
			IOFunctions.println( "Only one channel available, cannot apply to another channel." );
			return;
		}
		else
		{
			if ( !applyChannels( result ) )
				return;
		}			
	}
	else if ( !askForIllum )
	{
		if ( result.getIlluminationsToProcess().size() == 1 )
		{
			IOFunctions.println( "Only one illumination direction available, cannot apply to another illumination direction." );
			return;
		}
		else
		{
			if ( !applyIllums( result ) )
				return;
		}			
	}
	else if ( !askForAngles )
	{
		if ( result.getAnglesToProcess().size() == 1 )
		{
			IOFunctions.println( "Only one angle available, cannot apply to another angle." );
			return;
		}
		else
		{
			if ( !applyAngles( result ) )
				return;
		}			
	}

	// now save it in case something was applied
	SpimData2.saveXML( result.getData(), new File( result.getXMLFileName() ).getName(), result.getClusterExtension() );
}
 
Example 15
Source File: ImportFromRender_Plugin.java    From render with GNU General Public License v2.0 4 votes vote down vote up
boolean setParametersFromDialog() {

            final GenericDialog dialog = new GenericDialog("Import Parameters");

            final int defaultTextColumns = 80;
            dialog.addStringField("Render Web Services Base URL", baseDataUrl, defaultTextColumns);
            dialog.addStringField("Render Stack Owner", renderOwner, defaultTextColumns);
            dialog.addStringField("Render Stack Project", renderProject, defaultTextColumns);
            dialog.addStringField("Render Stack Name", renderStack, defaultTextColumns);
            dialog.addStringField("Channel (empty for default)", "", defaultTextColumns);
            dialog.addNumericField("Min Z", minZ, 1);
            dialog.addNumericField("Max Z", maxZ, 1);
            dialog.addNumericField("Image Plus Type (use '-1' to slowly derive dynamically)", imagePlusType, 0);
            dialog.addMessage("  note: image plus type values are: 0:GRAY8, 1:GRAY16, 2:GRAY32, 3:COLOR_256, 4:COLOR_RGB");
            dialog.addCheckbox("Load Masks", loadMasks);
            dialog.addCheckbox("Split Sections", splitSections);
            dialog.addCheckbox("Replace Last Transform With Stage", replaceLastWithStage);
            dialog.addNumericField("Number of threads for mipmaps", numberOfMipmapThreads, 0);

            dialog.showDialog();
            dialog.repaint(); // seems to help with missing dialog elements, but shouldn't be necessary

            final boolean wasCancelled = dialog.wasCanceled();

            if (! wasCancelled) {
                baseDataUrl = dialog.getNextString();
                renderOwner = dialog.getNextString();
                renderProject = dialog.getNextString();
                renderStack =  dialog.getNextString();
                String channelString = dialog.getNextString();
                if (channelString != null && channelString.length() > 0) {
                    channels.add(channelString);
                }
                minZ = dialog.getNextNumber();
                maxZ = dialog.getNextNumber();
                imagePlusType = new Double(dialog.getNextNumber()).intValue();
                loadMasks = dialog.getNextBoolean();
                splitSections = dialog.getNextBoolean();
                replaceLastWithStage = dialog.getNextBoolean();
                numberOfMipmapThreads = (int) dialog.getNextNumber();
            }

            return wasCancelled;
        }
 
Example 16
Source File: MaxInscribedSpherePlugin.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 Sphere");
		gd.addChoice("Label Image:", imageNames, selectedImageName);
		// Set Borgefors weights as default
//		gd.addChoice("Distances", ChamferWeights3D.getAllLabels(), 
//				ChamferWeights3D.BORGEFORS.toString());
		gd.showDialog();
		
		if (gd.wasCanceled())
			return;
		
		// set up current parameters
		int labelImageIndex = gd.getNextChoiceIndex();
		ImagePlus labelImage = WindowManager.getImage(labelImageIndex+1);
//		ChamferWeights3D weights = ChamferWeights3D.fromLabel(gd.getNextChoice());
		
		// check if image is a 3D label image
		if (labelImage.getStackSize() <= 1) 
		{
            IJ.showMessage("Input image should be a 3D label image");
            return;
		}
		
		// Check if image may be a label image
		if (!LabelImages.isLabelImageType(labelImage))
		{
            IJ.showMessage("Input image should be a 3D label image");
            return;
        }
        
		// Execute the plugin
		LargestInscribedBall algo = new LargestInscribedBall();
		DefaultAlgoListener.monitor(algo);
		ResultsTable table = algo.computeTable(labelImage);
        
        // Display plugin result
		String tableName = labelImage.getShortTitle() + "-MaxInscribedSphere"; 
		table.show(tableName);
	}
 
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 setup( final Selection selection )
{
	if ( !setupSIFT( "Distortion Correction: " ) )
		return false;

	/* Geometric filters */

	final GenericDialog gd = new GenericDialog( "Distortion Correction: Geometric filters" );

	gd.addNumericField( "maximal_alignment_error :", maxEpsilon, 2, 6, "px" );
	gd.addNumericField( "minimal_inlier_ratio :", minInlierRatio, 2 );
	gd.addNumericField( "minimal_number_of_inliers :", minNumInliers, 0 );
	gd.addChoice( "expected_transformation :", Param.modelStrings, Param.modelStrings[ expectedModelIndex ] );
	gd.addCheckbox( "test_multiple_hypotheses", multipleHypotheses );
	gd.addCheckbox( "ignore constant background", rejectIdentity );
	gd.addNumericField( "tolerance :", identityTolerance, 2, 6, "px" );
	gd.addCheckbox( "tiles are rougly in place", tilesAreInPlace );

	gd.showDialog();

	if ( gd.wasCanceled() )
		return false;

	maxEpsilon = ( float )gd.getNextNumber();
	minInlierRatio = ( float )gd.getNextNumber();
	minNumInliers = ( int )gd.getNextNumber();
	expectedModelIndex = gd.getNextChoiceIndex();
	multipleHypotheses = gd.getNextBoolean();
	rejectIdentity = gd.getNextBoolean();
	identityTolerance = ( float )gd.getNextNumber();
	tilesAreInPlace = gd.getNextBoolean();

	final GenericDialog gdOptimize = new GenericDialog( "Distortion Correction: Montage Optimization" );
	gdOptimize.addChoice( "desired_transformation :", modelStrings, modelStrings[ desiredModelIndex ] );
	gdOptimize.addCheckbox( "regularize_model", regularize );
	gdOptimize.addMessage( "Optimization:" );
	gdOptimize.addNumericField( "maximal_iterations :", maxIterationsOptimize, 0 );
	gdOptimize.addNumericField( "maximal_plateauwidth :", maxPlateauwidthOptimize, 0 );

	gdOptimize.showDialog();

	if ( gdOptimize.wasCanceled() )
		return false;

	desiredModelIndex = gdOptimize.getNextChoiceIndex();
	regularize = gdOptimize.getNextBoolean();
	maxIterationsOptimize = ( int )gdOptimize.getNextNumber();
	maxPlateauwidthOptimize = ( int )gdOptimize.getNextNumber();

	if ( regularize )
	{
		final GenericDialog gdRegularize = new GenericDialog( "Distortion Correction: Montage Regularization" );

		gdRegularize.addChoice( "regularizer :", modelStrings, modelStrings[ regularizerIndex ] );
		gdRegularize.addNumericField( "lambda :", lambdaRegularize, 2 );

		gdRegularize.showDialog();

		if ( gdRegularize.wasCanceled() )
			return false;

		regularizerIndex = gdRegularize.getNextChoiceIndex();
		lambdaRegularize = gdRegularize.getNextNumber();
	}

	final GenericDialog gdLens = new GenericDialog( "Distortion Correction: Lens Distortion" );

	gdLens.addMessage( "Lens Model :" );
	gdLens.addNumericField( "power_of_polynomial_kernel :", dimension, 0 );
	gdLens.addNumericField( "lambda :", lambda, 6 );

	gdLens.addMessage( "Apply Distortion Correction :" );

	Utils.addLayerRangeChoices( selection.getLayer(), gdLens );
	gdLens.addCheckbox( "clear_present_transforms", clearTransform );
	gdLens.addCheckbox( "visualize_distortion_model", visualize );

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

	dimension = ( int )gdLens.getNextNumber();
	lambda = ( double )gdLens.getNextNumber();
	firstLayerIndex = gdLens.getNextChoiceIndex();
	lastLayerIndex = gdLens.getNextChoiceIndex();
	clearTransform = gdLens.getNextBoolean();
	visualize = gdLens.getNextBoolean();

	return true;
}
 
Example 19
Source File: ElasticMontage.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public boolean setup()
{
	/* Block Matching */
	if ( bmBlockRadius < 0 )
	{
		bmBlockRadius = Util.roundPos( springLengthSpringMesh / 2 );
	}
	final GenericDialog gdBlockMatching = new GenericDialog( "Elastic montage: Block Matching and Spring Meshes" );

	gdBlockMatching.addMessage( "Block Matching:" );
	gdBlockMatching.addNumericField( "patch_scale :", bmScale, 2 );
	gdBlockMatching.addNumericField( "search_radius :", bmSearchRadius, 0, 6, "px" );
	gdBlockMatching.addNumericField( "block_radius :", bmBlockRadius, 0, 6, "px" );

	gdBlockMatching.addMessage( "Correlation Filters:" );
	gdBlockMatching.addNumericField( "minimal_PMCC_r :", bmMinR, 2 );
	gdBlockMatching.addNumericField( "maximal_curvature_ratio :", bmMaxCurvatureR, 2 );
	gdBlockMatching.addNumericField( "maximal_second_best_r/best_r :", bmRodR, 2 );

	gdBlockMatching.addMessage( "Local Smoothness Filter:" );
	gdBlockMatching.addCheckbox( "use_local_smoothness_filter", bmUseLocalSmoothnessFilter );
	gdBlockMatching.addChoice( "approximate_local_transformation :", ParamOptimize.modelStrings, ParamOptimize.modelStrings[ bmLocalModelIndex ] );
	gdBlockMatching.addNumericField( "local_region_sigma:", bmLocalRegionSigma, 2, 6, "px" );
	gdBlockMatching.addNumericField( "maximal_local_displacement (absolute):", bmMaxLocalEpsilon, 2, 6, "px" );
	gdBlockMatching.addNumericField( "maximal_local_displacement (relative):", bmMaxLocalTrust, 2 );

	gdBlockMatching.addMessage( "Montage :" );
	gdBlockMatching.addCheckbox( "tiles_are_pre-montaged", isAligned );

	gdBlockMatching.showDialog();

	if ( gdBlockMatching.wasCanceled() )
		return false;

	bmScale = gdBlockMatching.getNextNumber();
	bmSearchRadius = ( int )gdBlockMatching.getNextNumber();
	bmBlockRadius = ( int )gdBlockMatching.getNextNumber();
	bmMinR = ( float )gdBlockMatching.getNextNumber();
	bmMaxCurvatureR = ( float )gdBlockMatching.getNextNumber();
	bmRodR = ( float )gdBlockMatching.getNextNumber();

	bmUseLocalSmoothnessFilter = gdBlockMatching.getNextBoolean();
	bmLocalModelIndex = gdBlockMatching.getNextChoiceIndex();
	bmLocalRegionSigma = ( float )gdBlockMatching.getNextNumber();
	bmMaxLocalEpsilon = ( float )gdBlockMatching.getNextNumber();
	bmMaxLocalTrust = ( float )gdBlockMatching.getNextNumber();

	isAligned = gdBlockMatching.getNextBoolean();


	final GenericDialog gdSpringMesh = new GenericDialog( "Elastic montage: Spring Meshes" );

	/* TODO suggest a resolution that matches maxEpsilon */
	gdSpringMesh.addNumericField( "spring_length :", springLengthSpringMesh, 2, 6, "px" );
	gdSpringMesh.addNumericField( "stiffness :", stiffnessSpringMesh, 2 );
	gdSpringMesh.addNumericField( "maximal_stretch :", maxStretchSpringMesh, 2, 6, "px" );
	gdSpringMesh.addNumericField( "maximal_iterations :", maxIterationsSpringMesh, 0 );
	gdSpringMesh.addNumericField( "maximal_plateauwidth :", maxPlateauwidthSpringMesh, 0 );
	gdSpringMesh.addCheckbox( "use_legacy_optimizer :", useLegacyOptimizer );


	gdSpringMesh.showDialog();

	if ( gdSpringMesh.wasCanceled() )
		return false;

	springLengthSpringMesh = gdSpringMesh.getNextNumber();
	stiffnessSpringMesh = gdSpringMesh.getNextNumber();
	maxStretchSpringMesh = gdSpringMesh.getNextNumber();
	maxIterationsSpringMesh = ( int )gdSpringMesh.getNextNumber();
	maxPlateauwidthSpringMesh = ( int )gdSpringMesh.getNextNumber();
	useLegacyOptimizer = gdSpringMesh.getNextBoolean();

	if ( isAligned )
		po.desiredModelIndex = 3;
	else
	{
		if ( !po.setup( "Elastic montage : SIFT based pre-montage" ) )
			return false;

		final GenericDialog gdSIFT = new GenericDialog( "Elastic montage : SIFT based pre-montage: Miscellaneous" );
		gdSIFT.addCheckbox( "tiles_are_roughly_in_place", tilesAreInPlace );
		gdSIFT.showDialog();
		if ( gdSIFT.wasCanceled() )
			return false;

		tilesAreInPlace = gdSIFT.getNextBoolean();
	}

	return true;
}
 
Example 20
Source File: ImposeMinAndMax3DPlugin.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( "Impose Min and Max 3D", "ERROR: detected ImageJ version " + IJ.getVersion()  
				+ ".\nThis plugin requires version 1.48a or superior, please update ImageJ!" );
		return;
	}
	
	// Open a dialog to choose:
	// - mask image
	// - marker image
	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("Impose Min & Max 3D");
	
	gd.addChoice("Original Image", imageNames, IJ.getImage().getTitle());
	gd.addChoice("Marker Image", imageNames, IJ.getImage().getTitle());
	gd.addChoice("Operation", 
			Operation.getAllLabels(), 
			Operation.IMPOSE_MINIMA.label);
	gd.addChoice("Connectivity", connectivityLabels, connectivityLabels[0]);
	gd.showDialog();
	
	if (gd.wasCanceled())
		return;

	// set up current parameters
	int refImageIndex = gd.getNextChoiceIndex();
	ImagePlus refImage = WindowManager.getImage(refImageIndex + 1);
	int markerImageIndex = gd.getNextChoiceIndex();
	ImagePlus markerImage = WindowManager.getImage(markerImageIndex + 1);
	Operation op = Operation.fromLabel(gd.getNextChoice());
	int conn = connectivityValues[gd.getNextChoiceIndex()];
	
	// Extract image processors
	ImageStack refStack = refImage.getStack();
	ImageStack markerStack = markerImage.getStack();
	
	long t0 = System.currentTimeMillis();
	
	// Compute geodesic reconstruction
	ImageStack recProc = op.applyTo(refStack, markerStack, conn);
	
	// Keep same color model as 
	recProc.setColorModel(refStack.getColorModel());

	// create resulting image
	String newName = createResultImageName(refImage);
	ImagePlus resultImage = new ImagePlus(newName, recProc);
	resultImage.copyScale(markerImage);
	resultImage.show();
	resultImage.setSlice(refImage.getCurrentSlice());

	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime(op.toString(), t1 - t0, refImage);
}