use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class RegisterImages method addManualMeasurements.
static void addManualMeasurements(Image image, AbstractAffineModel2D model) {
AffineTransform transform = model.createAffine();
image.addMeasurement(new Measurement(Measurements.TRANSLATE_X, transform.getTranslateX()));
image.addMeasurement(new Measurement(Measurements.TRANSLATE_Y, transform.getTranslateY()));
image.addMeasurement(new Measurement(Measurements.SCALE_X, transform.getScaleX()));
image.addMeasurement(new Measurement(Measurements.SCALE_Y, transform.getScaleY()));
image.addMeasurement(new Measurement(Measurements.SHEAR_X, transform.getShearX()));
image.addMeasurement(new Measurement(Measurements.SHEAR_Y, transform.getShearY()));
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class RectangleHoughDetection method process.
@Override
public Status process(Workspace workspace) {
// Getting input image
String inputImageName = parameters.getValue(INPUT_IMAGE);
Image inputImage = workspace.getImage(inputImageName);
ImagePlus ipl = inputImage.getImagePlus();
// Getting parameters
String outputObjectsName = parameters.getValue(OUTPUT_OBJECTS);
boolean outputTransformImage = parameters.getValue(OUTPUT_TRANSFORM_IMAGE);
String outputImageName = parameters.getValue(OUTPUT_IMAGE);
// Getting parameters
String xRange = parameters.getValue(X_RANGE);
String yRange = parameters.getValue(Y_RANGE);
String widthRange = parameters.getValue(WIDTH_RANGE);
String lengthRange = parameters.getValue(LENGTH_RANGE);
String oriRange = parameters.getValue(ORIENTATION_RANGE);
int samplingRate = parameters.getValue(DOWNSAMPLE_FACTOR);
boolean multithread = parameters.getValue(ENABLE_MULTITHREADING);
boolean normaliseScores = parameters.getValue(NORMALISE_SCORES);
String detectionMode = parameters.getValue(DETECTION_MODE);
double detectionThreshold = parameters.getValue(DETECTION_THRESHOLD);
int nObjects = parameters.getValue(NUMBER_OF_OBJECTS);
int exclusionRadius = parameters.getValue(EXCLUSION_RADIUS);
boolean showTransformImage = parameters.getValue(SHOW_TRANSFORM_IMAGE);
boolean showDetectionImage = parameters.getValue(SHOW_DETECTION_IMAGE);
boolean showHoughScore = parameters.getValue(SHOW_HOUGH_SCORE);
int labelSize = parameters.getValue(LABEL_SIZE);
// Storing the image calibration
SpatCal cal = SpatCal.getFromImage(ipl);
int nFrames = ipl.getNFrames();
double frameInterval = ipl.getCalibration().frameInterval;
Objs outputObjects = new Objs(outputObjectsName, cal, nFrames, frameInterval, TemporalUnit.getOMEUnit());
xRange = resampleRange(xRange, samplingRate);
yRange = resampleRange(yRange, samplingRate);
widthRange = resampleRange(widthRange, samplingRate);
lengthRange = resampleRange(lengthRange, samplingRate);
int nThreads = multithread ? Prefs.getThreads() : 1;
// Iterating over all images in the ImagePlus
int count = 1;
int total = ipl.getNChannels() * ipl.getNSlices() * ipl.getNFrames();
for (int c = 0; c < ipl.getNChannels(); c++) {
for (int z = 0; z < ipl.getNSlices(); z++) {
for (int t = 0; t < ipl.getNFrames(); t++) {
ipl.setPosition(c + 1, z + 1, t + 1);
// Applying scaling
ImageProcessor ipr = ipl.getProcessor();
if (samplingRate != 1)
ipr = ipr.resize(ipr.getWidth() / samplingRate);
// Initialising the Hough transform
String[] paramRanges = new String[] { xRange, yRange, widthRange, lengthRange, oriRange };
RectangleTransform transform = new RectangleTransform(ipr, paramRanges);
transform.setnThreads(nThreads);
// Running the transforms
transform.run();
// Normalising scores based on the number of points in that rectangle
if (normaliseScores)
transform.normaliseScores();
// Getting the accumulator as an image
if (outputTransformImage || (showOutput && showTransformImage)) {
ImagePlus showIpl = new Duplicator().run(transform.getAccumulatorAsImage());
if (outputTransformImage) {
Image outputImage = new Image(outputImageName, showIpl);
workspace.addImage(outputImage);
}
if (showOutput && showTransformImage) {
IntensityMinMax.run(showIpl, true);
showIpl.setTitle("Accumulator");
showIpl.show();
}
}
// Getting rectangle objects and adding to workspace
ArrayList<double[]> rectangles;
switch(detectionMode) {
default:
case DetectionModes.ALL_ABOVE_SCORE:
rectangles = transform.getObjects(detectionThreshold, exclusionRadius);
break;
case DetectionModes.N_HIGHEST_SCORES:
rectangles = transform.getNObjects(nObjects, exclusionRadius);
break;
}
for (double[] rectangle : rectangles) {
// Initialising the object
Obj outputObject = outputObjects.createAndAddNewObject(VolumeType.QUADTREE);
// Getting rectangle parameters
int x = (int) Math.round(rectangle[0]) * samplingRate;
int y = (int) Math.round(rectangle[1]) * samplingRate;
int w = (int) Math.round(rectangle[2]) * samplingRate;
int l = (int) Math.round(rectangle[3]) * samplingRate;
int ori = (int) Math.round(rectangle[4]);
double score = rectangle[5];
double thetaRads = -Math.toRadians((double) ori);
int x1 = (int) Math.round((-l / 2) * Math.cos(thetaRads));
int y1 = (int) Math.round(-(-l / 2) * Math.sin(thetaRads));
RotatedRectRoi roi = new RotatedRectRoi(x + x1, y + y1, x - x1, y - y1, w);
for (Point point : roi.getContainedPoints()) {
try {
try {
outputObject.add(point.x, point.y, z);
} catch (PointOutOfRangeException e) {
}
} catch (IntegerOverflowException e) {
return Status.FAIL;
}
}
// Adding measurements
outputObject.setT(t);
outputObject.addMeasurement(new Measurement(Measurements.SCORE, score));
}
writeProgressStatus(count++, total, "images");
}
}
}
ipl.setPosition(1, 1, 1);
workspace.addObjects(outputObjects);
if (showOutput && showDetectionImage)
showDetectionImage(inputImage, outputObjects, showHoughScore, labelSize);
return Status.PASS;
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class ColourFactoryTest method testGetColoursMeasurementColour.
@ParameterizedTest
@EnumSource(VolumeType.class)
public void testGetColoursMeasurementColour(VolumeType volumeType) {
// Setting calibration parameters
double dppXY = 0.02;
double dppZ = 0.1;
String calibratedUnits = "µm";
SpatCal calibration = new SpatCal(dppXY, dppZ, calibratedUnits, 1, 1, 1);
// Creating the Objs
Objs collection = new Objs("Obj", calibration, 1, 0.02, UNITS.SECOND);
// Adding objects
Obj obj = collection.createAndAddNewObject(volumeType, 0);
Measurement meas = new Measurement("Meas", 3.2);
obj.addMeasurement(meas);
collection.add(obj);
obj = collection.createAndAddNewObject(volumeType, 1);
meas = new Measurement("Meas", -0.1);
obj.addMeasurement(meas);
collection.add(obj);
obj = collection.createAndAddNewObject(volumeType, 2);
meas = new Measurement("Meas", Double.NaN);
obj.addMeasurement(meas);
collection.add(obj);
HashMap<Integer, Float> hues = ColourFactory.getMeasurementValueHues(collection, "Meas", false, new double[] { Double.NaN, Double.NaN });
HashMap<Integer, Color> actual = ColourFactory.getColours(hues, 100);
// For random numbers we don't know what value they will have
assertEquals(3, actual.size());
assertEquals(Color.getHSBColor(3.2f, 1f, 1f), actual.get(0));
assertEquals(Color.getHSBColor(-0.1f, 1f, 1f), actual.get(1));
assertEquals(Color.getHSBColor(1f, 1f, 1f), actual.get(2));
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class ColourFactoryTest method testGetHuesIDColourNormalised.
@ParameterizedTest
@EnumSource(VolumeType.class)
public void testGetHuesIDColourNormalised(VolumeType volumeType) {
// Setting calibration parameters
double dppXY = 0.02;
double dppZ = 0.1;
String calibratedUnits = "µm";
SpatCal calibration = new SpatCal(dppXY, dppZ, calibratedUnits, 1, 1, 1);
// Creating the Objs
Objs collection = new Objs("Obj", calibration, 1, 0.02, UNITS.SECOND);
// Adding objects
Obj obj = collection.createAndAddNewObject(volumeType, 0);
Measurement meas = new Measurement("Meas", 3.2);
obj.addMeasurement(meas);
collection.add(obj);
obj = collection.createAndAddNewObject(volumeType, 1);
meas = new Measurement("Meas", -0.1);
obj.addMeasurement(meas);
collection.add(obj);
obj = collection.createAndAddNewObject(volumeType, 2);
meas = new Measurement("Meas", Double.NaN);
obj.addMeasurement(meas);
collection.add(obj);
HashMap<Integer, Float> actual = ColourFactory.getIDHues(collection, true);
// For random numbers we don't know what value they will have
assertEquals(3, actual.size());
assertEquals(0f, actual.get(0), tolerance);
assertEquals(0.06f, actual.get(1), tolerance);
assertEquals(0.13f, actual.get(2), tolerance);
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class LabelFactoryTest method testGetIDsMeasurement.
@ParameterizedTest
@EnumSource(VolumeType.class)
public void testGetIDsMeasurement(VolumeType volumeType) {
// Setting calibration parameters
double dppXY = 0.02;
double dppZ = 0.1;
String calibratedUnits = "µm";
SpatCal calibration = new SpatCal(dppXY, dppZ, calibratedUnits, 1, 1, 1);
// Creating the Objs
Objs collection = new Objs("Obj", calibration, 1, 0.02, UNITS.SECOND);
// Adding objects
Obj obj = collection.createAndAddNewObject(volumeType, 0);
Measurement meas = new Measurement("Meas", 3.2);
obj.addMeasurement(meas);
obj = collection.createAndAddNewObject(volumeType, 1);
meas = new Measurement("Meas", -0.1);
obj.addMeasurement(meas);
obj = collection.createAndAddNewObject(volumeType, 2);
meas = new Measurement("Meas", Double.NaN);
obj.addMeasurement(meas);
DecimalFormat df = LabelFactory.getDecimalFormat(2, false);
HashMap<Integer, String> actual = LabelFactory.getMeasurementLabels(collection, "Meas", df);
assertEquals(3, actual.size());
assertEquals("3.20", actual.get(0));
assertEquals("-0.10", actual.get(1));
assertEquals("NA", actual.get(2));
}
Aggregations