Repository navigation
Expand file tree
/
Copy pathcomparison.py
More file actions
57 lines (43 loc) · 1.6 KB
/
Copy pathcomparison.py
File metadata and controls
57 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import tifffile as tif
import numpy as np
import json
import os
def isIdentical(image_path1, image_path2):
"""
Compare two TIFF images to check if they are equal in every value.
Args:
image_path1 (str): Path to the first TIFF image
image_path2 (str): Path to the second TIFF image
Returns:
bool: True if images are identical, False otherwise
"""
with tif.TiffFile(image_path1) as tif1, tif.TiffFile(image_path2) as tif2:
# Read the image data
data1 = tif1.asarray()
data2 = tif2.asarray()
print(f"Shape of GT = {data1.shape}\nShape of OUT = {data2.shape}")
# Reduce dimensions if a dimension is 1
if data1.shape != data2.shape:
data1 = np.squeeze(data1)
data2 = np.squeeze(data2)
# Compare the arrays
return np.array_equal(data1, data2)
def sort_json(data):
if isinstance(data, dict):
return {k: sort_json(v) for k, v in sorted(data.items())}
elif isinstance(data, list):
return sorted(sort_json(x) for x in data)
else:
return data
def isJsonIdentical(json_path1, json_path2):
with open(json_path1) as f1, open(json_path2) as f2:
json_data1 = json.load(f1)
json_data2 = json.load(f2)
if json_data1 == json_data2:
return True
return False
if __name__ == "__main__":
fd = r'..\TransformImages\MaxIntensityProjectionRGB'
p1 = os.path.join(fd, 'GT_Test_8bit_ZYX_Cells3D_ch2_nuc_processed.tif')
p2 = os.path.join(fd, 'OUT_Test_8bit_ZYX_Cells3D_ch2_nuc_processed.tif')
result = isIdentical(p1, p2)