44import torchstain .torch
55import torch
66import torchvision
7- import time
87import numpy as np
98from torchvision import transforms
10- from skimage . metrics import structural_similarity as ssim
9+
1110
1211def setup_function (fn ):
1312 print ("torch version:" , torch .__version__ , "torchvision version:" , torchvision .__version__ )
@@ -52,11 +51,11 @@ def test_macenko_torch():
5251 result_torch , _ , _ = torch_normalizer .normalize (I = t_to_transform , stains = True )
5352
5453 # convert to numpy and set dtype
55- result_numpy = result_numpy .astype ("float32" )
56- result_torch = result_torch .numpy ().astype ("float32" )
54+ result_numpy = result_numpy .astype ("float32" ) / 255.
55+ result_torch = result_torch .numpy ().astype ("float32" ) / 255.
5756
5857 # assess whether the normalized images are identical across backends
59- np .testing .assert_almost_equal (ssim ( result_numpy .flatten (), result_torch .flatten ()), 1.0 , decimal = 4 , verbose = True )
58+ np .testing .assert_almost_equal (result_numpy .flatten (), result_torch .flatten (), decimal = 2 , verbose = True )
6059
6160def test_reinhard_torch ():
6261 size = 1024
@@ -83,8 +82,9 @@ def test_reinhard_torch():
8382 result_torch = torch_normalizer .normalize (I = t_to_transform )
8483
8584 # convert to numpy and set dtype
86- result_numpy = result_numpy .astype ("float32" )
87- result_torch = result_torch .numpy ().astype ("float32" )
85+ result_numpy = result_numpy .astype ("float32" ) / 255.
86+ result_torch = result_torch .numpy ().astype ("float32" ) / 255.
8887
88+
8989 # assess whether the normalized images are identical across backends
90- np .testing .assert_almost_equal (ssim ( result_numpy .flatten (), result_torch .flatten ()), 1.0 , decimal = 4 , verbose = True )
90+ np .testing .assert_almost_equal (result_numpy .flatten (), result_torch .flatten (), decimal = 2 , verbose = True )
0 commit comments