colorMap = null;
this.histogramSize = upperBound;
}
protected synchronized void train() {
PlanarImage source = getSourceImage(0);
if (roi == null)
roi = new ROIShape(source.getBounds());
// Cycle throw all source tiles.
int minTileX = source.getMinTileX();
int maxTileX = source.getMaxTileX();
int minTileY = source.getMinTileY();
int maxTileY = source.getMaxTileY();
int xStart = source.getMinX();
int yStart = source.getMinY();
histogram = new HistogramHash(histogramSize);
while(true) {
histogram.init();
int oldbits = bits;
mask = (255 << 8 - bits) & 255;
mask = mask | (mask << 8) | (mask << 16);
for (int y = minTileY; y <= maxTileY; y++) {
for (int x = minTileX; x <= maxTileX; x++) {
// Determine the required region of this tile.
// (Note that getTileRect() instersects tile and
// image bounds.)
Rectangle tileRect = source.getTileRect(x, y);
// Process if and only if within ROI bounds.
if (roi.intersects(tileRect)) {
// If checking for skipped tiles determine
// whether this tile is "hit".
if (checkForSkippedTiles &&
tileRect.x >= xStart &&
tileRect.y >= yStart) {
// Determine the offset within the tile.
int offsetX =
(xPeriod - ((tileRect.x - xStart) % xPeriod)) %
xPeriod;
int offsetY =
(yPeriod - ((tileRect.y - yStart) % yPeriod)) %
yPeriod;
// Continue with next tile if offset
// is larger than either tile dimension.
if (offsetX >= tileRect.width ||
offsetY >= tileRect.height) {
continue;
}
}
// add the histogram.
computeHistogram(source.getData(tileRect));
if (histogram.isFull())
break;
}
}