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

The following examples show how to use ij.gui.GenericDialog#addCheckbox() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetLabelMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
public GenericDialog showDialog()
{

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

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

	return gd;
}
 
Example 2
Source File: EfficientBayesianBased.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void queryAdditionalParameters( final GenericDialog gd )
{
	gd.addChoice( "ImgLib2_container_FFTs", BoundingBoxGUI.imgTypes, BoundingBoxGUI.imgTypes[ defaultFFTImgType ] );
	gd.addCheckbox( "Save_memory (not keep FFT's on CPU, 2x time & 0.5x memory)", defaultSaveMemory );
	saveMem = (Checkbox)gd.getCheckboxes().lastElement();
	gd.addChoice( "Type_of_iteration", iterationTypeString, iterationTypeString[ defaultIterationType ] );
	it = (Choice)gd.getChoices().lastElement();
	gd.addChoice( "Image_weights", weightsString, weightsString[ defaultWeightType ] );
	weight = (Choice)gd.getChoices().lastElement();
	gd.addChoice( "OSEM_acceleration", osemspeedupChoice, osemspeedupChoice[ defaultOSEMspeedupIndex ] );
	gd.addNumericField( "Number_of_iterations", defaultNumIterations, 0 );
	gd.addCheckbox( "Debug_mode", defaultDebugMode );
	gd.addCheckbox( "Adjust_blending_parameters (if stripes are visible)", defaultAdjustBlending );
	gd.addCheckbox( "Use_Tikhonov_regularization", defaultUseTikhonovRegularization );
	gd.addNumericField( "Tikhonov_parameter", defaultLambda, 4 );
	gd.addChoice( "Compute", blocksChoice, blocksChoice[ defaultBlockSizeIndex ] );
	block = (Choice)gd.getChoices().lastElement();
	gd.addChoice( "Compute_on", computationOnChoice, computationOnChoice[ defaultComputationTypeIndex ] );
	gpu = (Choice)gd.getChoices().lastElement();
	gd.addChoice( "PSF_estimation", extractPSFChoice, extractPSFChoice[ defaultExtractPSF ] );
	gd.addChoice( "PSF_display", displayPSFChoice, displayPSFChoice[ defaultDisplayPSF ] );
}
 
Example 3
Source File: GeometricHashing.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addQuery( final GenericDialog gd, final RegistrationType registrationType )
{
	gd.addChoice( "Transformation model", TransformationModel.modelChoice, TransformationModel.modelChoice[ defaultModel ] );
	gd.addCheckbox( "Regularize_model", defaultRegularize );
	gd.addSlider( "Allowed_error_for_RANSAC (px)", 0.5, 20.0, RANSACParameters.max_epsilon );
	gd.addSlider( "Significance required for a descriptor match", 1.0, 20.0, GeometricHashingParameters.ratioOfDistance );
}
 
Example 4
Source File: BinaryOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public int showDialog (ImagePlus imp, String command, PlugInFilterRunner pfr) {
	if (doOptions) {
		this.imp = imp;
		this.pfr = pfr;
		GenericDialog gd = new GenericDialog("Binary Options");
		gd.addNumericField("Iterations (1-"+MAX_ITERATIONS+"):", iterations, 0, 3, "");
		gd.addNumericField("Count (1-8):", count, 0, 3, "");
		gd.addCheckbox("Black background", Prefs.blackBackground);
		gd.addCheckbox("Pad edges when eroding", Prefs.padEdges);
		gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]);
		if (imp != null) {
			gd.addChoice("Do:", operations, operation);
			gd.addPreviewCheckbox(pfr);
			gd.addDialogListener(this);
			previewing = true;
		}
		gd.addHelp(IJ.URL+"/docs/menus/process.html#options");
		gd.showDialog();
		previewing = false;
		if (gd.wasCanceled()) return DONE;
		if (imp==null) {                 //options dialog only, no do/preview
			dialogItemChanged(gd, null); //read dialog result
			return DONE;
		}
		return operation.equals(NO_OPERATION) ? DONE : IJ.setupDialog(imp, flags);
	} else {   //no dialog, 'arg' is operation type
		if (!imp.getProcessor().isBinary()) {
			IJ.error("8-bit binary (black and white only) image required.");
			return DONE;
		}
		return IJ.setupDialog(imp, flags);
	}
}
 
Example 5
Source File: FlipAxesCommand.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run()
{
	// load SpimData
	final LoadParseQueryXML result = new LoadParseQueryXML();
	if ( !result.queryXML( "to load a TileConfiguration for", false, false, false, false, false ) )
		return;
	final SpimData2 data = result.getData();
	final ArrayList< ViewId > views = SpimData2.getAllViewIdsSorted( result.getData(),
			result.getViewSetupsToProcess(), result.getTimePointsToProcess() );

	final Map< ViewId, Dimensions > dims = new HashMap<>();
	views.forEach( v -> dims.put( v,
			data.getSequenceDescription().getViewDescriptions().get( v ).getViewSetup().getSize() ) );
	final boolean[] flipAxes = new boolean[3];
	GenericDialog gd = new GenericDialog( "Flip Parameters" );
	gd.addCheckbox( "Flip_X", true );
	gd.addCheckbox( "Flip_Y", false );
	gd.addCheckbox( "Flip_Z", false );

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

	flipAxes[0] = gd.getNextBoolean();
	flipAxes[1] = gd.getNextBoolean();
	flipAxes[2] = gd.getNextBoolean();

	FlipAxes.applyFlipToData( data.getViewRegistrations(), dims, views, flipAxes );

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

}
 
Example 6
Source File: RGLDM.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addQuery( final GenericDialog gd, final RegistrationType registrationType )
{
	gd.addChoice( "Transformation model", TransformationModel.modelChoice, TransformationModel.modelChoice[ defaultModel ] );
	gd.addCheckbox( "Regularize_model", defaultRegularize );
	gd.addSlider( "Number_of_neighbors for the descriptors", 3, 10, RGLDMParameters.numNeighbors );
	gd.addSlider( "Redundancy for descriptor matching", 0, 10, RGLDMParameters.redundancy );		
	gd.addSlider( "Significance required for a descriptor match", 1.0, 10.0, RGLDMParameters.ratioOfDistance );
	gd.addSlider( "Allowed_error_for_RANSAC (px)", 0.5, 20.0, RANSACParameters.max_epsilon );
}
 
Example 7
Source File: AreaList.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 AreaLists", 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 : this.layer_set.getZDisplayables()) {
			if (zd.getClass() == AreaList.class) {
				final AreaList ali = (AreaList)zd;
				ali.fill_paint = fp;
				ali.updateInDatabase("fill_paint");
				Display.repaint(this.layer_set, ali, 2);
			}
		}
	} else {
		if (this.fill_paint != fp) {
			prev.add("fill_paint", fp);
			this.fill_paint = fp;
			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: GlobalOptimizationParameters.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static GlobalOptimizationParameters askUserForParameters(boolean askForGrouping)
{
	// ask user for parameters
	final GenericDialog gd = new GenericDialog("Global optimization options");
	gd.addChoice( "Global_optimization_strategy", methodDescriptions, methodDescriptions[ defaultGlobalOpt ] );
	gd.addNumericField( "relative error threshold", 2.5, 3 );
	gd.addNumericField( "absolute error threshold", 3.5, 3 );
	if (askForGrouping )
		gd.addCheckbox( "show_expert_grouping_options", defaultExpertGrouping );
	gd.showDialog();

	if (gd.wasCanceled())
		return null;

	final double relTh = gd.getNextNumber();
	final double absTh = gd.getNextNumber();
	final int methodIdx = defaultGlobalOpt = gd.getNextChoiceIndex();
	final boolean expertGrouping = askForGrouping ? gd.getNextBoolean() : false;

	final GlobalOptType method;
	if (methodIdx == 0)
		method = GlobalOptType.SIMPLE;
	else if (methodIdx == 1)
		method = GlobalOptType.ITERATIVE;
	else
		method = GlobalOptType.TWO_ROUND;

	return new GlobalOptimizationParameters(relTh, absTh, method, expertGrouping);
}
 
Example 9
Source File: WeightedAverageFusion.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void queryAdditionalParameters( final GenericDialog gd )
{
	if ( Fusion.defaultInterpolation >= Fusion.interpolationTypes.length )
		Fusion.defaultInterpolation = Fusion.interpolationTypes.length - 1;
	
	if ( this.getFusionType() == WeightedAvgFusionType.FUSEDATA )
	{
		int maxViews = 0;
		
		for ( final TimePoint t : timepointsToProcess )
			for ( final Channel c : channelsToProcess )
				maxViews = Math.max( maxViews, FusionHelper.assembleInputData( spimData, t, c, viewIdsToProcess ).size() );
		
		// any choice but all views
		final String[] views = new String[ maxViews ];
		
		views[ 0 ] = "All";
		
		for ( int i = 1; i < views.length; ++i )
			views[ i ] = "" + i;
		
		if ( defaultNumParalellViewsIndex < 0 || defaultNumParalellViewsIndex >= views.length )
			defaultNumParalellViewsIndex = 0;
		
		gd.addChoice( "Process_views_in_paralell", views, views[ defaultNumParalellViewsIndex ] );
		this.sequentialViews = (Choice)gd.getChoices().lastElement();
	}
	
	if ( this.getFusionType() == WeightedAvgFusionType.FUSEDATA )
	{
		gd.addCheckbox( "Blend images smoothly", Fusion.defaultUseBlending );
		gd.addCheckbox( "Content-based fusion", Fusion.defaultUseContentBased );
	}
	gd.addChoice( "Interpolation", Fusion.interpolationTypes, Fusion.interpolationTypes[ Fusion.defaultInterpolation ] );
}
 
Example 10
Source File: ExportToRenderAsIs_Plugin.java    From render with GNU General Public License v2.0 5 votes vote down vote up
boolean setParametersFromDialog() {

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

            final int defaultTextColumns = 100;
            dialog.addStringField("Render Web Services Base URL", baseDataUrl, defaultTextColumns);
            layerRange.addFieldsToDialog(dialog);
            dialog.addCheckbox("Only Export Visible Patches", onlyExportVisiblePatches);
            dialog.addCheckbox("Use Patch Title For Tile ID", usePatchTitleForTileId);
            dialog.addMessage("  note: leave unchecked to use TrakEM2 patch object ID as tile ID");
            dialog.addStringField("Target Render Stack Owner", targetRenderOwner, defaultTextColumns);
            dialog.addStringField("Target Render Stack Project", targetRenderProject, defaultTextColumns);
            dialog.addStringField("Target Render Stack Name", targetRenderStack, defaultTextColumns);
            dialog.addNumericField("Stack Resolution X (nm/pixel)", stackResolutionX, 0);
            dialog.addNumericField("Stack Resolution Y (nm/pixel)", stackResolutionY, 0);
            dialog.addNumericField("Stack Resolution Z (nm/pixel)", stackResolutionZ, 0);
            dialog.addCheckbox("Complete Stack After Export", completeStackAfterExport);

            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().trim();
                layerRange.setFieldsFromDialog(dialog);
                onlyExportVisiblePatches = dialog.getNextBoolean();
                usePatchTitleForTileId = dialog.getNextBoolean();
                targetRenderOwner = dialog.getNextString().trim();
                targetRenderProject = dialog.getNextString().trim();
                targetRenderStack =  dialog.getNextString().trim();
                stackResolutionX = dialog.getNextNumber();
                stackResolutionY = dialog.getNextNumber();
                stackResolutionZ = dialog.getNextNumber();
                completeStackAfterExport = dialog.getNextBoolean();
            }

            return wasCancelled;
        }
 
Example 11
Source File: StitchingTEM.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns false when canceled.
 * @param ref is an optional Patch from which to estimate an appropriate image scale
 * 			at which to perform the phase correlation, for performance reasons.
 * */
public boolean setup(final Patch ref)
{
	final GenericDialog gd = new GenericDialog("Montage with phase correlation");
	if (overlap < 0) overlap = 0.1f;
	else if (overlap > 1) overlap = 1;
	gd.addSlider("tile_overlap (%): ", 1, 100, overlap * 100);
	int sc = (int)cc_scale * 100;
	if (null != ref) {
		// Estimate scale from ref Patch dimensions
		final int w = ref.getOWidth();
		final int h = ref.getOHeight();
		sc = (int)((512.0 / (w > h ? w : h)) * 100); // guess a scale so that image is 512x512 aprox
	}
	if (sc <= 0) sc = 25;
	else if (sc > 100) sc = 100;
	gd.addSlider("scale (%):", 1, 100, sc);
	gd.addNumericField( "max/avg displacement threshold: ", mean_factor, 2 );
	gd.addNumericField("regression threshold (R):", min_R, 2);
	gd.addCheckbox("hide disconnected", false);
	gd.addCheckbox("remove disconnected", false);
	gd.showDialog();
	if (gd.wasCanceled()) return false;

	overlap = (float)gd.getNextNumber() / 100f;
	cc_scale = gd.getNextNumber() / 100.0;
	mean_factor = gd.getNextNumber();
	min_R = gd.getNextNumber();
	hide_disconnected = gd.getNextBoolean();
	remove_disconnected = gd.getNextBoolean();

	return true;
}
 
Example 12
Source File: OrientedBoundingBoxPlugin.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("Oriented 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
	OrientedBoundingBox2D op = new OrientedBoundingBox2D();
	Map<Integer, OrientedBox2D> boxes = op.analyzeRegions(labelImage);
       ResultsTable results = op.createTable(boxes);
       
	// show result
   	String tableName = labelImage.getShortTitle() + "-OBox"; 
   	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 13
Source File: StackList.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected boolean debugShowFiles()
{
	final GenericDialog gd = new GenericDialog( "3d image stacks files" );

	gd.addMessage( "" );
	gd.addMessage( "Path: " + directory + "   " );
	gd.addMessage( "Note: Not selected files will be treated as missing views (e.g. missing files).", GUIHelper.smallStatusFont );

	for ( int t = 0; t < timepointNameList.size(); ++t )
		for ( int c = 0; c < channelNameList.size(); ++c )
			for ( int i = 0; i < illuminationsNameList.size(); ++i )
				for ( int a = 0; a < angleNameList.size(); ++a )
				{
					String fileName = getFileNameFor( t, c, i, a );
					
					final boolean fileExisits = new File( directory, fileName ).exists();
					
					String ext = "";
					
					if ( hasMultipleChannels > 0 && numDigitsChannels == 0 )
						ext +=  "c = " + channelNameList.get( c );

					if ( hasMultipleTimePoints > 0 && numDigitsTimepoints == 0 )
						if ( ext.length() > 0 )
							ext += ", t = " + timepointNameList.get( t );
						else
							ext += "t = " + timepointNameList.get( t );

					if ( hasMultipleIlluminations > 0 && numDigitsIlluminations == 0 )
						if ( ext.length() > 0 )
							ext += ", i = " + illuminationsNameList.get( i );
						else
							ext += "i = " + illuminationsNameList.get( i );

					if ( hasMultipleAngles > 0 && numDigitsAngles == 0 )
						if ( ext.length() > 0 )
							ext += ", a = " + angleNameList.get( a );
						else
							ext += "a = " + angleNameList.get( a );

					if ( ext.length() > 1 )
						fileName += "   >> [" + ext + "]";

					final boolean select;

					if ( fileExisits )
					{
						fileName += " (file found)";
						select = true;
					}
					else
					{
						select = false;
						fileName += " (file NOT found)";
					}
					
					gd.addCheckbox( fileName, select );
					
					// otherwise underscores are gone ...
					((Checkbox)gd.getCheckboxes().lastElement()).setLabel( fileName );
					if ( !fileExisits )
						((Checkbox)gd.getCheckboxes().lastElement()).setBackground( GUIHelper.error );
				}
			
	GUIHelper.addScrollBars( gd );

	gd.showDialog();

	if ( gd.wasCanceled() )
		return false;

	exceptionIds = new ArrayList<int[]>();

	// collect exceptions to the definitions
	for ( int t = 0; t < timepointNameList.size(); ++t )
		for ( int c = 0; c < channelNameList.size(); ++c )
			for ( int i = 0; i < illuminationsNameList.size(); ++i )
				for ( int a = 0; a < angleNameList.size(); ++a )
					if ( gd.getNextBoolean() == false )
					{
						exceptionIds.add( new int[]{ t, c, i, a } );
						System.out.println( "adding missing views t:" + t + " c:" + c + " i:" + i + " a:" + a );
					}

	return true;
}
 
Example 14
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 15
Source File: SimpleRemoveLinkPopup.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static boolean filterPairwiseShifts(
		SpimData2 data,
		boolean considerSelection,
		List< List<ViewId> > selectedViewGroups,
		final DemoLinkOverlay demoOverlay
		)
{
	final GenericDialog gd = new GenericDialog("Filter Pairwise Registrations");

	gd.addCheckbox("filter_by_link_quality", false);
	gd.addNumericField("min_R", 0.0, 2);
	gd.addNumericField("max_R", 1.0, 2);

	gd.addCheckbox("filter_by_shift_in_each_dimension", false);
	gd.addNumericField("max_shift_in_X", 0.0, 2);
	gd.addNumericField("max_shift_in_Y", 0.0, 2);
	gd.addNumericField("max_shift_in_Z", 0.0, 2);

	gd.addCheckbox("filter_by_total_shift_magnitude", false);
	gd.addNumericField("max_displacement", 0.0, 2);

	if (considerSelection)
		gd.addCheckbox("remove_only_links_between_selected_views", true);

	gd.showDialog();

	if (gd.wasCanceled())
		return false;

	final boolean doCorrelationFilter = gd.getNextBoolean();
	final double minR = gd.getNextNumber();
	final double maxR = gd.getNextNumber();

	final boolean doAbsoluteShiftFilter = gd.getNextBoolean();
	final double[] maxShift = new double[]{gd.getNextNumber(), gd.getNextNumber(), gd.getNextNumber()};

	final boolean doMagnitudeFilter = gd.getNextBoolean();
	final double maxMag = gd.getNextNumber();

	final boolean onlySelectedLinks = considerSelection ? gd.getNextBoolean() : false;

	final Set<Pair<Group<ViewId>, Group<ViewId>>> selectedPairs = new HashSet<>();
	if (onlySelectedLinks)
	{
		for (int i = 0; i < selectedViewGroups.size(); i++)
			for (int j = i+1; j< selectedViewGroups.size() -1; j++)
			{
				// add both ways just to make sure
				selectedPairs.add(new ValuePair<>(new Group<>(selectedViewGroups.get(i)), new Group<>(selectedViewGroups.get(j))));
				selectedPairs.add(new ValuePair<>(new Group<>(selectedViewGroups.get(j)), new Group<>(selectedViewGroups.get(i))));
			}
	}

	FilteredStitchingResults fsr = new FilteredStitchingResults(data.getStitchingResults(), demoOverlay );

	if (doCorrelationFilter)
		fsr.addFilter(new FilteredStitchingResults.CorrelationFilter(minR, maxR));

	if (doAbsoluteShiftFilter)
		fsr.addFilter(new FilteredStitchingResults.AbsoluteShiftFilter(maxShift));

	if (doMagnitudeFilter)
		fsr.addFilter(new FilteredStitchingResults.ShiftMagnitudeFilter(maxMag));

	if (onlySelectedLinks)
		fsr.applyToWrappedSubset(selectedPairs);
	else
		fsr.applyToWrappedAll();

	return true;
}
 
Example 16
Source File: Layer.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/** Pops up a dialog to choose the first Z coord, the thickness, the number of layers,
 *  and whether to skip the creation of any layers whose Z and thickness match
 *  that of existing layers.
 *  @return The newly created layers. */
static public List<Layer> createMany(final Project project, final LayerSet parent) {
	if (null == parent) return null;
	final GenericDialog gd = ControlWindow.makeGenericDialog("Many new layers");
	gd.addNumericField("First Z coord: ", 0, 3);
	gd.addNumericField("thickness: ", 1.0, 3);
	gd.addNumericField("Number of layers: ", 1, 0);
	gd.addCheckbox("Skip existing layers", true);
	gd.showDialog();
	if (gd.wasCanceled()) return null;
	// start iteration to add layers
	double z = gd.getNextNumber();
	final double thickness = gd.getNextNumber();
	final int n_layers = (int)gd.getNextNumber();
	final boolean skip = gd.getNextBoolean();
	if (thickness < 0) {
		Utils.log("Can't create layers with negative thickness");
		return null;
	}
	if (n_layers < 1) {
		Utils.log("Invalid number of layers");
		return null;
	}
	final List<Layer> layers = new ArrayList<Layer>(n_layers);
	for (int i=0; i<n_layers; i++) {
		Layer la = null;
		if (skip) {
			// Check if layer exists
			la = parent.getLayer(z);
			if (null == la) la = new Layer(project, z, thickness, parent);
			else la = null;
		} else la = new Layer(project, z, thickness, parent);
		if (null != la) {
			parent.addSilently(la);
			layers.add(la);
		}
		z += thickness;
	}
	parent.recreateBuckets(layers, true); // all empty
	// update the scroller of currently open Displays
	Display.updateLayerScroller(parent);
	return layers;
}
 
Example 17
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 18
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 19
Source File: GeodesicDistanceMapPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run(String arg0)
{
	// Open a dialog to choose:
	// - marker image
	// - mask image
	// - set of weights
	int[] indices = WindowManager.getIDList();
	if (indices == null)
	{
		IJ.error("No image", "Need at least one image to work");
		return;
	}

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

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

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

	gd.showDialog();

	if (gd.wasCanceled())
		return;

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

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

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

	res.show();
}
 
Example 20
Source File: ThresholderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public void applyThreshold(ImagePlus imp) {
	imp.deleteRoi();
	ImageProcessor ip = imp.getProcessor();
	ip.resetBinaryThreshold();
	int type = imp.getType();
	if (type==ImagePlus.GRAY16 || type==ImagePlus.GRAY32) {
		applyShortOrFloatThreshold(imp);
		return;
	}
	if (!imp.lock()) return;
	double saveMinThreshold = ip.getMinThreshold();
	double saveMaxThreshold = ip.getMaxThreshold();
	autoThreshold = saveMinThreshold==ImageProcessor.NO_THRESHOLD;

	boolean useBlackAndWhite = true;
	boolean noArgMacro =IJ.macroRunning() && Macro.getOptions()==null;
	if (skipDialog)
		fill1 = fill2 = useBlackAndWhite = true;
	else if (!(autoThreshold||noArgMacro)) {
		GenericDialog gd = new GenericDialog("Make Binary");
		gd.addCheckbox("Thresholded pixels to foreground color", fill1);
		gd.addCheckbox("Remaining pixels to background color", fill2);
		gd.addMessage("");
		gd.addCheckbox("Black foreground, white background", useBW);
		gd.showDialog();
		if (gd.wasCanceled())
		{imp.unlock(); return;}
		fill1 = gd.getNextBoolean();
		fill2 = gd.getNextBoolean();
		useBW = useBlackAndWhite = gd.getNextBoolean();
	} else {
		fill1 = fill2 = true;
		convertToMask = true;
	}

	if (type!=ImagePlus.GRAY8)
		convertToByte(imp);
	ip = imp.getProcessor();

	if (autoThreshold)
		autoThreshold(ip);
	else {
		if (Recorder.record && !Recorder.scriptMode() && (!IJ.isMacro()||Recorder.recordInMacros))
			Recorder.record("setThreshold", (int)saveMinThreshold, (int)saveMaxThreshold);
		minThreshold = saveMinThreshold;
		maxThreshold = saveMaxThreshold;
	}

	if (convertToMask && ip.isColorLut())
		ip.setColorModel(ip.getDefaultColorModel());
	int fcolor, bcolor;
	ip.resetThreshold();
	int savePixel = ip.getPixel(0,0);
	if (useBlackAndWhite)
		ip.setColor(Color.black);
	else
		ip.setColor(Toolbar.getForegroundColor());
	ip.drawPixel(0,0);
	fcolor = ip.getPixel(0,0);
	if (useBlackAndWhite)
		ip.setColor(Color.white);
	else
		ip.setColor(Toolbar.getBackgroundColor());
	ip.drawPixel(0,0);
	bcolor = ip.getPixel(0,0);
	ip.setColor(Toolbar.getForegroundColor());
	ip.putPixel(0,0,savePixel);

	int[] lut = new int[256];
	for (int i=0; i<256; i++) {
		if (i>=minThreshold && i<=maxThreshold)
			lut[i] = fill1?fcolor:(byte)i;
		else {
			lut[i] = fill2?bcolor:(byte)i;
		}
	}
	if (imp.getStackSize()>1)
		new StackProcessor(imp.getStack(), ip).applyTable(lut);
	else
		ip.applyTable(lut);
	if (convertToMask) {
		if (!imp.isInvertedLut()) {
			setInvertedLut(imp);
			fcolor = 255 - fcolor;
			bcolor = 255 - bcolor;
		}
		if (Prefs.blackBackground)
			ip.invertLut();
	}
	if (fill1 && fill2 && ((fcolor==0&&bcolor==255)||(fcolor==255&&bcolor==0)))
		imp.getProcessor().setThreshold(fcolor, fcolor, ImageProcessor.NO_LUT_UPDATE);
	imp.updateAndRepaintWindow();
	imp.unlock();
}