use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.
the class MeasurementManager method promptToRemoveMeasurements.
private boolean promptToRemoveMeasurements() {
var selectedItems = new ArrayList<>(listView.getSelectionModel().getSelectedItems());
if (selectedItems.isEmpty()) {
Dialogs.showErrorMessage("Remove measurements", "No measurements selected!");
return false;
}
String number = selectedItems.size() == 1 ? String.format("'%s'", selectedItems.iterator().next()) : selectedItems.size() + " measurements";
if (!Dialogs.showConfirmDialog("Remove measurements", "Are you sure you want to permanently remove " + number + "?"))
return false;
String removeString = selectedItems.stream().map(m -> "\"" + m + "\"").collect(Collectors.joining(", "));
logger.info("Removing measurements: {}", removeString);
Class<? extends PathObject> cls = comboBox.getSelectionModel().getSelectedItem();
QP.removeMeasurements(imageData.getHierarchy(), cls, selectedItems.toArray(String[]::new));
// Keep for scripting
WorkflowStep step = new DefaultScriptableWorkflowStep("Remove measurements", String.format("removeMeasurements(%s, %s);", cls.getName(), removeString));
imageData.getHistoryWorkflow().addStep(step);
// Update
refreshMeasurements();
updateCurrentList();
filterText.set("");
return true;
}
use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.
the class ImageData method addColorDeconvolutionStainsToWorkflow.
// TODO: REINTRODUCE LOGGING!
private static void addColorDeconvolutionStainsToWorkflow(ImageData<?> imageData) {
// logger.warn("Color deconvolution stain logging not currently enabled!");
ColorDeconvolutionStains stains = imageData.getColorDeconvolutionStains();
if (stains == null) {
return;
}
String arg = ColorDeconvolutionStains.getColorDeconvolutionStainsAsString(imageData.getColorDeconvolutionStains(), 5);
Map<String, String> map = GeneralTools.parseArgStringValues(arg);
WorkflowStep lastStep = imageData.getHistoryWorkflow().getLastStep();
String commandName = "Set color deconvolution stains";
WorkflowStep newStep = new DefaultScriptableWorkflowStep(commandName, map, "setColorDeconvolutionStains(\'" + arg + "');");
// else
if (!Objects.equals(newStep, lastStep))
imageData.getHistoryWorkflow().addStep(newStep);
// ColorDeconvolutionStains stains = imageData.getColorDeconvolutionStains();
// if (stains == null)
// return;
//
// String arg = ColorDeconvolutionStains.getColorDeconvolutionStainsAsString(imageData.getColorDeconvolutionStains(), 5);
// Map<String, String> map = GeneralTools.parseArgStringValues(arg);
// WorkflowStep lastStep = imageData.getWorkflow().getLastStep();
// String commandName = "Set color deconvolution stains";
// WorkflowStep newStep = new DefaultScriptableWorkflowStep(commandName,
// map,
// QP.class.getSimpleName() + ".setColorDeconvolutionStains(\'" + arg + "');");
//
// if (lastStep != null && commandName.equals(lastStep.getName()))
// imageData.getWorkflow().replaceLastStep(newStep);
// else
// imageData.getWorkflow().addStep(newStep);
}
use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.
the class ImageDetailsPane method promptToSetPixelSize.
static boolean promptToSetPixelSize(ImageData<BufferedImage> imageData, boolean requestZSpacing) {
var server = imageData.getServer();
var hierarchy = imageData.getHierarchy();
var selected = hierarchy.getSelectionModel().getSelectedObject();
var roi = selected == null ? null : selected.getROI();
PixelCalibration cal = server.getPixelCalibration();
double pixelWidthMicrons = cal.getPixelWidthMicrons();
double pixelHeightMicrons = cal.getPixelHeightMicrons();
double zSpacingMicrons = cal.getZSpacingMicrons();
// Use line or area ROI if possible
if (!requestZSpacing && roi != null && !roi.isEmpty() && (roi.isArea() || roi.isLine())) {
boolean setPixelHeight = true;
boolean setPixelWidth = true;
String message;
String units = GeneralTools.micrometerSymbol();
double pixelWidth = cal.getPixelWidthMicrons();
double pixelHeight = cal.getPixelHeightMicrons();
if (!Double.isFinite(pixelWidth))
pixelWidth = 1;
if (!Double.isFinite(pixelHeight))
pixelHeight = 1;
Double defaultValue = null;
if (roi.isLine()) {
setPixelHeight = roi.getBoundsHeight() != 0;
setPixelWidth = roi.getBoundsWidth() != 0;
message = "Enter selected line length";
defaultValue = roi.getScaledLength(pixelWidth, pixelHeight);
} else {
message = "Enter selected ROI area";
units = units + "^2";
defaultValue = roi.getScaledArea(pixelWidth, pixelHeight);
}
// }
if (Double.isNaN(defaultValue))
defaultValue = 1.0;
var params = new ParameterList().addDoubleParameter("inputValue", message, defaultValue, units, "Enter calibrated value in " + units + " for the selected ROI to calculate the pixel size").addBooleanParameter("squarePixels", "Assume square pixels", true, "Set the pixel width to match the pixel height");
params.setHiddenParameters(setPixelHeight && setPixelWidth, "squarePixels");
if (!Dialogs.showParameterDialog("Set pixel size", params))
return false;
Double result = params.getDoubleParameterValue("inputValue");
setPixelHeight = setPixelHeight || params.getBooleanParameterValue("squarePixels");
setPixelWidth = setPixelWidth || params.getBooleanParameterValue("squarePixels");
// Double result = Dialogs.showInputDialog("Set pixel size", message, defaultValue);
// if (result == null)
// return false;
double sizeMicrons;
if (roi.isLine())
sizeMicrons = result.doubleValue() / roi.getLength();
else
sizeMicrons = Math.sqrt(result.doubleValue() / roi.getArea());
if (setPixelHeight)
pixelHeightMicrons = sizeMicrons;
if (setPixelWidth)
pixelWidthMicrons = sizeMicrons;
} else {
// Prompt for all required values
ParameterList params = new ParameterList().addDoubleParameter("pixelWidth", "Pixel width", pixelWidthMicrons, GeneralTools.micrometerSymbol(), "Enter the pixel width").addDoubleParameter("pixelHeight", "Pixel height", pixelHeightMicrons, GeneralTools.micrometerSymbol(), "Entry the pixel height").addDoubleParameter("zSpacing", "Z-spacing", zSpacingMicrons, GeneralTools.micrometerSymbol(), "Enter the spacing between slices of a z-stack");
params.setHiddenParameters(server.nZSlices() == 1, "zSpacing");
if (!Dialogs.showParameterDialog("Set pixel size", params))
return false;
if (server.nZSlices() != 1) {
zSpacingMicrons = params.getDoubleParameterValue("zSpacing");
}
pixelWidthMicrons = params.getDoubleParameterValue("pixelWidth");
pixelHeightMicrons = params.getDoubleParameterValue("pixelHeight");
}
if ((pixelWidthMicrons <= 0 || pixelHeightMicrons <= 0) || (server.nZSlices() > 1 && zSpacingMicrons <= 0)) {
if (!Dialogs.showConfirmDialog("Set pixel size", "You entered values <= 0, do you really want to remove this pixel calibration information?")) {
return false;
}
zSpacingMicrons = server.nZSlices() > 1 && zSpacingMicrons > 0 ? zSpacingMicrons : Double.NaN;
if (pixelWidthMicrons <= 0 || pixelHeightMicrons <= 0) {
pixelWidthMicrons = Double.NaN;
pixelHeightMicrons = Double.NaN;
}
}
if (QP.setPixelSizeMicrons(imageData, pixelWidthMicrons, pixelHeightMicrons, zSpacingMicrons)) {
// Log for scripts
WorkflowStep step;
if (server.nZSlices() == 1) {
var map = Map.of("pixelWidthMicrons", pixelWidthMicrons, "pixelHeightMicrons", pixelHeightMicrons);
String script = String.format("setPixelSizeMicrons(%f, %f)", pixelWidthMicrons, pixelHeightMicrons);
step = new DefaultScriptableWorkflowStep("Set pixel size " + GeneralTools.micrometerSymbol(), map, script);
} else {
var map = Map.of("pixelWidthMicrons", pixelWidthMicrons, "pixelHeightMicrons", pixelHeightMicrons, "zSpacingMicrons", zSpacingMicrons);
String script = String.format("setPixelSizeMicrons(%f, %f, %f)", pixelWidthMicrons, pixelHeightMicrons, zSpacingMicrons);
step = new DefaultScriptableWorkflowStep("Set pixel size " + GeneralTools.micrometerSymbol(), map, script);
}
imageData.getHistoryWorkflow().addStep(step);
return true;
} else
return false;
}
use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.
the class Commands method selectObjectsByClass.
/**
* Select objects that are instances of a specified class, logging an appropriate method in the workflow.
*
* @param imageData
* @param cls
*/
public static void selectObjectsByClass(final ImageData<?> imageData, final Class<? extends PathObject> cls) {
if (cls == TMACoreObject.class)
QP.selectTMACores(imageData.getHierarchy());
else
QP.selectObjectsByClass(imageData.getHierarchy(), cls);
Map<String, String> params = Collections.singletonMap("Type", PathObjectTools.getSuitableName(cls, false));
String method;
if (cls == PathAnnotationObject.class)
method = "selectAnnotations();";
else if (cls == PathDetectionObject.class)
method = "selectDetections();";
else if (cls == TMACoreObject.class)
method = "selectTMACores();";
else if (cls == PathCellObject.class)
method = "selectCells();";
else if (cls == PathTileObject.class)
method = "selectTiles();";
else
// TODO: Get a suitable name to disguise Java classes
method = "selectObjectsByClass(" + cls.getName() + ");";
WorkflowStep newStep = new DefaultScriptableWorkflowStep("Select objects by class", params, method);
WorkflowStep lastStep = imageData.getHistoryWorkflow().getLastStep();
if (newStep.equals(lastStep))
imageData.getHistoryWorkflow().replaceLastStep(newStep);
else
imageData.getHistoryWorkflow().addStep(newStep);
}
use of qupath.lib.plugins.workflow.WorkflowStep in project qupath by qupath.
the class Commands method selectAllObjects.
/**
* Select all objects (excluding the root object) in the imageData.
*
* @param imageData
*/
public static void selectAllObjects(final ImageData<?> imageData) {
// Select all objects
QP.selectAllObjects(imageData.getHierarchy(), false);
// Add this step to the history workflow
Map<String, String> map = new HashMap<>();
map.put("includeRootObject", "false");
WorkflowStep newStep = new DefaultScriptableWorkflowStep("Select all objects", map, "selectAllObjects(false)");
imageData.getHistoryWorkflow().addStep(newStep);
}
Aggregations