Skip to content
Snippets Groups Projects
Commit 0c39bd3d authored by Daniel Felipe González Obando's avatar Daniel Felipe González Obando
Browse files

using Point and Point3D instead of vecmath

parent cecf0b07
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,6 @@ repositories {
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'javax.vecmath:vecmath:1.5.2'
compile files("${System.env.ICY_HOME}/icy.jar") // Icy core
compile files("${System.env.ICY_HOME}/lib/bioformats.jar") // bioformats
......
......@@ -19,6 +19,7 @@
package algorithms.danyfel80.islic;
import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
......@@ -31,17 +32,13 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.vecmath.Point2i;
import javax.vecmath.Point3d;
import javax.vecmath.Point3i;
import javax.vecmath.Vector3d;
import icy.image.IcyBufferedImage;
import icy.roi.BooleanMask2D;
import icy.roi.ROI;
import icy.sequence.Sequence;
import icy.type.DataType;
import icy.type.collection.array.Array2DUtil;
import icy.type.point.Point3D;
import plugins.kernel.roi.roi2d.ROI2DArea;
/**
......@@ -64,8 +61,8 @@ public class SLICTask {
private List<ROI> rois;
private Sequence superPixelsResult;
private Map<Point3i, double[]> colorLUT;
private Map<Point2i, Double> distanceLUT;
private Map<Point3D.Integer, double[]> colorLUT;
private Map<Point, Double> distanceLUT;
public SLICTask(Sequence sequence, int SPSize, double rigidity, boolean computeROIs) {
this.sequence = sequence;
......@@ -163,8 +160,8 @@ public class SLICTask {
int[] valRGB2 = new int[3];
IntStream.range(0, 3).forEach(c -> {
try {
valRGB1[c] = (int) Math.round(255 * (data[c % sequence.getSizeC()][pos1] / sequence.getDataTypeMax()));
valRGB2[c] = (int) Math.round(255 * (data[c % sequence.getSizeC()][pos2] / sequence.getDataTypeMax()));
valRGB1[c] = (int) Math.round(255 * (data[c % sequence.getSizeC()][pos1] / sequence.getDataTypeMax()));
valRGB2[c] = (int) Math.round(255 * (data[c % sequence.getSizeC()][pos2] / sequence.getDataTypeMax()));
} catch (Exception e) {
throw e;
}
......@@ -179,12 +176,12 @@ public class SLICTask {
}
private double[] getCIELab(double[][] sequenceData, int pos) {
Point3i rgbPoint = new Point3i();
int[] rgbVal = new int[3];
IntStream.range(0, 3).forEach(c -> {
rgbVal[c] = (int) Math.round(255 * (sequenceData[c % sequence.getSizeC()][pos] / sequence.getDataTypeMax()));
});
rgbPoint.set(rgbVal);
Point3D.Integer rgbPoint = new Point3D.Integer(rgbVal);
double[] LAB = colorLUT.get(rgbPoint);
if (LAB == null) {
......@@ -244,7 +241,7 @@ public class SLICTask {
diffb = bi - bk;
double dc = Math.sqrt(diffl * diffl + diffa * diffa + diffb * diffb);
Point2i dPt = new Point2i((int) Math.min(dx, dy), (int) Math.max(dx, dy));
Point dPt = new Point((int) Math.min(dx, dy), (int) Math.max(dx, dy));
Double ds = distanceLUT.get(dPt);
if (ds == null) {
ds = Math.sqrt(dx * dx + dy * dy);
......@@ -313,16 +310,16 @@ public class SLICTask {
boolean[] visited = new boolean[clusters.length];
int[] finalClusters = new int[clusters.length];
List<Point3d> labs = new ArrayList<>(SPnum);
List<Point3D.Double> labs = new ArrayList<>(SPnum);
List<Double> areas = new ArrayList<>(SPnum);
List<Point2i> firstPoints = new ArrayList<>(SPnum);
List<Point> firstPoints = new ArrayList<>(SPnum);
// fill known clusters
AtomicInteger usedLabels = new AtomicInteger(0);
IntStream.range(0, SPnum).forEach(i -> {
Point3d labCenter = new Point3d();
Point3D.Double labCenter = new Point3D.Double();
AtomicInteger area = new AtomicInteger(0);
Point2i p = new Point2i((int) Math.round(cxs[i]), (int) Math.round(cys[i]));
Point p = new Point((int) Math.round(cxs[i]), (int) Math.round(cys[i]));
int pPos = p.x + p.y * sequence.getWidth();
if (clusters[pPos] == i && !visited[pPos]) {
......@@ -343,9 +340,9 @@ public class SLICTask {
for (int x = 0; x < sequence.getWidth(); x++) {
int pos = x + yOff;
if (!visited[pos]) {
Point3d labCenter = new Point3d();
Point3D.Double labCenter = new Point3D.Double();
AtomicInteger area = new AtomicInteger(0);
Point2i p = new Point2i(x, y);
Point p = new Point(x, y);
findAreaAndColor(sequenceData, clusters, finalClusters, visited, p, labCenter, area,
usedLabels.getAndIncrement());
......@@ -408,7 +405,7 @@ public class SLICTask {
while (appliedLabel != mergedRefs[appliedLabel]) {
appliedLabel = mergedRefs[appliedLabel];
}
findAreaAndColor(sequenceData, clusters, finalClusters, visited, firstPoints.get(i), new Point3d(),
findAreaAndColor(sequenceData, clusters, finalClusters, visited, firstPoints.get(i), new Point3D.Double(),
new AtomicInteger(0), appliedLabel);
}
......@@ -450,20 +447,22 @@ public class SLICTask {
}
}
private void findAreaAndColor(double[][] sequenceData, int[] clusters, int[] newClusters, boolean[] visited,
Point2i p, Point3d labCenter, AtomicInteger area, int label) {
private void findAreaAndColor(double[][] sequenceData, int[] clusters, int[] newClusters, boolean[] visited, Point p,
Point3D.Double labCenter, AtomicInteger area, int label) {
int posp = p.x + p.y * sequence.getWidth();
area.set(0);
labCenter.set(0, 0, 0);
labCenter.x = 0d;
labCenter.y = 0d;
labCenter.z = 0d;
Deque<Point2i> q = new LinkedList<>();
Deque<Point> q = new LinkedList<>();
int val = clusters[posp];
visited[posp] = true;
q.add(p);
while (!q.isEmpty()) {
Point2i pti = q.pop();
Point pti = q.pop();
int posi = pti.x + pti.y * sequence.getWidth();
newClusters[posi] = label;
......@@ -475,7 +474,7 @@ public class SLICTask {
int[] ds = new int[] {0, -1, 0, 1, 0};
for (int is = 1; is < ds.length; is++) {
Point2i ptn = new Point2i(pti.x + ds[is - 1], pti.y + ds[is]);
Point ptn = new Point(pti.x + ds[is - 1], pti.y + ds[is]);
int posn = ptn.x + ptn.y * sequence.getWidth();
if (sequence.getBounds2D().contains(ptn.x, ptn.y) && !visited[posn] && clusters[posn] == val) {
visited[posn] = true;
......@@ -486,23 +485,23 @@ public class SLICTask {
}
}
private List<Integer> findNeighbors(int[] newClusters, boolean[] visited, Point2i p) {
private List<Integer> findNeighbors(int[] newClusters, boolean[] visited, Point p) {
int posp = p.x + p.y * sequence.getWidth();
HashSet<Integer> neighs = new HashSet<>();
Deque<Point2i> q = new LinkedList<>();
Deque<Point> q = new LinkedList<>();
int val = newClusters[posp];
visited[posp] = false;
q.add(p);
while (!q.isEmpty()) {
Point2i pti = q.pop();
Point pti = q.pop();
int[] ds = new int[] {0, -1, 0, 1, 0};
for (int is = 1; is < ds.length; is++) {
Point2i ptn = new Point2i(pti.x + ds[is - 1], pti.y + ds[is]);
Point ptn = new Point(pti.x + ds[is - 1], pti.y + ds[is]);
int posn = ptn.x + ptn.y * sequence.getWidth();
if (sequence.getBounds2D().contains(ptn.x, ptn.y)) {
if (newClusters[posn] == val) {
......@@ -520,8 +519,8 @@ public class SLICTask {
return new ArrayList<Integer>(neighs);
}
private double computeL(List<Point3d> labs, List<Double> areas, int i, Integer j) {
Vector3d diffLab = new Vector3d();
private double computeL(List<Point3D.Double> labs, List<Double> areas, int i, Integer j) {
Point3D.Double diffLab = new Point3D.Double();
diffLab.x = labs.get(j).x - labs.get(i).x;
diffLab.y = labs.get(j).y - labs.get(i).y;
diffLab.z = labs.get(j).z - labs.get(i).z;
......@@ -533,7 +532,7 @@ public class SLICTask {
}
}
private ROI2DArea defineROI(int[] newClusters, Point2i p, Point3d labP) {
private ROI2DArea defineROI(int[] newClusters, Point p, Point3D.Double labP) {
int posp = p.x + p.y * sequence.getWidth();
double[] lab = new double[] {labP.x, labP.y, labP.z};
int[] rgb = CIELab.toRGB(lab);
......
......@@ -17,15 +17,6 @@ public class SLIC extends EzPlug {
@Override
protected void initialize() {
try {
Class.forName("javax.vecmath.Point2i");
Class.forName("javax.vecmath.Point3d");
Class.forName("javax.vecmath.Point3i");
Class.forName("javax.vecmath.Vector3d");
} catch (ClassNotFoundException e) {
System.err.println("Could not load proper vecmath version: " + e);
e.printStackTrace();
}
inSequence = new EzVarSequence("Sequence");
inSPSize = new EzVarInteger("Superpixel size");
inSPReg = new EzVarDouble("Superpixels regularity");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment