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();
}
}
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);
}
Aggregations