Skip to content

Commit

Permalink
Fixed Clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanner Swanson committed Feb 3, 2025
1 parent 6a85d33 commit d60f327
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -69,34 +90,29 @@ 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__":
parser = argparse.ArgumentParser(description="Process some data with an optional clip argument.")

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)

0 comments on commit d60f327

Please sign in to comment.