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

The following examples show how to use ij.gui.GenericDialog#addNumericField() . 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: KMeans_ClusteringJ.java    From IJ-OpenCV with GNU General Public License v3.0 6 votes vote down vote up
private boolean showDialog() {

        GenericDialog gd = new GenericDialog("Number of clusters");
        gd.addNumericField("N clusters", nclusters, 0);
        //gd.addNumericField("Gaussian Kernel width:", gaussianKernelWidth, 0);

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

        nclusters = (int) gd.getNextNumber();
        if (nclusters < 2) {
            nclusters = 2;
        }

        return true;
    }
 
Example 2
Source File: ReplaceValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run(String arg0) {
	ImagePlus imagePlus = IJ.getImage();
	
	GenericDialog gd = new GenericDialog("Replace Value");
	gd.addNumericField("Initial Value", 1, 0);
	gd.addNumericField("Final Value", 0, 0);
	gd.showDialog();
	
	if (gd.wasCanceled())
		return;
	
	double initialValue = gd.getNextNumber();
	double finalValue = gd.getNextNumber();

	Images3D.replaceValue(imagePlus, initialValue, finalValue);
	imagePlus.updateAndDraw();
}
 
Example 3
Source File: TransformationModel.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public boolean queryRegularizedModel()
{
	final GenericDialog gd = new GenericDialog( "Regularization Parameters" );

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

	gd.showDialog();

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

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

	return true;
}
 
Example 4
Source File: EfficientBayesianBased.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected boolean getOSEM()
{
	if ( osemspeedupIndex == 0 )
	{
		defaultOSEMspeedup = osemSpeedUp = 1;
	}
	else if ( osemspeedupIndex == 3 )
	{
		GenericDialog gdOSEM = new GenericDialog( "OSEM options" );
		gdOSEM.addNumericField( "Additional_acceleration = ", defaultOSEMspeedup, 2 );
		gdOSEM.showDialog();
		
		if ( gdOSEM.wasCanceled() )
			return false;
		
		defaultOSEMspeedup = osemSpeedUp = gdOSEM.getNextNumber();			
	}
	
	return true;
}
 
Example 5
Source File: DifferenceOfGaussian.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( "Sigma" + ch, defaultSigma[ channelId ], 5 );
	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.sigma[ channelId ] = defaultSigma[ channelId ] = 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: BGR_Histogram_ComparisonJ_.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
private boolean showDialog() {

        GenericDialog gd = new GenericDialog("BGR Histogram Comparison");
        gd.addNumericField("Blue bins", blueBins, 0);
        gd.addNumericField("Green bins", greenBins, 0);
        gd.addNumericField("Red bins", redBins, 0);
        //gd.addNumericField("Gaussian Kernel width:", gaussianKernelWidth, 0);

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

        blueBins = (int) gd.getNextNumber();
        if (blueBins < 1) {
            blueBins = 1;
        }
        if (blueBins > 255) {
            blueBins = 255;
        }

        greenBins = (int) gd.getNextNumber();
        if (greenBins < 1) {
            greenBins = 1;
        }
        if (greenBins > 255) {
            greenBins = 255;
        }
        redBins = (int) gd.getNextNumber();
        if (redBins < 1) {
            redBins = 1;
        }
        if (redBins > 255) {
            redBins = 255;
        }

        return true;
    }
 
Example 7
Source File: Align.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public void addGeometricConsensusFilterFields( final GenericDialog gd )
{
	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 :", modelStrings, modelStrings[ expectedModelIndex ] );
	gd.addCheckbox( "ignore constant background", rejectIdentity );
	gd.addNumericField( "tolerance :", identityTolerance, 2, 6, "px" );
}
 
Example 8
Source File: DirectionalFilteringPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr)
	{
		// Normal setup
    	this.imagePlus = imp;
    	this.baseImage = imp.getProcessor().duplicate();

		// Create the configuration dialog
		GenericDialog gd = new GenericDialog("Directional Filtering");
		
		gd.addChoice("Type", Type.getAllLabels(), this.type.toString());
		gd.addChoice("Operation", Operation.getAllLabels(), this.op.toString());
		gd.addNumericField("Line Length", this.lineLength, 0, 8, "pixels");
		gd.addNumericField("Direction Number", this.nDirections, 0);
		
		gd.addPreviewCheckbox(pfr);
		gd.addDialogListener(this);
        previewing = true;
//		gd.addHelp("http://imagejdocu.tudor.lu/doku.php?id=plugin:morphology:fast_morphological_filters:start");
        gd.showDialog();
        previewing = false;
        
        if (gd.wasCanceled()) 
        {
			return DONE;
        }
        
    	parseDialogParameters(gd);
			
		// clean up an return 
		gd.dispose();
		return flags;
	}
 
Example 9
Source File: SelectIlluminationPopup.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static ViewSelection< ViewId > getViewSelectionResult( final GenericDialog gd, final AbstractSequenceDescription< ?, ?, ? > sd )
{
	String choice = gd.getNextChoice();
	if (choice.equals( "Pick brightest" ))
		return new BrightestViewSelection( sd );
	else if (choice.equals("Pick highest mean gradient magnitude"))
		return new MeanGradientMagnitudeViewSelection(sd);
	else if (choice.equals("Relative Fourier Ring Correlation"))
	{
		final GenericDialog gd1 = new GenericDialog( "Relative FRC Parameters" );

		gd1.addCheckbox( "Relative_FRC", QualityGUI.defaultUseRelativeFRC );
		gd1.addCheckbox( "Smooth_Local_FRC", QualityGUI.defaultSmoothLocalFRC );
		gd1.addNumericField( "FRC_FFT_Size", QualityGUI.defaultFFTSize, 0 );
		gd1.addNumericField( "FRC_Stepsize (z)", QualityGUI.defaultFRCStepSize, 0 );

		gd1.showDialog();

		if ( gd1.wasCanceled() )
			return null;

		final boolean useRelativeFRC = QualityGUI.defaultUseRelativeFRC = gd1.getNextBoolean();
		final boolean useSmoothLocalFRC = QualityGUI.defaultSmoothLocalFRC = gd1.getNextBoolean();
		final int fftSize = QualityGUI.defaultFFTSize = Math.max( 16, (int)Math.round( gd1.getNextNumber() ) );
		final int frcStepSize = QualityGUI.defaultFRCStepSize = Math.max( 1, (int)Math.round( gd1.getNextNumber() ) );

		return new RelativeFRCSelection( sd, frcStepSize, fftSize, useRelativeFRC, useSmoothLocalFRC );
	}
	else
		return null;
	
}
 
Example 10
Source File: LabelAreaOpeningPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void run(String arg0) {
	ImagePlus imagePlus = IJ.getImage();
       
       // create the dialog, with operator options
	boolean isPlanar = imagePlus.getStackSize() == 1; 
	String title = "Label Size Opening";
       GenericDialog gd = new GenericDialog(title);
       String label = isPlanar ? "Min Pixel Number:" : "Min Voxel Number:";
       gd.addNumericField(label, 100, 0);
       gd.showDialog();
       
       // If cancel was clicked, do nothing
       if (gd.wasCanceled())
           return;

       int nPixelMin = (int) gd.getNextNumber();
       
       // Apply size opening using IJPB library
       ImagePlus resultPlus = LabelImages.sizeOpening(imagePlus, nPixelMin);

       // Display image, and choose same slice as original
	resultPlus.show();
	if (imagePlus.getStackSize() > 1) {
		resultPlus.setSlice(imagePlus.getCurrentSlice());
	}
}
 
Example 11
Source File: LucasKanadeParameters.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static void addQueriesToGD(final GenericDialog gd, boolean askForModelType)
{
	gd.addNumericField( "maximum_iterations", 100, 0, 10, "" );
	gd.addNumericField( "minimum_parameter_change_for_convergence", 0.01, 2, 10, "" );
	if (askForModelType)
		gd.addChoice( "transformation_type", modelChoices, modelChoices[0] );
	gd.addCheckbox( "show_expert_grouping_options", false );
}
 
Example 12
Source File: Loader.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/** If base_x or base_y are Double.MAX_VALUE, then those values are asked for in a GenericDialog. */
public Bureaucrat importLabelsAsAreaLists(final Layer first_layer, final String path_, final double base_x_, final double base_y_, final float alpha_, final boolean add_background_) {
	final Worker worker = new Worker("Import labels as arealists") {
		@Override
           public void run() {
			startedWorking();
			try {
				String path = path_;
				if (null == path) {
					final OpenDialog od = new OpenDialog("Select stack", "");
					final String name = od.getFileName();
					if (null == name || 0 == name.length()) {
						return;
					}
					String dir = od.getDirectory().replace('\\', '/');
					if (!dir.endsWith("/")) dir += "/";
					path = dir + name;
				}
				if (path.toLowerCase().endsWith(".xml")) {
					Utils.log("Avoided opening a TrakEM2 project.");
					return;
				}
				double base_x = base_x_;
				double base_y = base_y_;
				float alpha = alpha_;
				boolean add_background = add_background_;
				Layer layer = first_layer;
				if (Double.MAX_VALUE == base_x || Double.MAX_VALUE == base_y || alpha < 0 || alpha > 1) {
					final GenericDialog gd = new GenericDialog("Base x, y");
					Utils.addLayerChoice("First layer:", first_layer, gd);
					gd.addNumericField("Base_X:", 0, 0);
					gd.addNumericField("Base_Y:", 0, 0);
					gd.addSlider("Alpha:", 0, 100, 40);
					gd.addCheckbox("Add background (zero)", false);
					gd.showDialog();
					if (gd.wasCanceled()) {
						return;
					}
					layer = first_layer.getParent().getLayer(gd.getNextChoiceIndex());
					base_x = gd.getNextNumber();
					base_y = gd.getNextNumber();
					if (Double.isNaN(base_x) || Double.isNaN(base_y)) {
						Utils.log("Base x or y is NaN!");
						return;
					}
					alpha = (float)(gd.getNextNumber() / 100);
					add_background = gd.getNextBoolean();
				}
				releaseToFit(new File(path).length() * 3);
				final ImagePlus imp;
				if (path.toLowerCase().endsWith(".am")) {
					final AmiraMeshDecoder decoder = new AmiraMeshDecoder();
					if (decoder.open(path)) imp = new ImagePlus(path, decoder.getStack());
					else imp = null;
				} else {
					imp = openImagePlus(path);
				}
				if (null == imp) {
					Utils.log("Could not open image at " + path);
					return;
				}
				final Map<Float,AreaList> alis = AmiraImporter.extractAreaLists(imp, layer, base_x, base_y, alpha, add_background);
				if (!hasQuitted() && alis.size() > 0) {
					layer.getProject().getProjectTree().insertSegmentations(alis.values());
				}
			} catch (final Exception e) {
				IJError.print(e);
			} finally {
				finishedWorking();
			}
		}
	};
	return Bureaucrat.createAndStart(worker, first_layer.getProject());
}
 
Example 13
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 14
Source File: Align.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public void addAlignmentFields( final GenericDialog gd )
{
	gd.addChoice( "desired_transformation :", modelStrings, modelStrings[ desiredModelIndex ] );
	gd.addNumericField( "correspondence weight :", correspondenceWeight, 2 );
	gd.addCheckbox( "regularize", regularize );
}
 
Example 15
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Setup as a three step dialog.
 */
@Override
public boolean setup( final String title )
{
	source_dir = "";
	while ( source_dir == "" )
	{
		final DirectoryChooser dc = new DirectoryChooser( "Calibration Images" );
		source_dir = dc.getDirectory();
		if ( null == source_dir ) return false;

		source_dir = source_dir.replace( '\\', '/' );
		if ( !source_dir.endsWith( "/" ) ) source_dir += "/";
	}

	final String exts = ".tif.jpg.png.gif.tiff.jpeg.bmp.pgm";
	names = new File( source_dir ).list(
			new FilenameFilter()
			{
				@Override
                      public boolean accept( final File dir, final String name )
				{
					final int idot = name.lastIndexOf( '.' );
					if ( -1 == idot ) return false;
					return exts.contains( name.substring( idot ).toLowerCase() );
				}
			} );
	Arrays.sort( names );

	final GenericDialog gd = new GenericDialog( title );

	gd.addNumericField( "number_of_images :", 9, 0 );
	gd.addChoice( "first_image :", names, names[ 0 ] );
	gd.addNumericField( "power_of_polynomial_kernel :", dimension, 0 );
	gd.addNumericField( "lambda :", lambda, 6 );
	gd.addCheckbox( "apply_correction_to_images", applyCorrection );
	gd.addCheckbox( "visualize results", visualizeResults );
	final String[] options = new String[]{ "save", "load" };
	gd.addChoice( "What to do? ", options, options[ saveOrLoad ] );
	gd.addStringField( "file_name: ", saveFileName );
	gd.showDialog();

	if (gd.wasCanceled()) return false;

	numberOfImages = ( int )gd.getNextNumber();
	firstImageIndex = gd.getNextChoiceIndex();
	dimension = ( int )gd.getNextNumber();
	lambda = gd.getNextNumber();
	applyCorrection = gd.getNextBoolean();
	visualizeResults = gd.getNextBoolean();
	saveOrLoad = gd.getNextChoiceIndex();
	saveFileName = gd.getNextString();

	if ( saveOrLoad == 0 || visualizeResults )
	{
		final GenericDialog gds = new GenericDialog( title );
		SIFT.addFields( gds, sift );

		gds.addNumericField( "closest/next_closest_ratio :", rod, 2 );

		gds.addMessage( "Geometric Consensus Filter:" );
		gds.addNumericField( "maximal_alignment_error :", maxEpsilon, 2, 6, "px" );
		gds.addNumericField( "inlier_ratio :", minInlierRatio, 2 );
		gds.addChoice( "expected_transformation :", modelStrings, modelStrings[ expectedModelIndex ] );

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

		SIFT.readFields( gds, sift );

		rod = ( float )gds.getNextNumber();

		maxEpsilon = ( float )gds.getNextNumber();
		minInlierRatio = ( float )gds.getNextNumber();
		expectedModelIndex = gds.getNextChoiceIndex();

		return !( gd.invalidNumber() || gds.invalidNumber() );
	}

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

	final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	final String[] fonts = ge.getAvailableFontFamilyNames();
	final String[] sizes = {"8","9","10","12","14","18","24","28","36","48","60","72"};
	final String[] styles = {"Plain", "Bold", "Italic", "Bold+Italic"};
	int i = 0;
	final String family = this.font.getFamily();
	for (i = fonts.length -1; i>-1; i--) {
		if (family.equals(fonts[i])) break;
	}
	if (-1 == i) i = 0;
	gd.addChoice("Font Family: ", fonts, fonts[i]);
	final int size = this.font.getSize();
	for (i = sizes.length -1; i>-1; i--) {
		if (Integer.parseInt(sizes[i]) == size) break;
	}
	if (-1 == i) i = 0;
	gd.addChoice("Font Size: ", sizes, sizes[i]);
	gd.addNumericField("or enter size: ", size, 0);
	i=0;
	switch (this.font.getStyle()) {
		case Font.PLAIN: i=0; break;
		case Font.BOLD: i=1; break;
		case Font.ITALIC: i=2; break;
		case Font.BOLD+Font.ITALIC: i=3; break;
	}
	gd.addChoice("Font style: ", styles, styles[i]);

	gd.showDialog();
	if (gd.wasCanceled()) return;
	// superclass processing
	processAdjustPropertiesDialog(gd);
	// local proccesing
	final String new_font = gd.getNextChoice();
	int new_size = Integer.parseInt(gd.getNextChoice());
	final int new_size_2 = (int)gd.getNextNumber();
	if (new_size_2 != size) {
		new_size = new_size_2;
	}
	int new_style = gd.getNextChoiceIndex();
	switch (new_style) {
		case 0: new_style = Font.PLAIN; break;
		case 1: new_style = Font.BOLD; break;
		case 2: new_style = Font.ITALIC; break;
		case 3: new_style = Font.BOLD+Font.ITALIC; break;
	}
	this.font = new Font(new_font, new_style, new_size);
	updateInDatabase("font");
	// update dimensions
	setText(this.title, true);
}
 
Example 20
Source File: Displayable.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
protected GenericDialog makeAdjustPropertiesDialog() {
	Rectangle box = getBoundingBox(null);
	GenericDialog gd = new GD("Properties of #" + id, this);
	gd.addStringField("title: ", title);
	gd.addNumericField("x: ", box.x, 2);
	gd.addNumericField("y: ", box.y, 2);
	gd.addNumericField("scale_x: ", 1, 2);
	gd.addNumericField("scale_y: ", 1, 2);
	gd.addNumericField("rot (degrees): ", 0, 2);
	gd.addSlider("alpha: ", 0, 100, (int)(alpha*100));
	gd.addCheckbox("visible", visible);
	gd.addSlider("Red: ", 0, 255, color.getRed());
	gd.addSlider("Green: ", 0, 255, color.getGreen());
	gd.addSlider("Blue: ", 0, 255, color.getBlue());
	gd.addCheckbox("locked", locked);
	// add slider listener
	final Scrollbar alp = (Scrollbar)gd.getSliders().get(0);
	final Scrollbar red = (Scrollbar)gd.getSliders().get(1);
	final Scrollbar green = (Scrollbar)gd.getSliders().get(2);
	final Scrollbar blue = (Scrollbar)gd.getSliders().get(3);
	final TextField talp = (TextField)gd.getNumericFields().get(5);
	final TextField tred = (TextField)gd.getNumericFields().get(6);
	final TextField tgreen = (TextField)gd.getNumericFields().get(7);
	final TextField tblue = (TextField)gd.getNumericFields().get(8);
	SliderListener sla = new SliderListener() {
		public void update() {
			setAlpha((float)alp.getValue()/100);
		}
	};
	SliderListener slc = new SliderListener() {
		public void update() {
			setColor(new Color(red.getValue(), green.getValue(), blue.getValue()));
		}
	};
	alp.addAdjustmentListener(sla);
	red.addAdjustmentListener(slc);
	green.addAdjustmentListener(slc);
	blue.addAdjustmentListener(slc);
	talp.addTextListener(sla);
	tred.addTextListener(slc);
	tgreen.addTextListener(slc);
	tblue.addTextListener(slc);
	
	gd.addChoice( "composite mode: ", compositeModes, compositeModes[ compositeMode ] );
	return gd;
}