diff --git a/main.py b/main.py index 7fb142a..2376cab 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,6 @@ def scale_up(img, target_shape): # scale back up for the filter bank img_su = cv2.resize(img, (target_shape[0], target_shape[1]), interpolation=cv2.INTER_LINEAR) return img_su - def run_detection(fileLocation, clip): with open(fileLocation, "r") as f: strData = f.read() @@ -53,8 +52,30 @@ def run_detection(fileLocation, clip): # set value to either 0 or 1. rounds up if >= 0.5, else down return (npArray, anomaly_map_value) # returns original, and analyzed version for comparison. -def display_result(orig, res, fileName): - #''' +def store_data(orig, res, fileName): + with open(f"OutputDataRaw/{fileName}_raw_original.txt", "w+") as f: + vals = np.array2string( + orig, + precision=16, # Precision for floating point values + suppress_small=False, # Avoid suppressing small values + separator=', ', + threshold=np.prod(orig.shape) # Prevent truncation for large arrays + ) + f.write(vals) + with open(f"OutputDataRaw/{fileName}_raw_analyzed.txt", "w+") as f: + vals = np.array2string( + res, + precision=16, # Precision for floating point values + suppress_small=False, # Avoid suppressing small values + separator=', ', + threshold=np.prod(res.shape) # Prevent truncation for large arrays + ) + f.write(vals) + +def display_result(orig, res, fileName=None): + '''Displays original and analyzed data side by side. + Currently does not save chart or output since feature was + not found to be particularly useful.''' fig, ax = plt.subplots(1, 2, figsize=(12, 6)) # Display the original map @@ -69,19 +90,9 @@ def display_result(orig, res, fileName): plt.tight_layout() # Adjust layout for better spacing plt.show() - ''' - - plt.imshow(orig, cmap='hot') - plt.title("Original Map") - plt.colorbar() - plt.show() - #plt.savefig(f"OutputData/{fileName}_original") - plt.imshow(res, cmap='hot') - plt.title("Anomaly Map") - plt.colorbar() - plt.show() - #plt.savefig(f"OutputData/{fileName}_analyzed")''' + if (fileName): + plt.savefig(f"OutputData/{fileName}_analyzed") if __name__ == "__main__": @@ -89,14 +100,19 @@ def display_result(orig, res, fileName): parser.add_argument('-p', '--path', required=True, help="Path to the input file. Should be InputFolder.../...") parser.add_argument('-c', '--clip', type=int, help="Integer 0-2 for clip value. 0 = none, 1 = standard, 2 = binary.", default=0) + parser.add_argument('-s', '--save', type=bool, help="True or False to save result.", default=False) args = parser.parse_args() if (args.clip not in [0, 1, 2]): clipValue = 0 else: clipValue = args.clip + + fileName = None - fileName = args.path.split("/")[-1] # get the file name from Path. Used to label output. - + if (args.save): + fileName = args.path.split("/")[-1] # get the file name from Path. Can be used to label output. + (orig, res) = run_detection(args.path, args.clip) + store_data(orig, res, fileName) display_result(orig, res, fileName) \ No newline at end of file