(output_dir)
| 1007 | |
| 1008 | |
| 1009 | def object_detection(output_dir): |
| 1010 | # Load the original image |
| 1011 | png_dir = os.path.join(output_dir, "png") |
| 1012 | if os.path.isdir(png_dir): |
| 1013 | for filename in tqdm(os.listdir(png_dir), desc="Object detection PNG test: "): |
| 1014 | f = os.path.join(png_dir, filename) |
| 1015 | # checking if it is a file |
| 1016 | if os.path.isfile(f): |
| 1017 | # print(f) |
| 1018 | image_path = f |
| 1019 | original_image = cv2.imread(image_path) |
| 1020 | |
| 1021 | # Step 1: Run detection on the original image |
| 1022 | process_and_save(original_image.copy(), f"{filename}_original") |
| 1023 | |
| 1024 | # Step 2: Isolate RGB channels and run detection on each |
| 1025 | rgb_channels = ['red', 'green', 'blue'] |
| 1026 | for i, color in enumerate(rgb_channels): |
| 1027 | isolated_image = np.zeros_like(original_image) |
| 1028 | isolated_image[:, :, i] = original_image[:, :, i] # Keep only one channel active |
| 1029 | |
| 1030 | process_and_save(isolated_image, f"{filename}_{color}_only") |
| 1031 | |
| 1032 | # Step 3: Iterate over LSB removals (1 to 8 bits) and run detection |
| 1033 | for bits in range(1, 9): # Extract 1-bit to 8-bit LSBs |
| 1034 | lsb_image = extract_lsb_and_normalize(original_image, bits) |
| 1035 | process_and_save(lsb_image, f"{filename}_lsb_{bits}_bits_normalized") |
| 1036 | |
| 1037 | # cv2.destroyAllWindows() |
| 1038 | |
| 1039 | jpg_dir = os.path.join(output_dir, "jpg") |
| 1040 | if os.path.isdir(jpg_dir): |
| 1041 | for filename in tqdm(os.listdir(jpg_dir), desc="Object detection JPG test: "): |
| 1042 | f = os.path.join(jpg_dir, filename) |
| 1043 | # checking if it is a file |
| 1044 | if os.path.isfile(f): |
| 1045 | # print(f) |
| 1046 | image_path = f |
| 1047 | original_image = cv2.imread(image_path) |
| 1048 | |
| 1049 | # Step 1: Run detection on the original image |
| 1050 | process_and_save(original_image.copy(), f"{filename}_original") |
| 1051 | |
| 1052 | # Step 2: Isolate RGB channels and run detection on each |
| 1053 | rgb_channels = ['red', 'green', 'blue'] |
| 1054 | for i, color in enumerate(rgb_channels): |
| 1055 | isolated_image = np.zeros_like(original_image) |
| 1056 | isolated_image[:, :, i] = original_image[:, :, i] # Keep only one channel active |
| 1057 | |
| 1058 | process_and_save(isolated_image, f"{filename}_{color}_only") |
| 1059 | |
| 1060 | # Step 3: Iterate over LSB removals (1 to 8 bits) and run detection |
| 1061 | for bits in range(1, 9): # Extract 1-bit to 8-bit LSBs |
| 1062 | lsb_image = extract_lsb_and_normalize(original_image, bits) |
| 1063 | process_and_save(lsb_image, f"{filename}_lsb_{bits}_bits_normalized") |
| 1064 | |
| 1065 | # cv2.destroyAllWindows() |
| 1066 | print("OBJECT DECTECTION TEST DONE") |
no test coverage detected