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

The following examples show how to use ij.gui.GenericDialog#getNextChoiceIndex() . 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: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 6 votes vote down vote up
private void setPreferences() {
	final GenericDialog gd = new GenericDialog("Preferences");
	gd.addChoice("Secondary style color:", Colors.colors, dColor2);
	gd.setInsets(0, 0, 0);
	gd.addMessage("(Used by styles 'box', 'circle', 'connected', etc.)");
	gd.setInsets(30, 0, 0);
	gd.addMessage("After plotting a series:");
	gd.setInsets(0, 20, 0);
	gd.addCheckbox("Auto-select_next_Y-values", autoNextValues);
	gd.addCheckbox("Auto-select_next_shape", autoNextShape);
	gd.addCheckbox("Auto-select_next_color", autoNextColor);
	showAsSubDialog(gd);
	if (gd.wasOKed()) {
		dColor2 = Colors.colors[gd.getNextChoiceIndex()];
		autoNextValues = gd.getNextBoolean();
		autoNextShape = gd.getNextBoolean();
		autoNextColor = gd.getNextBoolean();
	}
}
 
Example 2
Source File: GenericLoadParseQueryXML.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Querys a single element from the list
 * 
 * @param name - type of elements (e.g. "Timepoint")
 * @param list - list of available elements
 * @param defaultSelection - default selection
 * @return the selection or -1 if cancelled
 */
public static int queryIndividualEntry( final String name, final String[] list, int defaultSelection )
{
	if ( defaultSelection >= list.length )
		defaultSelection = 0;

	final GenericDialog gd = new GenericDialog( "Select Single " + name );
	gd.addChoice( "Processing_" + name, list, list[ defaultSelection ] );
	
	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return -1;
	
	return gd.getNextChoiceIndex();
}
 
Example 3
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 4
Source File: Align.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean readRegularizationFields( final GenericDialog gd )
{
	regularizerModelIndex = gd.getNextChoiceIndex();
	lambda = gd.getNextNumber();

	return !gd.invalidNumber();
}
 
Example 5
Source File: EquivalentEllipsePlugin.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("Equivalent Ellipse");
	gd.addChoice("Label Image:", imageNames, selectedImageName);
	gd.addCheckbox("Overlay Ellipse", true);
	gd.addCheckbox("Overlay Axes", 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 showEllipse = gd.getNextBoolean();
	boolean showAxes = 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
	EquivalentEllipse op = new EquivalentEllipse();
	Map<Integer, Ellipse> ellipses = op.analyzeRegions(labelImage);
       ResultsTable results = op.createTable(ellipses);
       
	// show result
   	String tableName = labelImage.getShortTitle() + "-Ellipses"; 
   	results.show(tableName);
   	
	// Check if results must be displayed on an image
	if (showEllipse || showAxes)
	{
		// find image for displaying geometric overlays
		ImagePlus resultImage = WindowManager.getImage(resultImageIndex + 1);
		showResultsAsOverlay(ellipses, resultImage, showEllipse, showAxes);
	}
   }
 
Example 6
Source File: Define_Bounding_Box.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public BoundingBox defineBoundingBox(
		final SpimData2 data,
		final List< ViewId > viewIds,
		final String clusterExtension,
		final String xmlFileName,
		final boolean saveXML )
{
	final String[] boundingBoxDescriptions = new String[ staticBoundingBoxAlgorithms.size() ];

	for ( int i = 0; i < staticBoundingBoxAlgorithms.size(); ++i )
		boundingBoxDescriptions[ i ] = staticBoundingBoxAlgorithms.get( i ).getDescription();

	if ( defaultBoundingBoxAlgorithm >= boundingBoxDescriptions.length )
		defaultBoundingBoxAlgorithm = 0;

	final GenericDialog gd = new GenericDialog( "Image Fusion" );

	gd.addChoice( "Bounding_Box", boundingBoxDescriptions, boundingBoxDescriptions[ defaultBoundingBoxAlgorithm ] );
	gd.addStringField( "Bounding_Box_Name", defaultName, 30 );

	// assemble the last registration names of all viewsetups involved
	final HashMap< String, Integer > names = GUIHelper.assembleRegistrationNames( data, viewIds );
	gd.addMessage( "" );
	GUIHelper.displayRegistrationNames( gd, names );
	gd.addMessage( "" );

	GUIHelper.addWebsite( gd );

	if ( names.keySet().size() > 5 )
		GUIHelper.addScrollBars( gd );
	
	gd.showDialog();

	if ( gd.wasCanceled() )
		return null;

	final int boundingBoxAlgorithm = defaultBoundingBoxAlgorithm = gd.getNextChoiceIndex();
	final String boundingBoxName = gd.getNextString();

	for ( final BoundingBox bb : data.getBoundingBoxes().getBoundingBoxes() )
	{
		if ( bb.getTitle().equals( boundingBoxName ) )
		{
			IOFunctions.println( "A bounding box with the name '" + boundingBoxName + "' already exists." );
			defaultName = boundingBoxName + "1";
			return null;
		}
	}

	final BoundingBoxGUI boundingBox = staticBoundingBoxAlgorithms.get( boundingBoxAlgorithm ).newInstance( data, viewIds );

	if ( !boundingBox.queryParameters( null, null ) )
		return null;

	boundingBox.setTitle( boundingBoxName );
	defaultName = boundingBoxName + "1";

	data.getBoundingBoxes().addBoundingBox( boundingBox );

	if ( saveXML )
		SpimData2.saveXML( data, xmlFileName, clusterExtension );

	return boundingBox;
}
 
Example 7
Source File: Compare.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public boolean setup(final boolean to_file, final String regex, final boolean plot, final boolean condense) {
	final GenericDialog gd = new GenericDialog("All to all");
	gd.addMessage("Choose a point interdistance to resample to, or 0 for the average of all.");
	gd.addNumericField("point_interdistance: ", delta, 2);
	gd.addCheckbox("skip insertion/deletion strings at ends when scoring", skip_ends);
	gd.addNumericField("maximum_ignorable consecutive muts in endings: ", max_mut, 0);
	gd.addNumericField("minimum_percentage that must remain: ", min_chunk, 2);
	gd.addCheckbox("Score mutations only", score_mut_only);
	Utils.addEnablerListener((Checkbox)gd.getCheckboxes().get(0), new Component[]{(Component)gd.getNumericFields().get(0), (Component)gd.getNumericFields().get(1)}, null);

	final String[] transforms = {"translate and rotate",
				     "translate, rotate and scale",
				     "translate, rotate, scale and shear",
				     "moving least squares",
				     "relative",
				     "direct"};
	gd.addChoice("Transform_type: ", transforms, transforms[transform_type]);
	gd.addCheckbox("Chain_branches", chain_branches);

	gd.addChoice("Presets: ", preset_names, preset_names[0]);
	gd.addMessage("");
	gd.addChoice("Scoring type: ", distance_types, distance_types[distance_type]);
	final String[] distance_types2 = {"Levenshtein", "Dissimilarity", "Average physical distance", "Median physical distance", "Cummulative physical distance", "Standard deviation", "Combined SLM", "Proximity", "Proximity of mutation pairs", "None"}; // CAREFUL when adding more entries: index 9 is used as None for sortMatches and as a conditional.
	gd.addChoice("Resort scores by: ", distance_types2, distance_types2[distance_type_2]);
	gd.addNumericField("Min_matches: ", min_matches, 0);
	if (to_file) {
		gd.addChoice("File format: ", formats, formats[2]);
	}
	gd.addCheckbox("normalize", normalize);
	gd.addCheckbox("direct", direct);
	gd.addCheckbox("substring_matching", substring_matching);
	gd.addStringField("regex: ", null != regex ? regex : "");
	if (plot) {
		gd.addNumericField("plot_width: ", plot_width, 0);
		gd.addNumericField("plot_height: ", plot_height, 0);
		gd.addNumericField("plot_max_x: ", plot_max_x, 2);
		gd.addNumericField("plot_max_y: ", plot_max_y, 2);
	}
	if (condense) {
		gd.addCheckbox("cut_uneven_ends", cut_uneven_ends);
		final String[] env = {"1 std dev", "2 std dev", "3 std dev", "average", "maximum"};
		gd.addChoice("envelope", env, env[envelope_type]);
		gd.addNumericField("delta envelope:", delta_envelope, 1);
	}

	//////

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

	delta = gd.getNextNumber();
	skip_ends = gd.getNextBoolean();
	max_mut = (int)gd.getNextNumber();
	min_chunk = (float)gd.getNextNumber();
	score_mut_only = gd.getNextBoolean();
	if (skip_ends) {
		if (max_mut < 0) max_mut = 0;
		if (min_chunk <= 0) skip_ends = false;
		if (min_chunk > 1) min_chunk = 1;
	}
	transform_type = gd.getNextChoiceIndex();
	chain_branches = gd.getNextBoolean();
	preset = presets[gd.getNextChoiceIndex()];

	distance_type = gd.getNextChoiceIndex();
	distance_type_2 = gd.getNextChoiceIndex();
	min_matches = (int) gd.getNextNumber();
	if (min_matches < 0) {
		Utils.log("Using 0 min_matches!");
		min_matches = 0;
	}

	format = formats[0];
	if (to_file) format = gd.getNextChoice().trim();

	normalize = gd.getNextBoolean();
	direct = gd.getNextBoolean();
	substring_matching = gd.getNextBoolean();

	this.regex = gd.getNextString().trim();
	if (0 == this.regex.length()) this.regex = null;

	if (plot) {
		plot_width = (int)gd.getNextNumber();
		plot_height = (int)gd.getNextNumber();
		plot_max_x = gd.getNextNumber();
		plot_max_y = gd.getNextNumber();
	}
	if (condense) {
		cut_uneven_ends = gd.getNextBoolean();
		envelope_type = gd.getNextChoiceIndex();
		delta_envelope = gd.getNextNumber();
		Utils.log2("delta_envelope has been set to " + delta_envelope);
	}

	return true;
}
 
Example 8
Source File: InertiaEllipsePlugin.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("Inertia Ellipse");
	gd.addChoice("Label Image:", imageNames, selectedImageName);
	gd.addCheckbox("Overlay Ellipse", true);
	gd.addCheckbox("Overlay Axes", 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 showEllipse = gd.getNextBoolean();
	boolean showAxes = 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
	InertiaEllipse op = new InertiaEllipse();
	Map<Integer, Ellipse> ellipses = op.analyzeRegions(labelImage);
       ResultsTable results = op.createTable(ellipses);
       
	// show result
   	String tableName = labelImage.getShortTitle() + "-Ellipses"; 
   	results.show(tableName);
   	
	// Check if results must be displayed on an image
	if (showEllipse || showAxes)
	{
		// find image for displaying geometric overlays
		ImagePlus resultImage = WindowManager.getImage(resultImageIndex + 1);
		showResultsAsOverlay(ellipses, resultImage, showEllipse, showAxes);
	}
   }
 
Example 9
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 10
Source File: AnalyzeMicrostructure3D.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();
    
    if (imagePlus.getStackSize() == 1) 
    {
        IJ.error("Requires a Stack");
        return;
    }
    
    // create the dialog, with operator options
    GenericDialog gd = new GenericDialog("Microstructure Analysis");
    gd.addCheckbox("Volume", true);
    gd.addCheckbox("Surface Area", true);
    gd.addCheckbox("Mean_Breadth", true);
    gd.addCheckbox("Euler Number", true);
    gd.addMessage("");
    gd.addChoice("Surface area method:", dirNumberLabels, dirNumberLabels[1]);
    gd.addChoice("Mean breadth method:", dirNumberLabels, dirNumberLabels[1]);
    gd.addChoice("Mean Breadth Conn.:", connectivity2dNames, connectivity2dNames[1]);
    gd.addChoice("Euler Connectivity:", connectivity3dNames, connectivity3dNames[1]);
    gd.showDialog();
    
    // If cancel was clicked, do nothing
    if (gd.wasCanceled())
        return;

    // Extract features to extract from image
    computeVolume       = gd.getNextBoolean();
    computeSurface      = gd.getNextBoolean();
    computeMeanBreadth  = gd.getNextBoolean();
    computeEulerNumber  = gd.getNextBoolean();
    
    // extract analysis options
    surfaceAreaDirs = dirNumbers[gd.getNextChoiceIndex()];
    meanBreadthDirs = dirNumbers[gd.getNextChoiceIndex()];
    connectivity2d = connectivity2dValues[gd.getNextChoiceIndex()];
    connectivity = connectivity3dValues[gd.getNextChoiceIndex()];
    
    // Execute the plugin
    ResultsTable table = process(imagePlus);
    
    // create string for indexing results
    String tableName = imagePlus.getShortTitle() + "-microstructure"; 

    // show result
    table.show(tableName);
}
 
Example 11
Source File: RegionAdjacencyGraphPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run(String arg0)
{
	ImagePlus imagePlus = IJ.getImage();
	
	boolean isPlanar = imagePlus.getStackSize() == 1;
	boolean showRAG = false;
	ImagePlus targetPlus = imagePlus;

	if (isPlanar)
	{
		// create the list of image names
		int[] indices = WindowManager.getIDList();
		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();

		GenericDialog gd = new GenericDialog("Region Adjacency Graph");
		gd.addCheckbox("Show RAG", true);
		gd.addChoice("Image to overlay", imageNames, selectedImageName);
		
		gd.showDialog();
		if (gd.wasCanceled())
		{
			return;
		}
		
		showRAG = gd.getNextBoolean();
		int targetImageIndex = gd.getNextChoiceIndex();
		targetPlus = WindowManager.getImage(indices[targetImageIndex]);
	}

	Set<LabelPair> adjList = RegionAdjacencyGraph.computeAdjacencies(imagePlus);
	
	if (showRAG)
	{
		overlayRAG(adjList, imagePlus, targetPlus);
	}
	
	ResultsTable table = createTable(adjList);
	String newName = imagePlus.getShortTitle() + "-RAG";
	table.show(newName);
}
 
Example 12
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);
		}
	}
 
Example 13
Source File: ParticleAnalysis3DPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void run(String args) 
  {
      ImagePlus imagePlus = IJ.getImage();
      
if (imagePlus.getStackSize() == 1) 
{
	IJ.error("Requires a Stack");
	return;
}

      // create the dialog, with operator options
      GenericDialog gd = new GenericDialog("Particles Analysis 3D");
      gd.addCheckbox("Volume", true);
      gd.addCheckbox("Surface Area", true);
      gd.addCheckbox("Sphericity", true);
      gd.addCheckbox("Euler Number", true);
      gd.addCheckbox("Equivalent Ellipsoid", true);
      gd.addCheckbox("Ellipsoid Elongation", true);
      gd.addCheckbox("Max. Inscribed Ball", true);
      gd.addMessage("");
      gd.addChoice("Surface area method:", surfaceAreaMethods, surfaceAreaMethods[1]);
      gd.addChoice("Euler Connectivity:", connectivityNames, connectivityNames[1]);
      gd.showDialog();
      
      // If cancel was clicked, do nothing
      if (gd.wasCanceled())
          return;

      // Extract features to extract from image
      computeVolume 		= gd.getNextBoolean();
      computeSurface 		= gd.getNextBoolean();
      computeSphericity 	= gd.getNextBoolean() & computeVolume & computeSurface;
      computeEulerNumber	= gd.getNextBoolean();
      computeEllipsoid 	= gd.getNextBoolean();
      computeElongations 	= gd.getNextBoolean() & computeEllipsoid;
      computeInscribedBall = gd.getNextBoolean();
      
      
      // extract analysis options
      surfaceAreaDirs = dirNumbers[gd.getNextChoiceIndex()];
      connectivity = connectivityValues[gd.getNextChoiceIndex()];
      
      // Execute the plugin
      ResultsTable table = process(imagePlus);
      
	// create string for indexing results
String tableName = imagePlus.getShortTitle() + "-morpho"; 
  
// show result
table.show(tableName);
  }
 
Example 14
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 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: MorphologicalReconstructionPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run(String arg) 
{
	// 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("Morphological Reconstruction");
	
	gd.addChoice("Marker Image", imageNames, IJ.getImage().getTitle());
	gd.addChoice("Mask Image", imageNames, IJ.getImage().getTitle());
	gd.addChoice("Type of Reconstruction", 
			Operation.getAllLabels(),
			Operation.BY_DILATION.label);
	gd.addChoice("Connectivity", 
			Conn2D.getAllLabels(), 
			Conn2D.C4.label);
	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);
	Operation op = Operation.fromLabel(gd.getNextChoice());
	int conn = Conn2D.fromLabel(gd.getNextChoice()).getValue();
	
	// Extract image procesors
	ImageProcessor markerProc = markerImage.getProcessor();
	ImageProcessor maskProc = maskImage.getProcessor();
	
	long t0 = System.currentTimeMillis();
	
	// Compute geodesic reconstruction
	ImageProcessor recProc = op.applyTo(markerProc, maskProc, conn);
	
	// Keep same color model
	recProc.setColorModel(maskProc.getColorModel());

	// create resulting image
	String newName = createResultImageName(markerImage);
	ImagePlus resultImage = new ImagePlus(newName, recProc);
	resultImage.copyScale(maskImage);
	resultImage.show();
	
	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime(op.toString(), t1 - t0, markerImage);
}
 
Example 17
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 18
Source File: ICP_Refine.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run(String arg)
{
	final LoadParseQueryXML result = new LoadParseQueryXML();
	if ( !result.queryXML( "for ICP refinement", true, true, true, true, true ) )
		return;

	final SpimData2 data = result.getData();
	ArrayList< ViewId > selectedViews = SpimData2.getAllViewIdsSorted( result.getData(), result.getViewSetupsToProcess(), result.getTimePointsToProcess() );

	final ICPRefinementParameters params = ICPRefinement.initICPRefinement( data, selectedViews.stream().map( vid -> data.getSequenceDescription().getViewDescription( vid ) ).collect( Collectors.toList() ) );

	if ( params == null )
		return;

	final GenericDialog gd = new GenericDialog( "ICP Refinement" );

	gd.addChoice( "ICP_Refinement_Type", ICPRefinement.refinementType, ICPRefinement.refinementType[ ICPRefinement.defaultRefinementChoice ] );

	gd.addMessage( "" );
	gd.addMessage( "The following parameters are ignored if EXPERT is selected above", GUIHelper.mediumstatusfont );
	gd.addMessage( "" );

	gd.addChoice( "Downsampling", ICPRefinement.downsampling, ICPRefinement.downsampling[ ICPRefinement.defaultDownsamplingChoice ] );
	gd.addChoice( "Interest Point threshold", ICPRefinement.threshold, ICPRefinement.threshold[ ICPRefinement.defaultThresholdChoice ] );
	gd.addChoice( "ICP_Max_Error", ICPRefinement.distance, ICPRefinement.distance[ ICPRefinement.defaultDistanceChoice ] );

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

	final ICPType icpType = ICPType.values()[ ICPRefinement.defaultRefinementChoice = gd.getNextChoiceIndex() ];

	if ( icpType == ICPType.Expert )
	{
		if ( !ICPRefinement.getGUIParametersAdvanced( data, params ) )
			return;
	}
	else
	{
		final int downsamplingChoice = ICPRefinement.defaultDownsamplingChoice = gd.getNextChoiceIndex();
		final int thresholdChoice = ICPRefinement.defaultThresholdChoice = gd.getNextChoiceIndex();
		final int distanceChoice = ICPRefinement.defaultDistanceChoice = gd.getNextChoiceIndex();

		if ( !ICPRefinement.getGUIParametersSimple( icpType, data, params, downsamplingChoice, thresholdChoice, distanceChoice ) )
			return;
	}

	ICPRefinement.refine( data, params, null );

	SpimData2.saveXML( data, result.getXMLFileName(), result.getClusterExtension() );

}
 
Example 19
Source File: Fast_Translation_Fusion.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static FastFusionParameters queryParameters(final SpimData2 spimData, final List< ViewId > viewsToProcess)
{
	// get view descriptions for all present views
	final List< ViewDescription > presentViewDescriptions = viewsToProcess.stream()
			.filter( v -> spimData.getSequenceDescription().getViewDescription( v ).isPresent() )
			.map( v -> spimData.getSequenceDescription().getViewDescription( v ) ).collect( Collectors.toList() );

	// get registrations and corresponding affine transforms for all present
	final List< ViewRegistration > registrations = presentViewDescriptions.stream()
			.map( v -> spimData.getViewRegistrations().getViewRegistration( v ) ).collect( Collectors.toList() );

	final boolean allNonTranslationsEqual = checkTranslationOnly( registrations );

	// TODO: use subclassed FusionGUI here? -> that way, we could use exporters
	final GenericDialog gd = new GenericDialog( "Fast Fusion Options" );

	// warn when not allNonTranslationsEqual
	if ( !allNonTranslationsEqual )
		gd.addMessage(
				"WARNING: View Registrations differ in more than just Translation, the fast fusion will not be exact"
						+ ", consider using the normal fusion",
				GUIHelper.mediumstatusfont, GUIHelper.warning );

	// query downsampling, datatype, blending, interpolation
	gd.addChoice( "Downsampling", dsChoices, dsChoices[defaultDsChoice] );
	gd.addCheckbox( "Use_Linear_Interpolation", defaultUseInterpolation );
	gd.addCheckbox( "Use_Blending", defaultUseBlending );
	gd.addChoice( "Output_Data_Type", dtypeChoices, dtypeChoices[defaultDtypeChoice] );

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

	final FastFusionParameters params = new FastFusionParameters();

	defaultDsChoice = gd.getNextChoiceIndex();
	params.downsampling = Integer.parseInt( dsChoices[defaultDsChoice] );
	params.useLinearInterpolation = defaultUseInterpolation = gd.getNextBoolean();
	params.useBlending = gd.getNextBoolean();
	defaultDtypeChoice = gd.getNextChoiceIndex();
	params.dataType = FastFusionDataType.values()[defaultDtypeChoice];

	return params;
}
 
Example 20
Source File: DifferenceOfGaussian.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected boolean queryAdditionalParameters( final GenericDialog gd )
{
	final int computationTypeIndex = defaultComputationChoiceIndex = gd.getNextChoiceIndex();

	if ( computationTypeIndex == 1 )
		accurateCUDA = false;
	else
		accurateCUDA = true;

	if ( computationTypeIndex >= 1 )
	{
		final ArrayList< String > potentialNames = new ArrayList< String >();
		potentialNames.add( "separable" );
		
		cuda = NativeLibraryTools.loadNativeLibrary( potentialNames, CUDASeparableConvolution.class );

		if ( cuda == null )
		{
			IOFunctions.println( "Cannot load CUDA JNA library." );
			deviceList = null;
			return false;
		}
		else
		{
			deviceList = new ArrayList< CUDADevice >();
		}

		// multiple CUDA devices sometimes crashes, no idea why yet ...
		final ArrayList< CUDADevice > selectedDevices = CUDATools.queryCUDADetails( cuda, false, this );

		if ( selectedDevices == null || selectedDevices.size() == 0 )
			return false;
		else
			deviceList.addAll( selectedDevices );

		// TODO: remove this, only for debug on non-CUDA machines >>>>
		if ( deviceList.get( 0 ).getDeviceName().startsWith( "CPU emulation" ) )
		{
			for ( int i = 0; i < deviceList.size(); ++i )
			{
				deviceList.set( i, new CUDADevice( -1-i, deviceList.get( i ).getDeviceName(), deviceList.get( i ).getTotalDeviceMemory(), deviceList.get( i ).getFreeDeviceMemory(), deviceList.get( i ).getMajorComputeVersion(), deviceList.get( i ).getMinorComputeVersion() ) );
				IOFunctions.println( "Running on cpu emulation, added " + ( -1-i ) + " as device" );
			}
		}
		// TODO: <<<< remove this, only for debug on non-CUDA machines
	}
	else
	{
		deviceList = null;
	}

	return true;
}