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

The following examples show how to use ij.gui.GenericDialog#addSlider() . 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: ShenCastan.java    From Scripts with GNU General Public License v3.0 6 votes vote down vote up
/** Displays the dialog prompt. */
@Override
public int showDialog(final ImagePlus imp, final String command, final PlugInFilterRunner pfr) {
	this.pfr = pfr;

	final String msg = "<html><div WIDTH=350>"
			+ "<a href='https://github.com/tferr/Scripts/blob/master/Segmentation/README.md#shen-castan-edge-detector'>"
			+ "Shen-Castan</a> filtering is an edge detection technique. It is an alternative "
			+ "to other popular approaches such as "
			+ "<a href='http://en.wikipedia.org/wiki/Canny_edge_detector'>Canny</a>-"
			+ "<a href='http://en.wikipedia.org/wiki/Deriche_edge_detector'>Deriche</a> filtering.</p>"
			+ "<p>The Shen-Castan coefficient corresponds to a smooting factor <i>alpha</i>. "
			+ "<i>Alpha</i> can vary between 0 (high smoothing, suitable for noisy images) "
			+ "and 1 (no smoothing, suitable for non-noisy images).</p></div></html>";

	final GenericDialog gd = new GenericDialog(command);
	gd.addSlider("Coefficient:", 0.0001d, 1.0001d, f);
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
	gd.addHelp(msg);
	gd.showDialog();
	if (gd.wasCanceled() || !dialogItemChanged(gd, null)) // read parameters
		return DONE;
	return IJ.setupDialog(imp, flags);
}
 
Example 2
Source File: SkewImagesPopup.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	final SpimData spimData = (SpimData)panel.getSpimData();
	final List< ViewId > views = ((GroupedRowWindow) panel).selectedRowsViewIdGroups().stream().reduce(new ArrayList<>(),  (a,b) -> {a.addAll( b ); return a;} );

	final Map<ViewId, Dimensions> dims = new HashMap<>();
	views.forEach( v -> dims.put( v, spimData.getSequenceDescription().getViewDescriptions() .get( v ).getViewSetup().getSize()) );
	GenericDialog gd = new GenericDialog( "(De)Skew Parameters" );
	
	gd.addChoice( "Skew Direction", axesChoice, axesChoice[0] );
	gd.addChoice( "Skew Along Which Axis", axesChoice, axesChoice[2] );
	gd.addSlider( "Angle", -90, 90, 45 );

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

	final int direction = gd.getNextChoiceIndex();
	final int skewAxis = gd.getNextChoiceIndex();
	final double angle = gd.getNextNumber() / 180 * Math.PI;

	SkewImages.applySkewToData( spimData.getViewRegistrations(), dims, views, direction, skewAxis, angle );

	panel.updateContent();
	panel.bdvPopup().updateBDV();
}
 
Example 3
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 4
Source File: Display3D.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
synchronized private final int adjustResampling() {
	if (resample > 0) return resample;
	final GenericDialog gd = new GenericDialog("Resample");
	final int default_resample = estimateResamplingFactor();
	gd.addSlider("Resample: ", 1, Math.max(default_resample, 100), -1 != resample ? resample : default_resample);
	gd.showDialog();
	if (gd.wasCanceled()) {
		resample = -1 != resample ? resample : default_resample; // current or default value
		return resample;
	}
	resample = ((java.awt.Scrollbar)gd.getSliders().get(0)).getValue();
	return resample;
}
 
Example 5
Source File: AreaWrapper.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean setup() {
	GenericDialog gd = new GenericDialog("Paint parameters");
	gd.addSlider("Default_alpha", 0, 100, default_alpha * 100);
	final String[] modes = {"Allow overlap", "Exclude others", "Erode others"};
	gd.addChoice("Paint mode", modes, modes[paint_mode]);
	gd.showDialog();
	if (gd.wasCanceled()) return false;
	this.default_alpha = (float) gd.getNextNumber();
	if (this.default_alpha > 1) this.default_alpha = 1f;
	else if (this.default_alpha < 0) this.default_alpha = 0.4f; // back to default's default value
	this.paint_mode = gd.getNextChoiceIndex();
	// trigger update of GUI radio buttons on all displays:
	Display.toolChanged(ProjectToolbar.BRUSH);
	return true;
}
 
Example 6
Source File: BoundingBoxGUI.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected GenericDialog getSimpleDialog( final boolean compress, final boolean allowModifyDimensions )
{
	final int[] rangeMin = new int[ 3 ];
	final int[] rangeMax = new int[ 3 ];

	setUpDefaultValues( rangeMin, rangeMax );

	final GenericDialog gd = new GenericDialog( "Manually define Bounding Box" );

	gd.addMessage( "Note: Coordinates are in global coordinates as shown " +
			"in Fiji status bar of a fused datasets", GUIHelper.smallStatusFont );

	if ( !compress )
		gd.addMessage( "", GUIHelper.smallStatusFont );

	gd.addSlider( "Minimal_X", rangeMin[ 0 ], rangeMax[ 0 ], this.min[ 0 ] );
	gd.addSlider( "Minimal_Y", rangeMin[ 1 ], rangeMax[ 1 ], this.min[ 1 ] );
	gd.addSlider( "Minimal_Z", rangeMin[ 2 ], rangeMax[ 2 ], this.min[ 2 ] );

	if ( !compress )
		gd.addMessage( "" );

	gd.addSlider( "Maximal_X", rangeMin[ 0 ], rangeMax[ 0 ], this.max[ 0 ] );
	gd.addSlider( "Maximal_Y", rangeMin[ 1 ], rangeMax[ 1 ], this.max[ 1 ] );
	gd.addSlider( "Maximal_Z", rangeMin[ 2 ], rangeMax[ 2 ], this.max[ 2 ] );

	if ( !allowModifyDimensions )
	{
		for ( int i = gd.getSliders().size() - 6; i < gd.getSliders().size(); ++i )
			((Scrollbar)gd.getSliders().get( i )).setEnabled( false );

		for ( int i = gd.getNumericFields().size() - 6; i < gd.getNumericFields().size(); ++i )
			((TextField)gd.getNumericFields().get( i )).setEnabled( false );
	}

	return gd;
}
 
Example 7
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 8
Source File: IterativeClosestPoint.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( "Maximal_distance for correspondence (px)", 0.25, 40.0, IterativeClosestPointParameters.maxDistance );
	gd.addNumericField( "Maximal_number of iterations", IterativeClosestPointParameters.maxIterations, 0 );
}
 
Example 9
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 10
Source File: ExtendedMinAndMaxPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
	// Normal setup
   	this.imagePlus = imp;
   	this.baseImage = imp.getProcessor().duplicate();

	// Create the configuration dialog
	GenericDialog gd = new GenericDialog("Extended Min & Max");
	
	gd.addChoice("Operation", Operation.getAllLabels(), Operation.EXTENDED_MINIMA.label);
	boolean isGray8 = (this.baseImage instanceof ByteProcessor);
	double minValue = isGray8 ? 1 : this.baseImage.getMin();
	double maxValue = isGray8 ? 255 : this.baseImage.getMax();
	gd.addSlider("Dynamic", minValue, maxValue, 10);
	gd.addChoice("Connectivity", connectivityLabels, connectivityLabels[0]);
	
	gd.addPreviewCheckbox(pfr);
	gd.addDialogListener(this);
       previewing = true;
       gd.addHelp("https://imagej.net/MorphoLibJ");
       gd.showDialog();
       previewing = false;
       
       if (gd.wasCanceled()) {
		return DONE;
       }
       
   	parseDialogParameters(gd);
		
	// clean up an return 
	gd.dispose();
	return flags;
}
 
Example 11
Source File: SkewImagesCommand.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();
	// get views to process
	final ArrayList< ViewId > views = SpimData2.getAllViewIdsSorted( result.getData(),
			result.getViewSetupsToProcess(), result.getTimePointsToProcess() );

	// get dimensions for selected views
	final Map< ViewId, Dimensions > dims = new HashMap<>();
	views.forEach( v -> dims.put( v,
			data.getSequenceDescription().getViewDescriptions().get( v ).getViewSetup().getSize() ) );

	// query parameters in dialog
	GenericDialog gd = new GenericDialog( "(De)Skew Parameters" );
	gd.addChoice( "Skew_Direction", axesChoice, axesChoice[0] );
	gd.addChoice( "Skew_Along_Which_Axis", axesChoice, axesChoice[2] );
	gd.addSlider( "Angle", -90, 90, 45 );
	gd.showDialog();

	if (gd.wasCanceled())
		return;

	// get parameters from dialog
	final int direction = gd.getNextChoiceIndex();
	final int skewAxis = gd.getNextChoiceIndex();
	final double angle = gd.getNextNumber() / 180 * Math.PI;

	SkewImages.applySkewToData( data.getViewRegistrations(), dims, views, direction, skewAxis, angle );

	// save result
	SpimData2.saveXML( data, result.getXMLFileName(), result.getClusterExtension() );
}
 
Example 12
Source File: AutomaticBoundingBox.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean queryParameters( final Fusion fusion, final ImgExport imgExport )
{
	// first get an idea of the maximal bounding box
	final double[] minBB = new double[ 3 ];
	final double[] maxBB = new double[ 3 ];

	BoundingBoxGUI.computeMaxBoundingBoxDimensions( spimData, viewIdsToProcess, minBB, maxBB );

	// compute dimensions and update size for this instance
	final long[] dim = new long[ maxBB.length ];

	// first time called on this object
	if ( this.min == null || this.max == null )
	{
		this.min = new int[ minBB.length ];
		this.max = new int[ minBB.length ];
	}

	for ( int d = 0; d < dim.length; ++d )
	{
		this.min[ d ] = (int)Math.round( minBB[ d ] );
		this.max[ d ] = (int)Math.round( maxBB[ d ] );
		dim[ d ] = this.max[ d ] - this.min[ d ] + 1;
	}

	final GenericDialog gd = new GenericDialog( "Automatically define Bounding Box" );

	final List< TimePoint > timepointsToProcess = SpimData2.getAllTimePointsSorted( spimData, viewIdsToProcess );
	final List< Channel > channelsToProcess = SpimData2.getAllChannelsSorted( spimData, viewIdsToProcess );

	final String[] timepoints = assembleTimepoints( timepointsToProcess );
	final String[] channels = assembleChannels( channelsToProcess );

	if ( defaultTimepointIndex >= timepoints.length )
		defaultTimepointIndex = 0;

	if ( defaultChannelIndex >= channels.length )
		defaultChannelIndex = 0;
			
	gd.addMessage( "Parameters for automatic segmentation", GUIHelper.largestatusfont );
	
	gd.addChoice( "Timepoint", timepoints, timepoints[ defaultTimepointIndex ] );
	gd.addChoice( "Channel", channels, channels[ defaultChannelIndex ] );
	gd.addSlider( "Background intensity [%]", 1.0, 99.0, defaultBackgroundIntensity );
	gd.addSlider( "Size_of_objects to be discarded", 1, 100, defaultDiscardedObjectSize );
	gd.addMessage( "" );
	gd.addSlider( "Downsampling", 1.0, 10.0, defaultDownsamplingAutomatic );
	gd.addCheckbox( "Load_input_images sequentially", defaultLoadSequentially );
	gd.addCheckbox( "Display_image_used for segmentation", defaultDisplaySegmentationImage );
	gd.addMessage( "Image size: ???x???x??? pixels", GUIHelper.mediumstatusfont, GUIHelper.good );
	Label l = (Label)gd.getMessage();
	
	// add listeners and update values
	addListeners( gd, gd.getNumericFields(), l, dim );
	
	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return false;

	final TimePoint timepoint = timepointsToProcess.get( defaultTimepointIndex = gd.getNextChoiceIndex() );
	final Channel channel = channelsToProcess.get( defaultChannelIndex = gd.getNextChoiceIndex() );
	final double background = defaultBackgroundIntensity = gd.getNextNumber();
	final int discardedObjectSize = defaultDiscardedObjectSize = (int)Math.round( gd.getNextNumber() );

	this.downsampling = defaultDownsamplingAutomatic = (int)Math.round( gd.getNextNumber() );
	final boolean loadSequentially = defaultLoadSequentially = gd.getNextBoolean();
	final boolean displaySegmentationImage = defaultDisplaySegmentationImage = gd.getNextBoolean();
	
	// compute approx bounding box
	final MinFilterThreshold automatic = new MinFilterThreshold(
			spimData,
			viewIdsToProcess,
			channel,
			timepoint,
			this,
			background,
			discardedObjectSize,
			loadSequentially,
			displaySegmentationImage );
	
	if ( !automatic.run() )
	{
		return false;
	}
	else
	{
		this.min = automatic.getMin().clone();
		this.max = automatic.getMax().clone();
		BoundingBoxGUI.defaultMin = automatic.getMin().clone();
		BoundingBoxGUI.defaultMax = automatic.getMax().clone();
	}

	return super.queryParameters( fusion, imgExport );
}
 
Example 13
Source File: BoundingBoxGUI.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Query the necessary parameters for the bounding box
 * 
 * @param fusion - the fusion for which the bounding box is computed, can be null
 * @param imgExport - the export module used, can be null
 * @return
 */
public boolean queryParameters( final Fusion fusion, final ImgExport imgExport, final boolean allowModifyDimensions )
{
	final boolean compress = fusion == null ? false : fusion.compressBoundingBoxDialog();
	final boolean supportsDownsampling = fusion == null ? false : fusion.supportsDownsampling();
	final boolean supports16BitUnsigned = fusion == null ? false : fusion.supports16BitUnsigned();

	final GenericDialog gd = getSimpleDialog( compress, allowModifyDimensions );

	if ( !compress )
		gd.addMessage( "" );

	if ( supportsDownsampling )
		gd.addSlider( "Downsample fused dataset", 1.0, 10.0, BoundingBoxGUI.staticDownsampling );
	
	if ( supports16BitUnsigned )
		gd.addChoice( "Pixel_type", pixelTypes, pixelTypes[ defaultPixelType ] );

	if ( fusion != null && imgExport != null )
		gd.addChoice( "ImgLib2_container", imgTypes, imgTypes[ defaultImgType ] );

	if ( fusion != null )
		fusion.queryAdditionalParameters( gd );

	if ( imgExport != null )
		imgExport.queryAdditionalParameters( gd, spimData );

	gd.addMessage( "Estimated size: ", GUIHelper.largestatusfont, GUIHelper.good );
	Label l1 = (Label)gd.getMessage();
	gd.addMessage( "???x???x??? pixels", GUIHelper.smallStatusFont, GUIHelper.good );
	Label l2 = (Label)gd.getMessage();

	final ManageListeners m = new ManageListeners( gd, gd.getNumericFields(), gd.getChoices(), l1, l2, fusion, imgExport, supportsDownsampling, supports16BitUnsigned );

	if ( fusion != null )
		fusion.registerAdditionalListeners( m );

	m.update();

	gd.showDialog();

	if ( gd.wasCanceled() )
		return false;

	if ( allowModifyDimensions )
	{
		this.min[ 0 ] = (int)Math.round( gd.getNextNumber() );
		this.min[ 1 ] = (int)Math.round( gd.getNextNumber() );
		this.min[ 2 ] = (int)Math.round( gd.getNextNumber() );

		this.max[ 0 ] = (int)Math.round( gd.getNextNumber() );
		this.max[ 1 ] = (int)Math.round( gd.getNextNumber() );
		this.max[ 2 ] = (int)Math.round( gd.getNextNumber() );
	}
	else
	{
		setNFIndex( gd, 6 );
	}

	if ( supportsDownsampling )
		this.downsampling = BoundingBoxGUI.staticDownsampling = (int)Math.round( gd.getNextNumber() );
	else
		this.downsampling = 1;

	if ( supports16BitUnsigned )
		this.pixelType = BoundingBoxGUI.defaultPixelType = gd.getNextChoiceIndex();
	else
		this.pixelType = BoundingBoxGUI.defaultPixelType = 0; //32-bit

	if ( fusion != null && imgExport != null )
		this.imgtype = BoundingBoxGUI.defaultImgType = gd.getNextChoiceIndex();

	if ( min[ 0 ] > max[ 0 ] || min[ 1 ] > max[ 1 ] || min[ 2 ] > max[ 2 ] )
	{
		IOFunctions.println( "Invalid coordinates, min cannot be larger than max" );
		return false;
	}

	if ( fusion != null )
		if ( !fusion.parseAdditionalParameters( gd ) )
			return false;

	if ( imgExport != null )
		if ( !imgExport.parseAdditionalParameters( gd, spimData ) )
			return false;

	BoundingBoxGUI.defaultMin[ 0 ] = min[ 0 ];
	BoundingBoxGUI.defaultMin[ 1 ] = min[ 1 ];
	BoundingBoxGUI.defaultMin[ 2 ] = min[ 2 ];
	BoundingBoxGUI.defaultMax[ 0 ] = max[ 0 ];
	BoundingBoxGUI.defaultMax[ 1 ] = max[ 1 ];
	BoundingBoxGUI.defaultMax[ 2 ] = max[ 2 ];

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

		if (plot == null)
			return;

		final int DEF_LINE_WIDTH = 1;
		final int DEF_MAX_INTERVALS = 12;
		final int DEF_TICK_LENGTH = 7;
		final int DEF_MINOR_TICK_LENGTH = 3;
		final int[] NUM_DEFAULTS = { DEF_LINE_WIDTH, DEF_MAX_INTERVALS, DEF_TICK_LENGTH, DEF_MINOR_TICK_LENGTH };
		final String DEF_BACKGROUND_COLOR = "white";
		final String title = plot.getTitle();
		final GenericDialog ogd = new GenericDialog("Options for " + title);
		ogd.setInsets(0, 10, 10);
		ogd.addMessage("This prompt allows you access customizations that\n"
				+ "are not accessible through the plot's \"More \u00bb\" menu");
		if (!pwClosed)
			ogd.addStringField("Plot title:", title, 27);
		ogd.addSlider("Line width:", 1, 20, 1);
		ogd.addSlider("Max. n. of intervals:", 1, 40, 12);
		ogd.addSlider("Major ticks length:", 1, 14, 7);
		ogd.addSlider("Minor ticks length:", 1, 14, 3);
		ogd.addChoice("Backgrond color:", Colors.colors, DEF_BACKGROUND_COLOR);
		final Panel buttonPanel = new Panel();
		final Button fontButton = new Button("  Text & Font...  ");
		fontButton.addActionListener(ogd);
		buttonPanel.add(fontButton);
		final Button templateButton = new Button("Apply Template...");
		templateButton.addActionListener(ogd);
		buttonPanel.add(templateButton);
		ogd.addPanel(buttonPanel, GridBagConstraints.EAST, new Insets(0, 0, 0, 0));
		ogd.hideCancelButton();
		ogd.addHelp("");
		ogd.setHelpLabel("Apply Defaults");
		ogd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {

				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<TextField> nFields = gd.getNumericFields();
					for (final TextField field : nFields)
						field.setText(Integer.toString(NUM_DEFAULTS[nFields.indexOf(field)]));
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					nChoices.firstElement().select(DEF_BACKGROUND_COLOR);
				} else if (e != null && e.toString().contains("Font")) {
					setPlotFont();
					return true;
				} else if (e != null && e.toString().contains("Template")) {
					setTemplate();
					return true;
				}

				plot.setLineWidth((int) ogd.getNextNumber());
				plot.setMaxIntervals((int) ogd.getNextNumber());
				plot.setTickLength((int) ogd.getNextNumber());
				plot.setBackgroundColor(Colors.colors[ogd.getNextChoiceIndex()]);
				plot.updateImage();
				return true;

			}
		});
		showAsSubDialog(ogd);
		if (!ogd.wasOKed())
			return;
		if (!pwClosed)
			plot.getImagePlus().setTitle(WindowManager.makeUniqueName(ogd.getNextString()));

	}
 
Example 17
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
private void setPlotFont() {

		if (plot == null)
			return;

		final String[] FONTS = new String[] { Font.SANS_SERIF, Font.MONOSPACED, Font.SERIF };
		final String[] STYLES = { "Plain", "Bold", "Italic", "Bold+Italic" };
		final String[] JUSTIFICATIONS = { "Left", "Center", "Right" };
		final String[] SCOPES = { "Plot", "Both Axes Titles", "X-axis Title", "Y-axis Title" };
		final String[] CHOICE_DEFAULTS = { FONTS[0], STYLES[0], JUSTIFICATIONS[0], SCOPES[0] };
		final int[] INT_STYLES = { Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD + Font.ITALIC };
		final int[] INT_JUSTIFICATIONS = { Plot.LEFT, Plot.CENTER, Plot.RIGHT };
		final int DEF_SIZE = 12;
		final boolean DEF_ANTIALISED = true;

		final GenericDialog fgd = new GenericDialog("Font Options");
		fgd.addChoice("Type:", FONTS, CHOICE_DEFAULTS[0]);
		fgd.addChoice("Style:", STYLES, CHOICE_DEFAULTS[1]);
		fgd.addChoice("Justification:", JUSTIFICATIONS, CHOICE_DEFAULTS[2]);
		fgd.addSlider("Size:", 9, 24, DEF_SIZE);
		fgd.setInsets(0, 20, 15);
		fgd.addCheckbox("Antialiased text", DEF_ANTIALISED);
		fgd.addChoice("Apply to:", SCOPES, CHOICE_DEFAULTS[3]);
		fgd.hideCancelButton();
		fgd.addHelp("");
		fgd.setHelpLabel("Apply Defaults");
		fgd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					for (final Choice choice : nChoices)
						choice.select(CHOICE_DEFAULTS[nChoices.indexOf(choice)]);
					((TextField) gd.getNumericFields().get(0)).setText(Integer.toString(DEF_SIZE));
					((Checkbox) gd.getCheckboxes().get(0)).setState(DEF_ANTIALISED);
				}

				final String type = FONTS[fgd.getNextChoiceIndex()];
				final int style = INT_STYLES[fgd.getNextChoiceIndex()];
				final int justification = INT_JUSTIFICATIONS[fgd.getNextChoiceIndex()];
				final int size = (int) fgd.getNextNumber();
				final int scopeIdx = fgd.getNextChoiceIndex();

				plot.setJustification(justification);
				plot.setAntialiasedText(fgd.getNextBoolean());
				final Font font = new Font(type, style, size);
				switch (scopeIdx) {
				case 1: // SCOPES[1]
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				case 2: // SCOPES[2]
					plot.setXLabelFont(font);
					break;
				case 3: // SCOPES[3]
					plot.setYLabelFont(font);
					break;
				default:
					plot.setFont(font);
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				}

				plot.updateImage();
				return true;
			}
		});
		showAsSubDialog(fgd);
		if (!fgd.wasOKed())
			return;
	}
 
Example 18
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;
}
 
Example 19
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 20
Source File: Utils.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static public final void addRGBColorSliders(final GenericDialog gd, final Color color) {
	gd.addSlider("Red: ", 0, 255, color.getRed());
	gd.addSlider("Green: ", 0, 255, color.getGreen());
	gd.addSlider("Blue: ", 0, 255, color.getBlue());
}