use of uk.ac.sussex.gdsc.core.ij.ImageAdapter in project GDSC-SMLM by aherbert.
the class ConfigurationTemplate method showTemplateImages.
/**
* Show template images.
*
* @param settings the settings
*/
private void showTemplateImages(ConfigurationTemplateSettings.Builder settings) {
title = "Template Example Images";
final String[] names = getTemplateNamesWithImage();
if (names.length == 0) {
IJ.error(title, "No templates with example images");
return;
}
// Follow when the image slice is changed
ImageListener listener;
if (imp != null) {
listener = new ImageAdapter() {
@Override
public void imageUpdated(ImagePlus imp) {
if (imp == ConfigurationTemplate.this.imp) {
updateResults(imp.getCurrentSlice());
}
}
};
ImagePlus.addImageListener(listener);
} else {
listener = null;
}
final NonBlockingGenericDialog gd = new NonBlockingGenericDialog(title);
gd.addMessage("View the example source image");
gd.addChoice("Template", names, settings.getTemplate());
gd.addCheckbox("Close_on_exit", settings.getClose());
gd.hideCancelButton();
templateImage = true;
gd.addDialogListener(this::dialogItemChanged);
// Show the first template
final String template = ((Choice) (gd.getChoices().get(0))).getSelectedItem();
showTemplateImage(template);
gd.addHelp(HelpUrls.getUrl("template-manager-show-images"));
gd.showDialog();
// There is no cancel so read the settings.
settings.setTemplate(gd.getNextChoice());
settings.setClose(gd.getNextBoolean());
// This is null safe so always do this
ImagePlus.removeImageListener(listener);
if (settings.getClose()) {
if (imp != null) {
imp.close();
}
closeResults();
closeInfo();
}
}
use of uk.ac.sussex.gdsc.core.ij.ImageAdapter in project GDSC-SMLM by aherbert.
the class SpotFinderPreview method showDialog.
@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
settings = Settings.load();
this.overlay = imp.getOverlay();
this.imp = imp;
// Saved by reference so do it once now
settings.save();
// The image is locked by the PlugInFilterRunner so unlock it to allow scroll.
// This should be OK as the image data is not modified and only the overlay is
// adjusted. If another plugin changes the image then the preview should update
// the overlay and it will be obvious to the user to turn this plugin off.
imp.unlock();
config = SettingsManager.readFitEngineConfiguration(0);
fitConfig = config.getFitConfiguration();
gd = new NonBlockingExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("spot-finder-preview"));
gd.addMessage("Preview candidate maxima");
final String[] templates = ConfigurationTemplate.getTemplateNames(true);
gd.addChoice("Template", templates, templates[0]);
final String[] models = CameraModelManager.listCameraModels(true);
gd.addChoice("Camera_model_name", models, fitConfig.getCameraModelName());
PeakFit.addPsfOptions(gd, (FitConfigurationProvider) () -> fitConfig);
final PeakFit.SimpleFitEngineConfigurationProvider provider = new PeakFit.SimpleFitEngineConfigurationProvider(config);
PeakFit.addDataFilterOptions(gd, provider);
gd.addChoice("Spot_filter_2", SettingsManager.getDataFilterMethodNames(), config.getDataFilterMethod(1, settings.defaultDataFilterMethod).ordinal());
PeakFit.addRelativeParameterOptions(gd, new RelativeParameterProvider(2.5, 4.5, "Smoothing_2", provider) {
@Override
void setAbsolute(boolean absolute) {
final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
final DataFilterMethod m = c.getDataFilterMethod(1, settings.defaultDataFilterMethod);
final double smooth = c.getDataFilterParameterValue(1, settings.defaultSmooth);
c.setDataFilter(m, smooth, absolute, 1);
}
@Override
boolean isAbsolute() {
return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterAbsolute(1, false);
}
@Override
double getValue() {
return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterValue(1, settings.defaultSmooth);
}
});
PeakFit.addSearchOptions(gd, provider);
PeakFit.addBorderOptions(gd, provider);
// Find if this image was created with ground truth data
if (imp.getID() == CreateData.getImageId()) {
final MemoryPeakResults results = CreateData.getResults();
if (results != null) {
gd.addSlider("Match_distance", 0, 2.5, settings.distance);
gd.addSlider("Lower_match_distance (%)", 0, 100, settings.lowerDistance);
gd.addCheckbox("Multiple_matches", settings.multipleMatches);
gd.addCheckbox("Show_TP", settings.showTP);
gd.addCheckbox("Show_FP", settings.showFP);
gd.addMessage("");
label = (Label) gd.getMessage();
final boolean integerCoords = false;
actualCoordinates = ResultsMatchCalculator.getCoordinates(results, integerCoords);
}
}
if (label == null) {
// If no ground truth data add options to show the spots by their rank
// and number of neighbours
gd.addSlider("Top_N", 0, 100, settings.topN);
topNScrollBar = gd.getLastScrollbar();
gd.addSlider("Select", 0, 100, settings.select);
selectScrollBar = gd.getLastScrollbar();
gd.addSlider("Neigbour_radius", 0, 10, settings.neighbourRadius);
}
ImageListener imageListener = null;
if (ImageJUtils.isShowGenericDialog()) {
// Listen for changes in the dialog options
gd.addOptionCollectedListener(event -> {
// Just run on the current processor
if (preview) {
run(imp.getProcessor());
}
});
// Listen for changes to an image
imageListener = new ImageAdapter() {
@Override
public void imageUpdated(ImagePlus imp) {
if (SpotFinderPreview.this.imp.getID() == imp.getID() && preview && imp.getCurrentSlice() != currentSlice && filter != null) {
run(imp.getProcessor(), filter);
}
}
};
ImagePlus.addImageListener(imageListener);
// Support template settings
final Vector<TextField> numerics = gd.getNumericFields();
final Vector<Choice> choices = gd.getChoices();
final Iterator<TextField> nu = numerics.iterator();
final Iterator<Choice> ch = choices.iterator();
final Choice textTemplate = ch.next();
textTemplate.removeItemListener(gd);
textTemplate.removeKeyListener(gd);
textTemplate.addItemListener(this::itemStateChanged);
textCameraModelName = ch.next();
textPsf = ch.next();
textDataFilterType = ch.next();
textDataFilterMethod = ch.next();
textSmooth = nu.next();
textDataFilterMethod2 = ch.next();
textSmooth2 = nu.next();
textSearch = nu.next();
textBorder = nu.next();
}
gd.addPreviewCheckbox(pfr);
gd.addDialogListener(this::dialogItemChanged);
gd.setOKLabel("Save");
gd.setCancelLabel("Close");
gd.showDialog();
if (imageListener != null) {
ImagePlus.removeImageListener(imageListener);
}
if (!gd.wasCanceled() && !SettingsManager.writeSettings(config, SettingsManager.FLAG_SILENT)) {
IJ.error(TITLE, "Failed to save settings");
}
// Reset
imp.setOverlay(overlay);
return DONE;
}
use of uk.ac.sussex.gdsc.core.ij.ImageAdapter in project GDSC-SMLM by aherbert.
the class SpotAnalysis method run.
@Override
public void run(String arg) {
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (WindowManager.getImageCount() == 0) {
IJ.showMessage(PLUGIN_TITLE, "No images opened.");
return;
}
final Frame frame = instance.get();
if ("add".equals(arg)) {
if (frame != null) {
((SpotAnalysis) frame).addFrame();
}
return;
}
if (frame != null) {
frame.toFront();
return;
}
instance.set(this);
IJ.register(SpotAnalysis.class);
WindowManager.addWindow(this);
ImagePlus.addImageListener(new ImageAdapter() {
@Override
public void imageUpdated(ImagePlus imp) {
SpotAnalysis.this.imageUpdated(imp);
}
});
createFrame();
setup();
addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent event) {
switch(event.getKeyChar()) {
case 'a':
addFrame();
break;
case ',':
rawImp.setSlice(rawImp.getSlice() + 1);
break;
case '.':
rawImp.setSlice(rawImp.getSlice() - 1);
break;
default:
break;
}
}
});
pack();
final Point loc = Prefs.getLocation(OPT_LOCATION);
if (loc != null) {
setLocation(loc);
} else {
GUI.center(this);
}
if (IJ.isMacOSX()) {
setResizable(false);
}
setVisible(true);
// Install shortcut for adding a slice
final String command = "Spot Analysis (Add)";
final String shortcut = "6";
final String plugin = "ij.plugin.Hotkeys(" + "\"" + command + "\")";
Menus.installPlugin(plugin, Menus.SHORTCUTS_MENU, "*" + command, shortcut, IJ.getInstance());
}
use of uk.ac.sussex.gdsc.core.ij.ImageAdapter in project GDSC-SMLM by aherbert.
the class SmoothImage method setup.
@Override
public int setup(String arg, ImagePlus imp) {
if ("final".equals(arg)) {
imp.updateAndDraw();
return DONE;
}
SmlmUsageTracker.recordPlugin(this.getClass(), arg);
if (imp == null) {
IJ.noImage();
return DONE;
}
final Roi roi = imp.getRoi();
if (roi != null && roi.getType() != Roi.RECTANGLE) {
IJ.error("Rectangular ROI required");
return DONE;
}
// Support simultaneous contrast adjustment by saving the min/max
// only when in the preview.
imageId = imp.getID();
saveMinMax(imp);
ImagePlus.addImageListener(new ImageAdapter() {
@Override
public void imageUpdated(ImagePlus imp) {
// Only when the dialog is open
if (imp.getID() == imageId && dialogVisible) {
saveMinMax(imp);
}
}
});
return FLAGS;
}
Aggregations