+ [task#127424] add region coloring logic.
This commit is contained in:
@@ -189,10 +189,20 @@ function colorRegions(binaryImageData)
|
||||
const pixels = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||
let regions = findRegions(pixels, canvas.width, canvas.height);
|
||||
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
|
||||
/* 过滤掉小区域。 */
|
||||
/* Filter out small regions. */
|
||||
const minArea = 90;
|
||||
regions = regions.filter(r => r.area >= minArea);
|
||||
|
||||
regions.forEach((region, colorIndex) => {
|
||||
/* 保存当前状态。 */
|
||||
/* Save current state. */
|
||||
ctx.save();
|
||||
|
||||
ctx.fillStyle = colors[colorIndex % colors.length];
|
||||
});
|
||||
resolve(canvas.toDataURL());
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user