Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,15 +33,19 @@ def compare_images(image1, image2, blur_value, technique, threshold_value):
|
|
| 33 |
filtered_contours = [cnt for cnt in contours if cv2.contourArea(cnt) > 500]
|
| 34 |
|
| 35 |
# Create a mask to isolate only the significant added object
|
| 36 |
-
mask = np.zeros_like(image1)
|
| 37 |
cv2.drawContours(mask, filtered_contours, -1, (255, 255, 255), thickness=cv2.FILLED)
|
| 38 |
|
| 39 |
# Apply the mask to highlight the object added in the second image
|
| 40 |
highlighted = cv2.bitwise_and(image2, mask)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
diff_colored =
|
| 44 |
-
diff_colored[:, :,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
overlayed = cv2.addWeighted(image1, 0.7, diff_colored, 0.3, 0)
|
| 46 |
|
| 47 |
return highlighted, overlayed
|
|
@@ -68,4 +72,4 @@ with gr.Blocks() as demo:
|
|
| 68 |
btn = gr.Button("Process")
|
| 69 |
btn.click(compare_images, inputs=[img1, img2, blur_slider, technique_dropdown, threshold_slider], outputs=[output1, output2])
|
| 70 |
|
| 71 |
-
demo.launch()
|
|
|
|
| 33 |
filtered_contours = [cnt for cnt in contours if cv2.contourArea(cnt) > 500]
|
| 34 |
|
| 35 |
# Create a mask to isolate only the significant added object
|
| 36 |
+
mask = np.zeros_like(image1, dtype=np.uint8)
|
| 37 |
cv2.drawContours(mask, filtered_contours, -1, (255, 255, 255), thickness=cv2.FILLED)
|
| 38 |
|
| 39 |
# Apply the mask to highlight the object added in the second image
|
| 40 |
highlighted = cv2.bitwise_and(image2, mask)
|
| 41 |
|
| 42 |
+
# Create a magenta overlay where changes occurred
|
| 43 |
+
diff_colored = np.zeros_like(image1, dtype=np.uint8)
|
| 44 |
+
diff_colored[:, :, 0] = thresh # Set blue channel to zero
|
| 45 |
+
diff_colored[:, :, 1] = 0 # Set green channel to zero
|
| 46 |
+
diff_colored[:, :, 2] = thresh # Set red channel to highlight in magenta
|
| 47 |
+
|
| 48 |
+
# Combine the original image with the magenta overlay
|
| 49 |
overlayed = cv2.addWeighted(image1, 0.7, diff_colored, 0.3, 0)
|
| 50 |
|
| 51 |
return highlighted, overlayed
|
|
|
|
| 72 |
btn = gr.Button("Process")
|
| 73 |
btn.click(compare_images, inputs=[img1, img2, blur_slider, technique_dropdown, threshold_slider], outputs=[output1, output2])
|
| 74 |
|
| 75 |
+
demo.launch()
|