Skip to content

Commit

Permalink
Create solid_filtered_overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpcshangbo committed May 23, 2024
1 parent 04878e5 commit abe8392
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions red2curve_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def classify_and_save_cracks(cls, raw_image_path, red_mask_image_path, output_fo
text_color = 'white' if avg_intensity < 128 else 'black' # Choose color based on average intensity
ax.text(x0, y0 - 5, f"{confidence:.1f}", color=text_color, alpha=0.5) # Set alpha for transparency (0 to 1)

print(f"Crack {i} classified as {crack_type} with confidence {confidence:.1f}")
# print(f"Crack {i} classified as {crack_type} with confidence {confidence:.1f}")
if crack_type == "other cracks":
print("Found other crack:", i) # Print if an "other_cracks" is detected
# print("Found other crack:", i) # Print if an "other_cracks" is detected
other_cracks_mask[y0:y1, x0:x1] = 255

# Save overall image with bounding boxes (Optional)
Expand All @@ -86,7 +86,7 @@ def classify_and_save_cracks(cls, raw_image_path, red_mask_image_path, output_fo
red_mask.save(os.path.join(output_folder, "red_mask.png")) # Save the red mask

# Create and SAVE the filtered raw mask for debugging
print(np.unique(other_cracks_mask)) # Should print [0 255] if "other_cracks" exist
# print(np.unique(other_cracks_mask)) # Should print [0 255] if "other_cracks" exist
filtered_raw_mask = Image.fromarray(other_cracks_mask) # Don't need to scale here
filtered_raw_mask.save(os.path.join(output_folder, "mask_filter.png"))

Expand All @@ -107,6 +107,15 @@ def classify_and_save_cracks(cls, raw_image_path, red_mask_image_path, output_fo
filtered_raw.paste(filtered_mask_img, (0, 0), filtered_mask_img)
filtered_raw.save(os.path.join(output_folder, "filtered_overlay.png"))

# Create solid_filtered_overlay
solid_filtered_overlay = Image.new("RGBA", raw_image.size)
solid_filtered_overlay.paste(raw_image)

solid_mask = Image.new("RGBA", filtered_mask_img.size, (255, 0, 0, 255)) # Solid red color
solid_filtered_overlay.paste(solid_mask, (0, 0), filtered_mask_img) # Use filtered_mask_img as the mask

solid_filtered_overlay.save(os.path.join(output_folder, "solid_filtered_overlay.png"))

filtered_raw = Image.new("RGBA", raw_image.size)
filtered_raw.paste(raw_image)

Expand Down

0 comments on commit abe8392

Please sign in to comment.