Hello,
This is my updated code, please have a look at it
Code:
private int w, h;
private int[] [] lbl;
private void Growing (BufferedImage image) (
w = image.getWidth ();
image.getHeight h = ();
lbl = new int[w] [h];
Stack <Point> mustDo = new <Point> Stack ();
for(int h = 0 h <h h + +)
for(int w = 0, w <w; w + +)
(lbl [w] [h] = 0;)
/ / to simplify the code I set the seed (seed) to start my choice (x = 5, y = 8)
int x = 5;
int y = 8;
lbl [x] [y] = 1;
mustDo.add (new Point (x, y));
while(mustDo.size ()> 0)
(
ThisPointer mustDo.get = Point (0); mustDo.remove (0);
/ / Check 8-neighborhood
for(int th =- 1; th <= 1; th + +)
for(int tw =- 1; tw <= 1; tw + +)
(
int thisPoint.x + rx = tw;
int ry = thisPoint.y + th;
if ((rx <0) | | (ry <0) | | (ry> = h) | | (rx> = w)) continues;
int RGB1 = buffeurActuel.getRGB (rx, ry);
int RGB2 = buffeurActuel.getRGB (thisPoint.x, thisPoint.y);
if (lbl [rx] [ry] <0) (
if (RGB1 == RGB2) (
mustDo.add (new Point (rx, ry));
lbl [rx] [ry] = 1;
)
)
)
)
int [] opt = new int [w * h];
int cnt = 0;
for (int h = 0 h <h = h + +)
for(int w = 0, w <= w; w + +)
output [cnt + +] = lbl [w] [h];
}
Bookmarks