use of uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType in project GDSC-SMLM by aherbert.
the class ImagePeakResultsFactory method createPeakResultsImage.
/**
* Create a PeakResults image using the specified parameters.
*
* <p>The image scale (coordinate-to-pixel mapping) is determined based on the configured
* settings. If the image scale cannot be set then the output image will be rendered using a
* 1-to-1 coordinates-to-pixel mapping. Note: The nm-per-pixel calibration of the results is
* required to correctly scale the image when rendering a fixed size output pixel. If not using a
* fixed size output pixel then this parameter is ignored.
*
* <p>A correct calibration can be added to the returned image using
* {@link uk.ac.sussex.gdsc.smlm.results.PeakResults#setCalibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration)
* PeakResults.setCalibration} before calling the
* {@link uk.ac.sussex.gdsc.smlm.results.PeakResults#begin()} method. Alternatively use the
* {@link ImageJImagePeakResults#setUncalibrated(boolean)} method to mark the image as
* uncalibrated.
*
* <p>No checks are made on the dimensions of the image. The {@link ImageJImagePeakResults} will
* throw an exception in the {@code begin()} method if the output image is too large to fit in a
* 2D array or there is not enough memory.
*
* @param resultsSettings The results image settings
* @param title The title of the image
* @param bounds Define the bounding rectangle of the result coordinates
* @param nmPerPixel The results scale in nanometers per pixel (ignored unless image type uses
* fixed size pixels)
* @return The PeakResults image
*/
public static ImageJImagePeakResults createPeakResultsImage(ResultsImageSettingsOrBuilder resultsSettings, String title, Rectangle bounds, double nmPerPixel) {
final ResultsImageType resultsImage = resultsSettings.getImageType();
final float imageScale = getScale(resultsSettings, bounds, nmPerPixel);
ImageJImagePeakResults image;
switch(resultsImage) {
case DRAW_FITTED_PSF:
case DRAW_INTENSITY_PRECISION:
case DRAW_LOCALISATIONS_PRECISION:
case DRAW_INTENSITY_AVERAGE_PRECISION:
case DRAW_LOCALISATIONS_AVERAGE_PRECISION:
// Special case for full PSF image
final PsfImagePeakResults image2 = new PsfImagePeakResults(title, bounds, imageScale);
if (resultsImage == ResultsImageType.DRAW_INTENSITY_AVERAGE_PRECISION || resultsImage == ResultsImageType.DRAW_LOCALISATIONS_AVERAGE_PRECISION) {
// Fixed width display (in pixels)
image2.setWidth((float) (((resultsSettings.getAveragePrecision() <= 0) ? nmPerPixel : resultsSettings.getAveragePrecision()) / nmPerPixel));
} else if (resultsImage == ResultsImageType.DRAW_INTENSITY_PRECISION || resultsImage == ResultsImageType.DRAW_LOCALISATIONS_PRECISION) {
image2.setCalculatedPrecision(true);
}
image = image2;
break;
default:
image = new ImageJImagePeakResults(title, bounds, imageScale);
}
int flags = 0;
switch(resultsImage) {
case DRAW_INTENSITY:
case DRAW_INTENSITY_PRECISION:
case DRAW_INTENSITY_AVERAGE_PRECISION:
case DRAW_FITTED_PSF:
flags |= ImageJImagePeakResults.DISPLAY_SIGNAL;
break;
case DRAW_FRAME_NUMBER:
flags |= ImageJImagePeakResults.DISPLAY_PEAK;
break;
case DRAW_FIT_ERROR:
flags |= ImageJImagePeakResults.DISPLAY_ERROR;
break;
case DRAW_Z_POSITION:
flags |= ImageJImagePeakResults.DISPLAY_Z_POSITION;
break;
case DRAW_ID:
flags |= ImageJImagePeakResults.DISPLAY_ID;
break;
default:
// Nothing to do for the other cases
break;
}
switch(resultsSettings.getImageMode()) {
case IMAGE_MAX:
flags |= ImageJImagePeakResults.DISPLAY_MAX;
break;
case IMAGE_REPLACE:
flags |= ImageJImagePeakResults.DISPLAY_REPLACE;
break;
default:
// Nothing to do for the other cases
break;
}
if (resultsSettings.getWeighted()) {
flags |= ImageJImagePeakResults.DISPLAY_WEIGHTED;
}
if (resultsSettings.getEqualised()) {
flags |= ImageJImagePeakResults.DISPLAY_EQUALIZED;
}
image.setDisplayFlags(flags);
image.setRollingWindowSize(resultsSettings.getRollingWindowSize());
image.setLutName(resultsSettings.getLutName());
return image;
}
use of uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType in project GDSC-SMLM by aherbert.
the class ResultsManager method addImageResultsOptions.
/**
* Adds the image results options.
*
* <p>Note: If using the option {@link #FLAG_IMAGE_REMOVE_NONE} then the integer value returned
* from the dialog choice should be offset by 1.
*
* <pre>
* ExtendedGenericDialog gd;
* ResultsSettings.Builder settings;
* ResultsManager.addImageResultsOptions(gd, settings, ResultsManager.FLAG_IMAGE_REMOVE_NONE);
* // ...
* settings.getResultsImageSettings().setImageTypeValue(gd.getNextChoiceIndex() + 1);
* </pre>
*
* @param gd the dialog
* @param resultsSettings the results settings
* @param flags the flags
*/
public static void addImageResultsOptions(final ExtendedGenericDialog gd, final Builder resultsSettings, final int flags) {
if (BitFlagUtils.anyNotSet(flags, FLAG_NO_SECTION_HEADER)) {
gd.addMessage("--- Image output ---");
}
final ResultsImageSettings.Builder imageSettings = resultsSettings.getResultsImageSettingsBuilder();
final EnumSet<ResultsImageType> requirePrecision = EnumSet.of(ResultsImageType.DRAW_LOCALISATIONS_AVERAGE_PRECISION, ResultsImageType.DRAW_INTENSITY_AVERAGE_PRECISION);
final EnumSet<ResultsImageType> requireWeighted = EnumSet.of(ResultsImageType.DRAW_LOCALISATIONS, ResultsImageType.DRAW_INTENSITY, ResultsImageType.DRAW_FRAME_NUMBER, ResultsImageType.DRAW_FIT_ERROR);
String[] names = SettingsManager.getResultsImageTypeNames();
final int offset = BitFlagUtils.areSet(flags, FLAG_IMAGE_REMOVE_NONE) ? 1 : 0;
if (offset != 0) {
names = Arrays.copyOfRange(names, 1, names.length);
}
gd.addChoice("Image", names, imageSettings.getImageTypeValue() - offset, new OptionListener<Integer>() {
@Override
public boolean collectOptions(Integer field) {
imageSettings.setImageTypeValue(field + offset);
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ResultsImageType resultsImage = imageSettings.getImageType();
if (resultsImage.getNumber() <= 0) {
return false;
}
final boolean isExtraOptions = BitFlagUtils.anySet(flags, FLAG_EXTRA_OPTIONS);
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE, null);
if (requireWeighted.contains(resultsImage)) {
egd.addCheckbox("Weighted", imageSettings.getWeighted());
}
egd.addCheckbox("Equalised", imageSettings.getEqualised());
if (requirePrecision.contains(resultsImage)) {
egd.addSlider("Image_Precision (nm)", 5, 30, imageSettings.getAveragePrecision());
}
egd.addChoice("Image_Size_mode", SettingsManager.getResultsImageSizeModeNames(), imageSettings.getImageSizeModeValue());
final Choice choice = egd.getLastChoice();
// Selectively show the fields based on the image size mode
final Label[] labels = new Label[3];
final Panel[] panels = new Panel[3];
// Adds a Label and Panel
egd.addSlider("Image_Scale", 1, 15, imageSettings.getScale());
labels[0] = egd.getLabel();
panels[0] = egd.getLastPanel();
// Adds a Label and Panel (panel contains a label)
egd.addNumericField("Image_Size", imageSettings.getImageSize(), 0, 6, "px");
labels[1] = egd.getLabel();
panels[1] = egd.getLastPanel();
// Adds a Label and Panel
egd.addSlider("Image_Pixel_size (nm)", 5, 30, imageSettings.getPixelSize());
labels[2] = egd.getLabel();
panels[2] = egd.getLastPanel();
// Setting each to visible = false does not work without manually revalidating.
// The alternative is to remove the components and add back the one to draw.
// This requires storing the constraints of the component when first added
// to the grid layout or controlling a dedicated display panel.
// Here the first option is used to simplify supporting any underlying layout.
// It relies on the layout manager to process and ignore the invisible components.
final ItemListener l = e -> {
for (int i = 0; i < panels.length; i++) {
labels[i].setVisible(false);
panels[i].setVisible(false);
}
final int index = choice.getSelectedIndex();
labels[index].setVisible(true);
panels[index].setVisible(true);
labels[index].revalidate();
panels[index].revalidate();
};
l.itemStateChanged(null);
choice.addItemListener(l);
if (isExtraOptions) {
egd.addNumericField("Image_Window", imageSettings.getRollingWindowSize(), 0);
}
if (BitFlagUtils.anyNotSet(flags, FLAG_IMAGE_NO_LUT)) {
egd.addChoice("LUT", LutHelper.getLutNames(), imageSettings.getLutName());
}
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
if (requireWeighted.contains(resultsImage)) {
imageSettings.setWeighted(egd.getNextBoolean());
}
imageSettings.setEqualised(egd.getNextBoolean());
if (requirePrecision.contains(resultsImage)) {
imageSettings.setAveragePrecision(egd.getNextNumber());
}
imageSettings.setImageSizeModeValue(egd.getNextChoiceIndex());
imageSettings.setScale(egd.getNextNumber());
imageSettings.setImageSize((int) egd.getNextNumber());
imageSettings.setPixelSize(egd.getNextNumber());
if (isExtraOptions) {
imageSettings.setRollingWindowSize((int) egd.getNextNumber());
}
if (BitFlagUtils.anyNotSet(flags, FLAG_IMAGE_NO_LUT)) {
imageSettings.setLutName(egd.getNextChoice());
}
return true;
}
});
}
Aggregations