use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource in project GDSC-SMLM by aherbert.
the class CameraModelManager method listCameraModels.
/**
* List the camera models with the correct dimensions.
*
* @param includeNone Set to true to include an empty string
* @param width the width
* @param height the height
* @return the list
*/
public static String[] listCameraModels(boolean includeNone, int width, int height) {
final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
final List<String> list = createList(includeNone);
for (final Map.Entry<String, CameraModelResource> entry : settings.getCameraModelResourcesMap().entrySet()) {
final CameraModelResource resource = entry.getValue();
if (resource.getWidth() == width && resource.getHeight() == height) {
list.add(entry.getKey());
}
}
return list.toArray(new String[0]);
}
use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource in project GDSC-SMLM by aherbert.
the class CameraModelManager method load.
/**
* Load the camera model. Returns null if the named model does not exist. Writes to the ImageJ log
* if a problems occurred loading the model.
*
* @param name the name
* @return the per pixel camera model (or null)
*/
public static PerPixelCameraModel load(String name) {
PerPixelCameraModel model = cameraModels.get(name);
if (model == null) {
final CameraModelSettings settings = CameraModelSettingsHolder.getSettings();
// Try and get the named resource
final CameraModelResource resource = settings.getCameraModelResourcesMap().get(name);
if (resource == null) {
return null;
}
model = loadFromFile(name, resource.getFilename());
// Cache this
cameraModels.put(name, model);
}
return model;
}
use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource in project GDSC-SMLM by aherbert.
the class CameraModelManager method runDeleteCameraModel.
private void runDeleteCameraModel(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-delete"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
final String name = gd.getNextChoice();
pluginSettings.setSelected(name);
final CameraModelResource resource = settings.getCameraModelResourcesMap().get(name);
if (resource == null) {
IJ.error(TITLE, "Failed to find camera data for model: " + name);
return;
}
CameraModelSettingsHolder.setSettings(settings.toBuilder().removeCameraModelResources(name).build());
ImageJUtils.log("Deleted camera model: %s\n%s", name, resource);
}
use of uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraModelResource 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();
}
}
Aggregations