I normally use the UntiledOpImage subclass, wich should work fine for region growing (I ask for someone confirming: even on tiled images, when computing output image the source will be presented as untiled... the method will present also a comptabile writeable raster:
Here is a snippet of my code:
Code:
Stack pstack = new Stack(); /* Keep track of neightboor pixel */
Vector visited = new Vector(0); /* Keep track of visited pixel */
/* Getfundamental informations */
Raster r = source0.getTile(x, y);
int minX = 0;
int minY = 0;
int width = source0.getTileWidth();
int height = source0.getTileHeight();
/* Compute the resulting image */
WritableRaster wr = r.createCompatibleWritableRaster(minX, minY, width, height);
/* Set all pixel black XXX Necessary? */
for (int a = 0; a < height; a++) {
for (int b = 0; b < width; b++)
wr.setSample(b + minX, a + minY, 0, 0);
}
/* Iterate on all origins */
for (int i = 0; i < origins.length; i++) {
/* Push origin */
pstack.push(origins[i]);
while (pstack.empty() == false) {
Point point = (Point)pstack.pop();
if (visited.contains(point) == false) {
int value = r.getSample(point.x + minX, point.y + minY, 0);
visited.add(point);
if ((value >= low) && (value <= high)) {
Point border;
/* Write the current pixel (within intervall) to the destination raster */
wr.setSample(point.x + minX, point.y + minY, 0, value);
/* Push all border pixel for region growing */
if (point.x - 1 >= minX) { /* Left border */
border = new Point(point.x - 1, point.y);
if (pstack.search(border) == -1)
pstack.push(border);
}
if (point.y - 1 >= minY) { /* Upper border */
border = new Point(point.x, point.y - 1);
if (pstack.search(border) == -1)
pstack.push(border);
}
if (point.x + 1 < width) { /* Right border */
border = new Point(point.x + 1, point.y);
if (pstack.search(border) == -1)
pstack.push(border);
}
if (point.y + 1 < height) { /* Bottom order */
border = new Point(point.x, point.y + 1);
if (pstack.search(border) == -1)
pstack.push(border);
}
}
}
}
}
/* Returns the filtered raster with regions grown */
return (wr);
Bookmarks