use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class ManualSpot method initInterface.
private void initInterface() {
// adjust slider threshold
jSliderConstant.setMaximum((int) spot3DImage.getMax());
jSliderConstant.setMinimum(0);
ArrayUtil hist = new ArrayUtil(spot3DImage.getHistogram(new BlankMask(spot3DImage)));
int pcHigh = hist.indexOfSumPercent(0.999);
jSliderConstant.setValue(pcHigh);
// set tool point and open RoiManager
IJ.setTool(Toolbar.POINT);
RoiManager manager = RoiManager.getInstance();
if (manager == null) {
manager = new RoiManager();
}
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class AllRegionsAssociation method computeAllRegionsAssociationPairs.
public void computeAllRegionsAssociationPairs(ImageHandler img, int BorderValue) {
list = new ArrayList<AssociationRegion>();
for (int z = 1; z < img.sizeZ - 1; z++) {
IJ.showStatus("Analysing " + z);
for (int x = 1; x < img.sizeX - 1; x++) {
for (int y = 1; y < img.sizeY - 1; y++) {
if (((BorderValue >= 0) && (img.getPixel(x, y, z) == BorderValue)) || (BorderValue < 0)) {
ArrayUtil tab = img.getNeighborhoodCross3D(x, y, z);
int val = (int) img.getPixel(x, y, z);
tab = tab.distinctValues();
for (int i = 0; i < tab.getSize(); i++) {
int val2 = tab.getValueInt(i);
if (val2 != val) {
AssociationRegion asso = new AssociationRegion();
asso.addRegion(val);
asso.addRegion(val2);
this.addAssoRegion(asso);
}
}
}
}
}
}
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class AllRegionsAssociation method getNbClusters.
public int getNbClusters() {
if (clusters == null) {
computeClusters();
}
ArrayUtil tab = new ArrayUtil(clusters);
tab = tab.distinctValues();
if (tab.getMinimum() == 0) {
return tab.getSize() - 1;
} else {
return tab.getSize();
}
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class AllRegionsAssociation method getClusters.
public ArrayList<Cluster> getClusters() {
if (clusters == null) {
computeClusters();
}
ArrayUtil tab = new ArrayUtil(clusters);
int nbClusters = (int) tab.getMaximum() + 1;
ArrayList<Cluster> clus = new ArrayList<Cluster>(nbClusters);
for (int i = 0; i < nbClusters; i++) {
clus.add(new Cluster());
}
for (AssociationRegion asso : list) {
int c = clusters[asso.getFirst()];
if (c != 0) {
clus.get(c).addAssoRegion(asso);
}
}
return clus;
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class RegionGrowing method mergeLabels.
public int mergeLabels(int[] oldLabels, ArrayList<Voxel3D> borders) {
// get borders between these labels
// ArrayList<Voxel3D> borders = this.getBordersMerge(oldLabels, outsideBorders);
watershedImage.resetStats(null);
int newLabel = (int) watershedImage.getMax() + 1;
for (Voxel3D V : borders) {
watershedImage.setPixel(V, newLabel);
}
// update image
watershedImage.replacePixelsValue(oldLabels, newLabel);
// update associations
if (computeAssociation) {
ArrayList<String> toRemove = new ArrayList();
ArrayList<String> toAdd = new ArrayList();
for (String S : associations) {
boolean reprep = false;
String[] asso = S.split("_");
ArrayUtil assoTab = new ArrayUtil(asso.length);
for (int i = 0; i < assoTab.getSize(); i++) {
int val = Integer.parseInt(asso[i]);
boolean rep = false;
for (int old : oldLabels) {
if (val == old) {
rep = true;
reprep = true;
break;
}
}
if (rep) {
assoTab.putValue(i, newLabel);
} else {
assoTab.putValue(i, val);
}
}
if (reprep) {
assoTab = assoTab.distinctValues();
// array from max to min with unique values
assoTab.reverse();
if (assoTab.getSize() == 1) {
toRemove.add(S);
} else {
String assoRep = "" + (int) assoTab.getValue(0);
for (int i = 1; i < assoTab.getSize(); i++) {
assoRep = assoRep.concat("_" + (int) assoTab.getValue(i));
}
toRemove.add(S);
toAdd.add(assoRep);
}
}
}
if (!toRemove.isEmpty()) {
associations.removeAll(toRemove);
}
if (!toAdd.isEmpty()) {
for (String A : toAdd) {
// test if association exists already
boolean ok = true;
for (String S : associations) {
if ((S.compareTo(A)) == 0) {
ok = false;
break;
}
}
if (ok) {
associations.add(A);
}
}
}
// With allRegions
assoRegions.replaceRegion(oldLabels, newLabel);
}
// ??
if (computeUpdatedLabels) {
}
// update volumes
if (computeVolumes) {
double newVol = 0;
for (int i : oldLabels) {
newVol += volumeLabels.get(i);
// volumeLabels.get(i)[1] = 0;
volumeLabels.set(i, 0.0);
}
newVol += borders.size();
volumeLabels.add(newVol);
}
return newLabel;
}
Aggregations