renderdiff: add viewer for image differences (#8768)

- Modify the compare script to output more details of a
   comparison. This will include the source/golden directory,
   the comparison directory (the new renderings), and a file
   path to difference images if the golden does not match
   the rendered image.
 - The image_diff script can now output a TIFF that is the
   difference of two input TIFFs.
 - Add a viewer for examining the differences between rendered
   output and golden images.
 - The viewer consists of a simple server of web API endpoints
   for querying difference results (along with rendered images
   in TIFF).
 - And a web-based (html + lit-element) UI for looking at the
   rendered images and differences.
This commit is contained in:
Powei Feng
2025-06-02 19:37:46 +00:00
committed by GitHub
parent 60036c75fe
commit cd22478e4f
11 changed files with 821 additions and 37 deletions
+26 -2
View File
@@ -13,7 +13,7 @@
# limitations under the License.
import tifffile
import numpy
import numpy as np
def same_image(tiff_file_a, tiff_file_b):
try:
@@ -27,7 +27,7 @@ def same_image(tiff_file_a, tiff_file_b):
return False
# numpy.array_equal() checks if two arrays have the same shape and elements.
if numpy.array_equal(img1_data, img2_data):
if np.array_equal(img1_data, img2_data):
return True
else:
return False
@@ -41,3 +41,27 @@ def same_image(tiff_file_a, tiff_file_b):
except Exception as e:
print(f"An unexpected error occurred: {e}")
return False
def output_image_diff(tiff_file_a, tiff_file_b, output_path):
try:
img1_data = tifffile.imread(tiff_file_a)
img2_data = tifffile.imread(tiff_file_b)
# If the dimensions (height, width, number of channels, number of pages/frames)
# are different, the images are not the same.
if img1_data.shape != img2_data.shape:
raise RuntimeError(f"Images {tiff_file_a} and {tiff_file_b} have different shapes: {img1_data.shape} vs {img2_data.shape}")
diff_img = np.abs(img1_data.astype(np.int16) - img2_data.astype(np.int16))
diff_img = diff_img.astype(np.uint8)
tifffile.imwrite(output_path, diff_img)
except FileNotFoundError:
print(f"Error: One or both files not found ('{file_path1}', '{file_path2}').")
return False
except tifffile.TiffFileError as e:
print(f"Error: One or both files are not valid TIFF files or could not be read. Details: {e}")
return False
except Exception as e:
print(f"An unexpected error occurred: {e}")
return False