Skip to content

Commit

Permalink
concretePostFilter works
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpcshangbo committed Apr 22, 2024
1 parent 9a0b8f7 commit d70b644
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
53 changes: 53 additions & 0 deletions concretePostFilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This script reads the crackMask images and the concreteMask folder to create filteredCrack folder which has those result images.
import cv2
import os
import configparser
import numpy as np

# Load the INI file and parse it
config = configparser.ConfigParser()
config.read("config.ini") # Replace with the actual path to your INI file

# Paths for the concreteMask images, raw images, and output images
# Read from the INI file
# mask_dir = config["Segmentation"]["mask_directory"]
# raw_dir = config["Settings"]["raw_directory"]
# output_dir = config["Overlay"]["overlay_transparent_directory"]
concreteMask_dir = config["CrackSegmentation"]["mask_directory"].replace("crackmask", "concretemask")
crackMask_dir = config["CrackSegmentation"]["mask_directory"]
output_dir = config["CrackSegmentation"]["mask_directory"].replace("crackmask", "filteredCrack")

# Ensure the output directory exists
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Iterate over the files in the mask directory
for concreteMask_name in os.listdir(concreteMask_dir):
# Extract the image name from the filename
crackMask_name = concreteMask_name.split(".")[0] + ".png"

# Load the mask and raw images
mask_image = cv2.imread(
os.path.join(concreteMask_dir, concreteMask_name), cv2.IMREAD_GRAYSCALE
)
original_image = cv2.imread(os.path.join(crackMask_dir, crackMask_name))

if mask_image is None or original_image is None:
print(f"Error reading {concreteMask_name} or {crackMask_name}. Skipping...")
continue

# Ensure the original image and mask have the same dimensions
if original_image.shape[:2] != mask_image.shape[:2]:
mask_image = cv2.resize(
mask_image, (original_image.shape[1], original_image.shape[0])
)

# Apply the mask to the original image
masked_original = cv2.bitwise_and(original_image, original_image, mask=mask_image)

# Save the overlaid image to the output directory
output_name = os.path.join(output_dir, crackMask_name)
cv2.imwrite(output_name, masked_original)
print(f"Saved {output_name}")

print("Processing complete!")
7 changes: 7 additions & 0 deletions cracksegmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
config_param = config["CrackSegmentation"]["config"]
model = config["CrackSegmentation"]["model"]

# Check if filteredRaw folder exists, then use filteredRaw as the raw folder
# filteredRaw = mask_directory.replace("crackmask", "filteredRaw")
# if os.path.exists(filteredRaw):
# raw_directory = filteredRaw

# Print the parameters

print(f"RAW_DIR={raw_directory}")
print(f"MASK_DIR={mask_directory}")
print(f"CONFIG={config_param}")
Expand Down
22 changes: 15 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from datetime import datetime

# Define flags for processing
concrete_filter = True
concrete_pre_filter = False
process_crack = True
process_stain = True
process_spall = True # if crack is not processed, spall won't be processed.
concrete_post_filter = True


def log_message(message):
Expand Down Expand Up @@ -39,20 +40,27 @@ def main(): # sourcery skip: extract-duplicate-method
log_message("Create raw, mask, overlay, mvs folders in run_timestamp folder.")
call_in_conda_env("python UpdateRawMaskOverlayConfigs.py")

if concrete_filter:
log_message("Running concrete mask...")
call_in_conda_env("python concretemask.py")
# if concrete_pre_filter:
# log_message("Running concrete mask...")
# call_in_conda_env("python concretemask.py")

log_message("Running filter raw...")
call_in_conda_env("python filterRaw.py")
exit()
# log_message("Running filter raw...")
# call_in_conda_env("python filterRaw.py")

# Run crack related processing

if process_crack:
# Run crack related processing
log_message("Running crack segmentation...")
call_in_conda_env("python cracksegmentation.py")

log_message("Running concrete mask...")
call_in_conda_env("python concretemask.py")

log_message("Running concrete post filter...")
call_in_conda_env("python concretePostFilter.py")

exit()

log_message("Converting crack masks to 3 categories according to directions...")
call_in_conda_env("python crack23directions.py")
Expand Down

0 comments on commit d70b644

Please sign in to comment.