use of qupath.lib.plugins.parameters.ParameterList in project qupath by qupath.
the class QuPathGUI method showSetupDialog.
/**
* Show a dialog requesting setup parameters
*
* @return
*/
public boolean showSetupDialog() {
// Show a setup message
Dialog<ButtonType> dialog = new Dialog<>();
dialog.setTitle("QuPath setup");
dialog.initOwner(getStage());
// Try to get an image to display
Image img = loadIcon(128);
BorderPane pane = new BorderPane();
if (img != null) {
StackPane imagePane = new StackPane(new ImageView(img));
imagePane.setPadding(new Insets(10, 10, 10, 10));
pane.setLeft(imagePane);
}
Map<String, Locale> localeMap = Arrays.stream(Locale.getAvailableLocales()).collect(Collectors.toMap(l -> l.getDisplayName(Locale.US), l -> l));
localeMap.remove("");
List<String> localeList = new ArrayList<>(localeMap.keySet());
Collections.sort(localeList);
long maxMemoryMB = Runtime.getRuntime().maxMemory() / 1024 / 1024;
String maxMemoryString = String.format("Current maximum memory is %.2f GB.", maxMemoryMB / 1024.0);
boolean canSetMemory = PathPrefs.hasJavaPreferences();
ParameterList paramsSetup = new ParameterList().addTitleParameter("Memory");
double originalMaxMemory = Math.ceil(maxMemoryMB / 1024.0);
if (canSetMemory) {
paramsSetup.addEmptyParameter("Set the maximum memory used by QuPath.");
// .addEmptyParameter(maxMemoryString);
boolean lowMemory = maxMemoryMB < 1024 * 6;
if (lowMemory) {
paramsSetup.addEmptyParameter("It is suggested to increase the memory limit to approximately\nhalf of the RAM available on your computer.");
}
paramsSetup.addDoubleParameter("maxMemoryGB", "Maximum memory", originalMaxMemory, "GB", "Set the maximum memory for Java.\n" + "Note that some commands (e.g. pixel classification) may still use more memory when needed,\n" + "so this value should generally not exceed half the total memory available on the system.");
} else {
paramsSetup.addEmptyParameter(maxMemoryString).addEmptyParameter("Sorry, I can't access the config file needed to change the max memory.\n" + "See the QuPath installation instructions for more details.");
}
paramsSetup.addTitleParameter("Region").addEmptyParameter("Set the region for QuPath to use for displaying numbers and messages.\n" + "Note: It is *highly recommended* to keep the default (English, US) region settings.\n" + "Support for regions that use different number formatting (e.g. commas as decimal marks)\n" + "is still experimental, and may give unexpected results.").addChoiceParameter("localeFormatting", "Numbers & dates", Locale.getDefault(Category.FORMAT).getDisplayName(), localeList, "Choose region settings used to format numbers and dates").addTitleParameter("Updates").addBooleanParameter("checkForUpdates", "Check for updates on startup (recommended)", PathPrefs.doAutoUpdateCheckProperty().get(), "Specify whether to automatically prompt to download the latest QuPath on startup (required internet connection)");
ParameterPanelFX parameterPanel = new ParameterPanelFX(paramsSetup);
pane.setCenter(parameterPanel.getPane());
Label labelMemory;
if (canSetMemory) {
labelMemory = new Label("You will need to restart QuPath for memory changes to take effect");
labelMemory.setStyle("-fx-font-weight: bold;");
labelMemory.setMaxWidth(Double.MAX_VALUE);
labelMemory.setAlignment(Pos.CENTER);
labelMemory.setFont(Font.font("Arial"));
labelMemory.setPadding(new Insets(10, 10, 10, 10));
pane.setBottom(labelMemory);
}
// dialog.initStyle(StageStyle.UNDECORATED);
dialog.getDialogPane().setContent(pane);
dialog.getDialogPane().getButtonTypes().setAll(ButtonType.APPLY, ButtonType.CANCEL);
Optional<ButtonType> result = dialog.showAndWait();
if (!result.isPresent() || !ButtonType.APPLY.equals(result.get()))
return false;
Locale localeFormatting = localeMap.get(paramsSetup.getChoiceParameterValue("localeFormatting"));
// Locale localeDisplay = localeMap.get(paramsSetup.getChoiceParameterValue("localeDisplay"));
PathPrefs.defaultLocaleFormatProperty().set(localeFormatting);
// PathPrefs.defaultLocaleDisplayProperty().set(localeDisplay);
PathPrefs.doAutoUpdateCheckProperty().set(paramsSetup.getBooleanParameterValue("checkForUpdates"));
if (canSetMemory && paramsSetup.containsKey("maxMemoryGB")) {
int maxMemorySpecifiedMB = (int) (Math.round(paramsSetup.getDoubleParameterValue("maxMemoryGB") * 1024));
if (maxMemorySpecifiedMB >= 1024) {
PathPrefs.maxMemoryMBProperty().set(maxMemorySpecifiedMB);
} else {
if (maxMemorySpecifiedMB >= 0)
Dialogs.showErrorNotification("Max memory setting", "Specified maximum memory setting too low - it must be at least 1 GB");
else
logger.warn("Requested max memory must be at least 1 GB - specified value {} will be ignored", paramsSetup.getDoubleParameterValue("maxMemoryGB"));
// PathPrefs.maxMemoryMBProperty().set(-1);
}
}
// Try to update display
if (getStage() != null && getStage().isShowing())
updateListsAndTables(getStage().getScene().getRoot());
return true;
}
use of qupath.lib.plugins.parameters.ParameterList in project qupath by qupath.
the class IntensityFeaturesPlugin method getDefaultParameterList.
@Override
public ParameterList getDefaultParameterList(final ImageData<BufferedImage> imageData) {
if (!parametersInitialized) {
params = new ParameterList();
// Regions & resolution
params.addTitleParameter("Resolution");
params.addDoubleParameter("downsample", "Downsample", 1, null, "Amount to downsample the image before calculating textures; choose 1 to use full resolution, or a higher value to use a smaller image").addDoubleParameter("pixelSizeMicrons", "Preferred pixel size", 2, GeneralTools.micrometerSymbol(), "Preferred pixel size of the image used to calculate the textures - higher values means coarser (lower resolution) images");
// Regions & resolution
params.addTitleParameter("Regions");
params.addChoiceParameter("region", "Region", RegionType.ROI, Arrays.asList(RegionType.values()), "The region within which to calculate the features");
params.addDoubleParameter("tileSizeMicrons", "Tile diameter", 25, GeneralTools.micrometerSymbol(), "Diameter of tile around the object centroid used to calculate textures.\nOnly matters if tiles are being used (i.e. the region parameter isn't ROI).");
params.addDoubleParameter("tileSizePixels", "Tile diameter", 200, "px (full resolution image)", "Diameter of tile around the object centroid used to calculate textures.\nOnly matters if tiles are being used (i.e. the region parameter isn't ROI).");
boolean hasMicrons = imageData.getServer().getPixelCalibration().hasPixelSizeMicrons();
params.getParameters().get("pixelSizeMicrons").setHidden(!hasMicrons);
params.getParameters().get("downsample").setHidden(hasMicrons);
params.getParameters().get("tileSizeMicrons").setHidden(!hasMicrons);
params.getParameters().get("tileSizePixels").setHidden(hasMicrons);
// Color transforms
params.addTitleParameter("Channels/Color transforms");
if (imageData.getServer().isRGB()) {
for (FeatureColorTransform transform : FeatureColorTransformEnum.values()) {
if (transform.supportsImage(imageData))
params.addBooleanParameter(transform.getKey(), transform.getPrompt(imageData), false);
}
} else {
for (FeatureColorTransform transform : getBasicChannelTransforms(imageData.getServer().nChannels())) {
params.addBooleanParameter(transform.getKey(), transform.getPrompt(imageData), false);
}
}
// Add feature-related parameters
for (FeatureComputerBuilder builder : builders) {
builder.addParameters(imageData, params);
}
}
parametersInitialized = true;
return params;
}
use of qupath.lib.plugins.parameters.ParameterList in project qupath by qupath.
the class DoGSuperpixelsPlugin method getDefaultParameterList.
@Override
public ParameterList getDefaultParameterList(ImageData<BufferedImage> imageData) {
ParameterList params = new ParameterList().addDoubleParameter("downsampleFactor", "Downsample factor", 8, null, "Downsample factor, used to determine the resolution of the image being processed").addDoubleParameter("sigmaPixels", "Gaussian sigma", 10, "px", "Sigma value used for smoothing; higher values result in larger regions being created").addDoubleParameter("sigmaMicrons", "Gaussian sigma", 10, GeneralTools.micrometerSymbol(), "Sigma value used for smoothing; higher values result in larger regions being created").addDoubleParameter("minThreshold", "Minimum intensity threshold", 10, null, "Regions with average values below this threshold will be discarded; this helps remove background or artefacts").addDoubleParameter("maxThreshold", "Maximum intensity threshold", 230, null, "Regions with average values above this threshold will be discarded; this helps remove background or artefacts").addDoubleParameter("noiseThreshold", "Noise threshold", 1, null, "Local threshold used to determine the number of regions created");
boolean hasMicrons = imageData != null && imageData.getServer().getPixelCalibration().hasPixelSizeMicrons();
params.getParameters().get("sigmaPixels").setHidden(hasMicrons);
params.getParameters().get("sigmaMicrons").setHidden(!hasMicrons);
return params;
}
use of qupath.lib.plugins.parameters.ParameterList in project qupath by qupath.
the class SLICSuperpixelsPlugin method getDefaultParameterList.
@Override
public ParameterList getDefaultParameterList(ImageData<BufferedImage> imageData) {
ParameterList params = new ParameterList().addTitleParameter("Size parameters").addDoubleParameter("sigmaPixels", "Gaussian sigma", 5, "px", "Adjust the Gaussian smoothing applied to the image, to reduce textures and give a smoother result").addDoubleParameter("sigmaMicrons", "Gaussian sigma", 5, GeneralTools.micrometerSymbol(), "Adjust the Gaussian smoothing applied to the image, to reduce textures and give a smoother result").addDoubleParameter("spacingPixels", "Superpixel spacing", 50, "px", "Control the (approximate) size of individual superpixels").addDoubleParameter("spacingMicrons", "Superpixel spacing", 50, GeneralTools.micrometerSymbol(), "Control the (approximate) size of individual superpixels").addTitleParameter("Algorithm parameters").addIntParameter("maxIterations", "Number of iterations", 10, null, "Maximum number of iterations to use for superpixel generation").addDoubleParameter("regularization", "Regularization", 0.25, null, "Control the 'squareness' of superpixels - higher values are more square").addBooleanParameter("adaptRegularization", "Auto-adapt regularization", false, "Automatically adapt regularization parameter for different superpixels").addBooleanParameter("useDeconvolved", "Use color deconvolved channels", false, "Use color-deconvolved values, rather than (standard) RGB->LAB colorspace transform");
boolean hasMicrons = imageData != null && imageData.getServer().getPixelCalibration().hasPixelSizeMicrons();
params.getParameters().get("sigmaPixels").setHidden(hasMicrons);
params.getParameters().get("sigmaMicrons").setHidden(!hasMicrons);
params.getParameters().get("spacingPixels").setHidden(hasMicrons);
params.getParameters().get("spacingMicrons").setHidden(!hasMicrons);
params.getParameters().get("useDeconvolved").setHidden(!(imageData.isBrightfield() && imageData.getColorDeconvolutionStains() != null && imageData.getServer().isRGB()));
return params;
}
use of qupath.lib.plugins.parameters.ParameterList in project qupath by qupath.
the class OMEPyramidWriterCommand method run.
@Override
public void run() {
if (currentTask != null && !currentTask.isDone()) {
if (!Dialogs.showConfirmDialog("OME Pyramid writer", "Do you want to stop the current export?"))
// TODO: Delete exporting file?
return;
else {
currentTask.cancel(true);
}
}
QuPathViewer viewer = qupath.getViewer();
int zPos = viewer.getZPosition();
int tPos = viewer.getTPosition();
ImageData<BufferedImage> imageData = viewer.getImageData();
if (imageData == null) {
Dialogs.showNoImageError("OME Pyramid writer");
return;
}
ImageServer<BufferedImage> server = imageData.getServer();
// Region
PathObject selected = imageData.getHierarchy().getSelectionModel().getSelectedObject();
ImageRegion region = null;
int width, height;
if (selected == null || !selected.hasROI() || !selected.getROI().isArea()) {
width = server.getWidth();
height = server.getHeight();
} else {
region = ImageRegion.createInstance(selected.getROI());
width = region.getWidth();
height = region.getHeight();
}
// Set compression - with a sanity check for validity, defaulting to another comparable method if necessary
CompressionType compression = getDefaultPyramidCompression();
List<String> compatibleCompression = Arrays.stream(CompressionType.values()).filter(c -> c.supportsImage(server)).map(c -> c.toFriendlyString()).collect(Collectors.toList());
if (!compatibleCompression.contains(compression.toFriendlyString()))
compression = CompressionType.DEFAULT;
var params = new ParameterList().addChoiceParameter("compression", "Compression type", compression.toFriendlyString(), compatibleCompression).addIntParameter("scaledDownsample", "Pyramidal downsample", scaledDownsample.get(), "", 1, 8, "Amount to downsample each consecutive pyramidal level; use 1 to indicate the image should not be pyramidal").addIntParameter("tileSize", "Tile size", getDefaultTileSize(), "px", "Tile size for export (should be between 128 and 8192)").addBooleanParameter("parallelize", "Parallelize export", parallelizeTiling.get(), "Export image tiles in parallel - " + "this should be faster, best keep it on unless you encounter export problems").addBooleanParameter("allZ", "All z-slices", allZ.get(), "Include all z-slices in the stack").addBooleanParameter("allT", "All timepoints", allT.get(), "Include all timepoints in the time-series");
boolean singleTile = server.getTileRequestManager().getTileRequests(RegionRequest.createInstance(server)).size() == 1;
params.setHiddenParameters(server.nZSlices() == 1, "allZ");
params.setHiddenParameters(server.nTimepoints() == 1, "allT");
params.setHiddenParameters(singleTile, "tileSize", "parallelize");
if (!Dialogs.showParameterDialog("Export OME-TIFF", params))
return;
compression = CompressionType.fromFriendlyString((String) params.getChoiceParameterValue("compression"));
defaultPyramidCompression.set(compression);
int downsampleScale = params.getIntParameterValue("scaledDownsample");
scaledDownsample.set(downsampleScale);
int tileSize = params.getIntParameterValue("tileSize");
boolean parallelize = params.getBooleanParameterValue("parallelize");
if (!singleTile) {
tileSize = GeneralTools.clipValue(tileSize, 128, 8192);
defaultTileSize.set(tileSize);
parallelizeTiling.set(parallelize);
}
boolean doAllZ = false;
boolean doAllT = false;
if (server.nZSlices() > 1) {
doAllZ = params.getBooleanParameterValue("allZ");
allZ.set(doAllZ);
}
if (server.nTimepoints() > 1) {
doAllT = params.getBooleanParameterValue("allT");
allT.set(doAllT);
}
OMEPyramidWriter.Builder builder = new OMEPyramidWriter.Builder(server);
if (region != null) {
builder = builder.region(region);
} else {
if (server.nZSlices() > 1 && !doAllZ)
builder.zSlice(zPos);
if (server.nTimepoints() > 1 && !doAllT)
builder.timePoint(tPos);
}
builder.compression(compression);
if (downsampleScale <= 1 || Math.max(width, height) / server.getDownsampleForResolution(0) < minSizeForTiling.get())
builder.downsamples(server.getDownsampleForResolution(0));
else
builder.scaledDownsampling(server.getDownsampleForResolution(0), downsampleScale);
// Set tile size; if we just have one tile, use the image width & height
if (singleTile)
builder = builder.tileSize(width, height);
else
builder = builder.tileSize(tileSize).parallelize(parallelize);
if (server.nZSlices() > 1 && doAllZ)
builder.allZSlices();
if (server.nTimepoints() > 1 && doAllT)
builder.allTimePoints();
// Prompt for file
File fileOutput = Dialogs.promptToSaveFile("Write pyramid", null, null, "OME TIFF pyramid", ".ome.tif");
if (fileOutput == null)
return;
String name = fileOutput.getName();
// We can have trouble with only the '.tif' part of the name being included
if (name.endsWith(".tif") && !name.endsWith(".ome.tif"))
fileOutput = new File(fileOutput.getParentFile(), name.substring(0, name.length() - 4) + ".ome.tif");
OMEPyramidSeries writer = builder.build();
if (pool == null) {
pool = Executors.newSingleThreadExecutor(ThreadTools.createThreadFactory("ome-pyramid-export", false));
}
currentTask = pool.submit(new WriterTask(OMEPyramidWriter.createWriter(writer), fileOutput.getAbsolutePath()));
}
Aggregations