Search in sources :

Example 1 with ExtendedStatistics

use of uk.ac.sussex.gdsc.core.utils.ExtendedStatistics in project GDSC-SMLM by aherbert.

the class CameraModelManager method runViewCameraModel.

private void runViewCameraModel(CameraModelSettings settings) {
    final GenericDialog gd = new GenericDialog(TITLE);
    final String[] models = listCameraModels(false);
    gd.addChoice("Model", models, pluginSettings.getSelected());
    gd.addHelp(HelpUrls.getUrl("camera-model-manager-view"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    final String name = gd.getNextChoice();
    pluginSettings.setSelected(name);
    // Try and get the named resource
    final CameraModelResource resource = settings.getCameraModelResourcesMap().get(name);
    if (resource == null) {
        IJ.error(TITLE, "Failed to find camera data for model: " + name);
        return;
    }
    // Try and load the resource.
    // Do not use loadFromFile as that validates the model data. We just want
    // to view the raw image.
    ImagePlus imp = IJ.openImage(resource.getFilename());
    // Remove the status from the ij.io.ImageWriter class
    IJ.showStatus("");
    if (imp == null) {
        IJ.error(TITLE, "Failed to load camera data for model: " + name);
        return;
    }
    final ImageStack stack = imp.getImageStack();
    if (stack.getSize() != 3) {
        IJ.error(TITLE, "Failed to load camera data for model: " + name + ".\nExpecting stack of size 3 but it was " + stack.getSize());
        return;
    }
    ImageJUtils.log("Camera model: %s\n%s", name, resource);
    for (int n = 1; n <= stack.getSize(); n++) {
        logStats(stack.getSliceLabel(n), stack.getProcessor(n));
    }
    // Show normalised variance: var/g^2
    final float[] varG2 = new float[stack.getWidth() * stack.getHeight()];
    try {
        final float[] gain = (float[]) stack.getPixels(2);
        final float[] variance = (float[]) stack.getPixels(3);
        final ExtendedStatistics stats1 = new ExtendedStatistics();
        final ExtendedStatistics stats2 = new ExtendedStatistics();
        for (int i = 0; i < gain.length; i++) {
            final double v1 = variance[i] / MathUtils.pow2(gain[i]);
            varG2[i] = (float) v1;
            stats1.add(Math.sqrt(v1));
            stats2.add(v1);
        }
        logStats("var/g^2", stats2);
        logStats("sqrt(var/g^2)", stats1);
    } catch (final Exception ex) {
        ImageJUtils.log("Failed to load camera model %s from file: %s. %s", name, resource.getFilename(), ex.getMessage());
    }
    stack.addSlice("var/g^2", varG2);
    // Create as a hyper stack
    imp = new ImagePlus(name, stack);
    imp.setDimensions(4, 1, 1);
    imp.setOpenAsHyperStack(true);
    final CompositeImage cimp = new CompositeImage(imp, CompositeImage.GRAYSCALE);
    cimp.resetDisplayRanges();
    for (int n = 1; n <= 4; n++) {
        cimp.setSliceWithoutUpdate(n);
        ImageJUtils.autoAdjust(cimp, true);
    }
    cimp.setSliceWithoutUpdate(1);
    imp = WindowManager.getImage(name);
    if (imp != null) {
        imp.setImage(cimp);
    } else {
        cimp.show();
    }
}
Also used : CameraModelResource(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource) ImageStack(ij.ImageStack) CompositeImage(ij.CompositeImage) GenericDialog(ij.gui.GenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) ExtendedStatistics(uk.ac.sussex.gdsc.core.utils.ExtendedStatistics)

Example 2 with ExtendedStatistics

use of uk.ac.sussex.gdsc.core.utils.ExtendedStatistics in project GDSC-SMLM by aherbert.

the class CameraModelManager method logStats.

private static void logStats(String name, ImageProcessor ip) {
    final ExtendedStatistics stats = new ExtendedStatistics();
    if (ip instanceof FloatProcessor) {
        stats.add((float[]) ip.getPixels());
    } else {
        for (int i = ip.getPixelCount(); i-- > 0; ) {
            stats.add(ip.getf(i));
        }
    }
    logStats(name, stats);
}
Also used : FloatProcessor(ij.process.FloatProcessor) ExtendedStatistics(uk.ac.sussex.gdsc.core.utils.ExtendedStatistics)

Aggregations

ExtendedStatistics (uk.ac.sussex.gdsc.core.utils.ExtendedStatistics)2 CompositeImage (ij.CompositeImage)1 ImagePlus (ij.ImagePlus)1 ImageStack (ij.ImageStack)1 GenericDialog (ij.gui.GenericDialog)1 FloatProcessor (ij.process.FloatProcessor)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 CameraModelResource (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource)1