Skip to content

Commit

Permalink
Added duplicate objects module
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcross committed Aug 19, 2024
1 parent af2b478 commit 13fb5b6
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ public PartnerRefs updateAndGetPartnerRefs() {

switch ((String) parameters.getValue(FILTER_MODE, workspace)) {
case FilterModes.MOVE_FILTERED:
String inputObjectsName = parameters.getValue(INPUT_OBJECTS, workspace);
String outputObjectsName = parameters.getValue(OUTPUT_FILTERED_OBJECTS, workspace);

// Getting references up to this location
PartnerRefs currentRefs = modules.getPartnerRefs(this);

// Adding relationships
String[] partnerNames = currentRefs.getPartnerNamesArray(inputObjectsName);
String[] partnerNames = currentRefs.getPartnerNamesArray(outputObjectsName);
for (String partnerName : partnerNames)
returnedRefs.add(partnerRefs.getOrPut(inputObjectsName, partnerName));
returnedRefs.add(partnerRefs.getOrPut(outputObjectsName, partnerName));

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public Measurement(String name, double value) {
this.value = value;
}

public Measurement duplicate() {
return new Measurement(getName(), getValue());
}


// GETTERS AND SETTERS

Expand Down
43 changes: 42 additions & 1 deletion mia-core/src/main/java/io/github/mianalysis/mia/object/Obj.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public Obj getParent(String name) {
// If the first parent was the only one listed, returning this
if (elements.length == 1)
return parent;

// If there are additional parents listed, re-constructing the string and
// running this method on the parent
StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -622,6 +622,47 @@ public void clearAllCoordinates() {
rois = new HashMap<>();
}

public Obj duplicate(Objs newCollection, boolean duplicateRelationships, boolean duplicateMeasurement,
boolean duplicateMetadata) {
Obj newObj = new Obj(newCollection, getID(), this);

// Duplicating coordinates
newObj.setCoordinateSet(getCoordinateSet().duplicate());

// Duplicating relationships
if (duplicateRelationships) {
for (Obj parent : parents.values()) {
newObj.addParent(parent);
parent.addChild(this);
}

for (Objs currChildren : children.values())
for (Obj child : currChildren.values()) {
newObj.addChild(child);
child.addParent(newObj);
}

for (Objs currPartners : partners.values())
for (Obj partner : currPartners.values()) {
newObj.addPartner(partner);
partner.addPartner(newObj);
}
}

// Duplicating measurements
if (duplicateMeasurement)
for (Measurement measurement : measurements.values())
newObj.addMeasurement(measurement.duplicate());

// Duplicating metadata
if (duplicateMetadata)
for (ObjMetadata metadataItem : metadata.values())
newObj.addMetadataItem(metadataItem.duplicate());

return newObj;

}

@Override
public int hashCode() {
// Updating the hash for time-point. Measurements and relationships aren't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public ObjMetadata(String name, String value) {
this.value = value;
}

public ObjMetadata duplicate() {
return new ObjMetadata(getName(), getValue());
}


// GETTERS AND SETTERS

Expand Down
59 changes: 42 additions & 17 deletions mia-core/src/main/java/io/github/mianalysis/mia/object/Objs.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class Objs extends LinkedHashMap<Integer, Obj> {
private double frameInterval;
private Unit<Time> temporalUnit;

public Objs(String name, double dppXY, double dppZ, String units, int width, int height, int nSlices, int nFrames, double frameInterval, Unit<Time> temporalUnit) {
public Objs(String name, double dppXY, double dppZ, String units, int width, int height, int nSlices, int nFrames,
double frameInterval, Unit<Time> temporalUnit) {
this.name = name;
this.spatCal = new SpatCal(dppXY, dppZ, units, width, height, nSlices);
this.nFrames = nFrames;
Expand Down Expand Up @@ -210,7 +211,7 @@ public int getLargestID() {
for (Obj obj : values())
if (obj.getID() > largestID)
largestID = obj.getID();

return largestID;

}
Expand All @@ -229,7 +230,8 @@ public Obj getAsSingleObject() {
try {
newObj.add(point.duplicate());
} catch (PointOutOfRangeException e) {
// This shouldn't occur, as the points are from a collection with the same dimensions
// This shouldn't occur, as the points are from a collection with the same
// dimensions
e.printStackTrace();
}

Expand All @@ -241,7 +243,8 @@ public Image convertToImage(String outputName, HashMap<Integer, Float> hues, int
return convertToImage(outputName, hues, bitDepth, nanBackground, false);
}

public Image convertToImage(String outputName, HashMap<Integer, Float> hues, int bitDepth, boolean nanBackground, boolean verbose) {
public Image convertToImage(String outputName, HashMap<Integer, Float> hues, int bitDepth, boolean nanBackground,
boolean verbose) {
// Create output image
Image image = createImage(outputName, bitDepth);

Expand All @@ -255,7 +258,7 @@ public Image convertToImage(String outputName, HashMap<Integer, Float> hues, int
object.addToImage(image, hues.get(object.getID()));
if (verbose)
Module.writeProgressStatus(++count, size(), "objects", "Object collection");
}
}

// Assigning the spatial cal from the cal
spatCal.setImageCalibration(image.getImagePlus());
Expand Down Expand Up @@ -283,7 +286,7 @@ public Image convertToImageRandomColours() {
}

public Image convertToImageBinary() {
HashMap<Integer, Float> hues = ColourFactory.getSingleColourValues(this,ColourFactory.SingleColours.WHITE);
HashMap<Integer, Float> hues = ColourFactory.getSingleColourValues(this, ColourFactory.SingleColours.WHITE);
Image dispImage = convertToImage(name, hues, 8, false);

if (dispImage == null)
Expand All @@ -301,7 +304,7 @@ public Image convertToImageBinary() {
}

public Image convertToImageIDColours() {
HashMap<Integer, Float> hues = ColourFactory.getIDHues(this,false);
HashMap<Integer, Float> hues = ColourFactory.getIDHues(this, false);
Image dispImage = convertToImage(name, hues, 32, false);

if (dispImage == null)
Expand All @@ -310,7 +313,7 @@ public Image convertToImageIDColours() {
return null;

ImagePlus dispIpl = dispImage.getImagePlus();
dispIpl.setLut(LUTs.Random(true,false));
dispIpl.setLut(LUTs.Random(true, false));
dispIpl.setPosition(1, 1, 1);
dispIpl.updateChannelAndDraw();

Expand Down Expand Up @@ -390,7 +393,7 @@ public Obj getByEqualsIgnoreNameAndID(Obj referenceObj) {
for (Obj testObj : values())
if (testObj.equalsIgnoreNameAndID(referenceObj))
return testObj;

return null;

}
Expand All @@ -402,7 +405,8 @@ public void resetCollection() {

/**
* Displays measurement values from a specific Module
* @param module The module for which measurements will be displayed
*
* @param module The module for which measurements will be displayed
* @param modules The collection of modules in which this module resides
*/
public void showMeasurements(Module module, Modules modules) {
Expand Down Expand Up @@ -492,7 +496,8 @@ public void showAllMeasurements() {

/**
* Displays metadata values from a specific Module
* @param module The module for which metadata will be displayed
*
* @param module The module for which metadata will be displayed
* @param modules The collection of modules in which this module resides
*/
public void showMetadata(Module module, Modules modules) {
Expand All @@ -508,7 +513,7 @@ public void showMetadata(Module module, Modules modules) {
LinkedHashSet<String> metadataNames = new LinkedHashSet<>();
for (ObjMetadataRef metadataRef : metadataRefs.values()) {
if (metadataRef.getObjectsName().equals(name))
metadataNames.add(metadataRef.getName());
metadataNames.add(metadataRef.getName());
}

// Iterating over each measurement, adding all the values
Expand Down Expand Up @@ -663,16 +668,15 @@ public Objs getObjectsInFrame(String outputObjectsName, int frame) {
outputObjects.setNFrames(1);

// Iterating over objects, getting those in this frame
for (Obj obj:values()) {
if (obj.getT() == frame) {
for (Obj obj : values()) {
if (obj.getT() == frame) {
Obj outputObject = new Obj(outputObjects, obj.getVolumeType(), obj.getID());
outputObject.setCoordinateSet(obj.getCoordinateSet().duplicate());
outputObject.setT(0);
outputObjects.add(outputObject);
}
}


return outputObjects;

}
Expand All @@ -692,11 +696,32 @@ public Unit<Time> getTemporalUnit() {
public void setNFrames(int nFrames) {
this.nFrames = nFrames;
}

public Objs duplicate(String newObjectsName, boolean duplicateRelationships, boolean duplicateMeasurement,
boolean duplicateMetadata, boolean addOriginalDuplicateRelationship) {
Objs newObjs = new Objs(newObjectsName, this);

for (Obj obj : values()) {
Obj newObj = obj.duplicate(newObjs, duplicateRelationships, duplicateMeasurement, duplicateMetadata);

newObjs.add(newObj);

if (addOriginalDuplicateRelationship) {
newObj.addParent(obj);
obj.addChild(newObj);
}
}

newObjs.maxID = this.maxID;

return newObjs;

}
}

// clear all
// print'HelloWorld'
// if{
// 'theSkyIsGreen'
// getMeasurements
// 'theSkyIsGreen'
// getMeasurements
// }
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import ij.plugin.Resizer;
import ij.process.LUT;
import ij.process.StackStatistics;
import inra.ijpb.binary.ChamferWeights3D;
import inra.ijpb.binary.distmap.DistanceTransform3DShort;
import io.github.mianalysis.mia.MIA;
import io.github.mianalysis.mia.module.Categories;
import io.github.mianalysis.mia.module.Category;
import io.github.mianalysis.mia.module.Module;
import io.github.mianalysis.mia.module.Modules;
import io.github.mianalysis.mia.module.images.process.binary.DistanceMap;
import io.github.mianalysis.mia.module.images.transform.InterpolateZAxis;
import io.github.mianalysis.mia.object.Obj;
import io.github.mianalysis.mia.object.Objs;
Expand All @@ -24,6 +24,7 @@
import io.github.mianalysis.mia.object.coordinates.volume.PointOutOfRangeException;
import io.github.mianalysis.mia.object.image.Image;
import io.github.mianalysis.mia.object.image.ImageFactory;
import io.github.mianalysis.mia.object.imagej.LUTs;
import io.github.mianalysis.mia.object.parameters.BooleanP;
import io.github.mianalysis.mia.object.parameters.ChoiceP;
import io.github.mianalysis.mia.object.parameters.InputObjectsP;
Expand All @@ -41,7 +42,6 @@
import io.github.mianalysis.mia.object.refs.collections.PartnerRefs;
import io.github.mianalysis.mia.object.system.Status;
import io.github.mianalysis.mia.process.ColourFactory;
import io.github.mianalysis.mia.object.imagej.LUTs;

/**
* Created by sc13967 on 01/08/2017.
Expand Down Expand Up @@ -196,11 +196,14 @@ public static Image getPaddedDistanceMap(Obj inputObject) {
if (!inputObject.is2D())
distIpl = InterpolateZAxis.matchZToXY(distIpl,InterpolateZAxis.InterpolationModes.NONE);

// Creating distance map using MorphoLibJ
short[] weights = ChamferWeights3D.BORGEFORS.getShortWeights();
DistanceTransform3DShort distTransform = new DistanceTransform3DShort(weights, true);

distIpl = DistanceMap.process(distIpl, "Distances", false, DistanceMap.WeightModes.W13_18_22_29_31,false, false);
distIpl.duplicate().show();
// // Creating distance map using MorphoLibJ
// short[] weights = ChamferWeights3D.BORGEFORS.getShortWeights();
// DistanceTransform3DShort distTransform = new DistanceTransform3DShort(weights, true);

distIpl.setStack(distTransform.distanceMap(distIpl.getStack()));
// distIpl.setStack(distTransform.distanceMap(distIpl.getStack()));

if (!inputObject.is2D()) {
Resizer resizer = new Resizer();
Expand Down Expand Up @@ -272,7 +275,7 @@ public Status process(Workspace workspace) {
edgeObjects = new Objs(edgeObjectName,inputObjects);
workspace.addObjects(edgeObjects);
}

MIA.log.writeDebug("here");
// Initialising output interior objects
String interiorObjectName = null;
Objs interiorObjects = null;
Expand Down
Loading

0 comments on commit 13fb5b6

Please sign in to comment.