Spaces:
Running
Running
fixed filled mask
Browse files- index.html +33 -5
index.html
CHANGED
|
@@ -424,14 +424,42 @@
|
|
| 424 |
tempCanvas.height = this.outputCanvas.height;
|
| 425 |
tempCtx.drawImage(this.predictedMask, 0, 0, tempCanvas.width, tempCanvas.height);
|
| 426 |
|
| 427 |
-
if (this.currentView === 'filled') {
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
this.outputCtx.globalAlpha = this.transparencySlider.value / 100;
|
| 433 |
this.outputCtx.drawImage(tempCanvas, 0, 0);
|
| 434 |
-
this.outputCtx.globalAlpha = 1.0;
|
|
|
|
|
|
|
| 435 |
|
| 436 |
} else if (this.currentView === 'outline') {
|
| 437 |
const src = cv.imread(tempCanvas);
|
|
|
|
| 424 |
tempCanvas.height = this.outputCanvas.height;
|
| 425 |
tempCtx.drawImage(this.predictedMask, 0, 0, tempCanvas.width, tempCanvas.height);
|
| 426 |
|
| 427 |
+
// if (this.currentView === 'filled') {
|
| 428 |
+
// tempCtx.globalCompositeOperation = 'source-in';
|
| 429 |
+
// tempCtx.fillStyle = '#FF00FF'; // Magenta
|
| 430 |
+
// tempCtx.fillRect(0, 0, tempCanvas.width, tempCanvas.height);
|
| 431 |
+
|
| 432 |
+
// this.outputCtx.globalAlpha = this.transparencySlider.value / 100;
|
| 433 |
+
// this.outputCtx.drawImage(tempCanvas, 0, 0);
|
| 434 |
+
// this.outputCtx.globalAlpha = 1.0;
|
| 435 |
|
| 436 |
+
if (this.currentView === 'filled') {
|
| 437 |
+
// --- FIX START: Correct way to create a colored overlay ---
|
| 438 |
+
const imageData = tempCtx.getImageData(0, 0, tempCanvas.width, tempCanvas.height);
|
| 439 |
+
const data = imageData.data;
|
| 440 |
+
|
| 441 |
+
// Iterate through each pixel
|
| 442 |
+
for (let i = 0; i < data.length; i += 4) {
|
| 443 |
+
// data[i] is red, data[i+3] is alpha (transparency)
|
| 444 |
+
// If the pixel in the mask is white (value > 128)
|
| 445 |
+
if (data[i] > 128) {
|
| 446 |
+
data[i] = 255; // R - Magenta
|
| 447 |
+
data[i + 1] = 0; // G
|
| 448 |
+
data[i + 2] = 255; // B
|
| 449 |
+
data[i + 3] = 255; // Alpha - make it fully opaque
|
| 450 |
+
} else {
|
| 451 |
+
// If the pixel is black, make it completely transparent
|
| 452 |
+
data[i + 3] = 0;
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
tempCtx.putImageData(imageData, 0, 0);
|
| 456 |
+
|
| 457 |
+
// Now draw this corrected overlay onto the main canvas with user-defined transparency
|
| 458 |
this.outputCtx.globalAlpha = this.transparencySlider.value / 100;
|
| 459 |
this.outputCtx.drawImage(tempCanvas, 0, 0);
|
| 460 |
+
this.outputCtx.globalAlpha = 1.0; // Reset alpha
|
| 461 |
+
// --- FIX END ---
|
| 462 |
+
|
| 463 |
|
| 464 |
} else if (this.currentView === 'outline') {
|
| 465 |
const src = cv.imread(tempCanvas);
|