use of imagingbook.pub.geometry.basic.Pnt2d.PntInt in project imagingbook-common by imagingbook.
the class SegmentationRegionContour method findNextContourPoint.
// --------------------------------------------------------------------
// Starts at point X0 in direction d0, returns a tuple holding
// the next point and the direction in which it was found if successful.
// Returns null if no successor point is found.
private Tuple2<PntInt, Integer> findNextContourPoint(final PntInt x0, final int d0) {
final int step = (NT == N4) ? 2 : 1;
PntInt x = null;
int d = d0;
int i = 0;
boolean done = false;
while (i < 7 && !done) {
// N4: i = 0,2,4,6 N8: i = 0,1,2,3,4,5,6
x = x0.plus(delta[d][0], delta[d][1]);
if (ip.getPixel(x.x, x.y) == BACKGROUND) {
// mark this background pixel not to be visited again
setLabel(x, VISITED);
d = (d + step) % 8;
} else {
// found a non-background pixel (next pixel to follow)
done = true;
}
i = i + step;
}
return (done) ? Tuple2.from(x, d) : // no successor found
Tuple2.from(x0, d0);
}
use of imagingbook.pub.geometry.basic.Pnt2d.PntInt in project imagingbook-common by imagingbook.
the class SegmentationBreadthFirst method floodFill.
private void floodFill(int u, int v, int label) {
// queue contains pixel coordinates
Deque<PntInt> Q = new LinkedList<>();
Q.addLast(PntInt.from(u, v));
while (!Q.isEmpty()) {
// get the next point to process
PntInt p = Q.removeFirst();
int x = p.x;
int y = p.y;
if ((x >= 0) && (x < width) && (y >= 0) && (y < height) && getLabel(x, y) == FOREGROUND) {
setLabel(x, y, label);
Q.addLast(PntInt.from(x + 1, y));
Q.addLast(PntInt.from(x, y + 1));
Q.addLast(PntInt.from(x, y - 1));
Q.addLast(PntInt.from(x - 1, y));
if (NT == NeighborhoodType2D.N8) {
Q.addLast(PntInt.from(x + 1, y + 1));
Q.addLast(PntInt.from(x - 1, y + 1));
Q.addLast(PntInt.from(x + 1, y - 1));
Q.addLast(PntInt.from(x - 1, y - 1));
}
}
}
}
use of imagingbook.pub.geometry.basic.Pnt2d.PntInt in project imagingbook-common by imagingbook.
the class BreadthFirstSegmentation method floodFill.
private void floodFill(int u, int v, int label) {
// queue contains pixel coordinates
Deque<PntInt> Q = new LinkedList<>();
Q.addLast(PntInt.from(u, v));
while (!Q.isEmpty()) {
// get the next point to process
PntInt p = Q.removeFirst();
int x = p.x;
int y = p.y;
if ((x >= 0) && (x < width) && (y >= 0) && (y < height) && getLabel(x, y) == FOREGROUND) {
setLabel(x, y, label);
Q.addLast(PntInt.from(x + 1, y));
Q.addLast(PntInt.from(x, y + 1));
Q.addLast(PntInt.from(x, y - 1));
Q.addLast(PntInt.from(x - 1, y));
if (NT == NeighborhoodType2D.N8) {
Q.addLast(PntInt.from(x + 1, y + 1));
Q.addLast(PntInt.from(x - 1, y + 1));
Q.addLast(PntInt.from(x + 1, y - 1));
Q.addLast(PntInt.from(x - 1, y - 1));
}
}
}
}
use of imagingbook.pub.geometry.basic.Pnt2d.PntInt in project imagingbook-common by imagingbook.
the class DepthFirstSegmentation method floodFill.
private void floodFill(int u, int v, int label) {
// stack contains pixel coordinates
Deque<PntInt> S = new LinkedList<>();
S.push(PntInt.from(u, v));
while (!S.isEmpty()) {
PntInt p = S.pop();
int x = p.x;
int y = p.y;
if ((x >= 0) && (x < width) && (y >= 0) && (y < height) && getLabel(x, y) == FOREGROUND) {
setLabel(x, y, label);
S.push(PntInt.from(x + 1, y));
S.push(PntInt.from(x, y + 1));
S.push(PntInt.from(x, y - 1));
S.push(PntInt.from(x - 1, y));
if (NT == NeighborhoodType2D.N8) {
S.push(PntInt.from(x + 1, y + 1));
S.push(PntInt.from(x - 1, y + 1));
S.push(PntInt.from(x + 1, y - 1));
S.push(PntInt.from(x - 1, y - 1));
}
}
}
}
use of imagingbook.pub.geometry.basic.Pnt2d.PntInt in project imagingbook-common by imagingbook.
the class ChamferMatcher method getMatchValue.
private float getMatchValue(PntInt[] points, int r, int s) {
float q = 0.0f;
for (PntInt p : points) {
final int u = r + p.x;
final int v = s + p.y;
if (0 <= u && u < MI && 0 <= v && v < NI) {
q = q + D[u][v];
}
}
return q;
}