20 #include "../bitmap/processing.h"
37 const Displacement LOOKUP_DIRECTION[2][2][2][2] = {
39 { { { { 0, 0 }, { 1, 0 } }, { { 0, +1 }, { +1, 0 } } }, { { { 0, -1 }, { 0, -1 } }, { { 9, 9 }, { 0, -1 } } } },
41 { { { { -1, 0 }, { 9, 9 } }, { { 0, 1 }, { +1, 0 } } }, { { { -1, 0 }, { -1, 0 } }, { { 0, 1 }, { 0, 0 } } } }
44 const Displacement LOOKUP_INTERNAL_PIXEL[3][3] = {
45 { { 0, 0 }, { 0, -1 }, { 0, 0 } },
46 { { -1, -1 }, { 9, 0 }, { 0, 0 } },
47 { { 0, 0 }, { -1, 0 }, { 0, 0 } }
50 const int W = in.getWidth(), H = in.getHeight();
51 const float LEVEL = level * in.MAX_VALUE;
56 for (
auto seed : border) {
68 if (
x < W &&
y < H && in().mean() > LEVEL) ++ctr;
69 if (
x > 0 &&
y < H && in(
x - 1,
y).mean() > LEVEL) ++ctr;
70 if (x < W && y > 0 && in(
x,
y - 1).mean() > LEVEL) ++ctr;
71 if (
x > 0 &&
y > 0 && in(
x - 1,
y - 1).mean() > LEVEL) ++ctr;
77 Displacement prev = { 0, 0 };
79 boundary.push_back(contour);
85 rb =
x < W &&
y < H && in().mean() > LEVEL,
86 lb =
x > 0 &&
y < H && in(
x - 1,
y).mean() > LEVEL,
87 rt = x < W && y > 0 && in(
x,
y - 1).mean() > LEVEL,
88 lt =
x > 0 &&
y > 0 && in(
x - 1,
y - 1).mean() > LEVEL;
91 if ((rb && lb && rt && lt) || !(rb || lb || rt || lt))
98 Displacement d = LOOKUP_DIRECTION[lt][rt][lb][rb];
100 if (prev.x == 0 && prev.y == 0)
107 Displacement ip = LOOKUP_INTERNAL_PIXEL[d.y + 1][d.x + 1];
108 int ipx =
x + ip.x, ipy =
y + ip.y;
109 if (ipx >= 0 && ipy >= 0 && ipx < W && ipy < H) {
110 testedPixels.
goTo(ipx, ipy);
122 }
while (seed.
x !=
x || seed.
y !=
y);
133 totalLength(0.0f), lastFragmentLength(0.0f)
144 (
x != p1.
x && (p1.
y -
y) * (p2.
x - p1.
x) == (p2.
y - p1.
y) * (p1.
x -
x)) ||
145 (
y != p1.
y && (p1.
x -
x) * (p2.
y - p1.
y) == (p2.
x - p1.
x) * (p1.
y -
y))
155 if (
x == p1.
x &&
y == p1.
y)
167 BitmapProcessing::read<Kernels::ComputeBounds>(
bitmap, boundary, border, testedPixels, level);
A very basic class for any image.
A sequence of integer-valued 2D points.
static void computeBoundary(std::vector< IntegerContour2D * > &boundary, AbstractBitmap &bitmap, std::vector< IntPoint > &border, BinaryMaskWriter &testedPixels, float level=0.5f)
Discovers an area boundary in a bitmap following a level curve, starting from a given set of points.
void clear()
Removes contour content.
std::vector< IntPoint > points
void addPoint(int x, int y)
Adds a new point to the end of the contour.
unsigned char getValue() const
Returns 0..MAX_UNNORM_VALUE value at current position.
void goTo(int x, int y)
Changes current position.
A generic to write mask bitmap data lookup tables for masks values.
void putValue(unsigned char x)
Puts a properly scaled (0..MAX_UNNORM_VALUE) value at the current position.
static void process(AbstractBitmap &bitmap, std::vector< IntegerContour2D * > &boundary, std::vector< IntPoint > &border, BinaryMaskWriter &testedPixels, float level)
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
jobject jlong jint jint y
Beatmup::InternalBitmap * bitmap
Beatmup::IntPoint p((int) x,(int) y)