我正在尝试计算对应图像之间的SSIM。例如,地面真实目录中名为106.tif的图像对应于假生成图像目录中的106.jpg。
地面真实目录的绝对路径为
这些图像相互对应,如下图所示: 请查看图片 我希望在一对一的基础上比较成千上万个这些图像。我不想将一个图像与多个其他图像进行比较。对应的真实和假图像具有相同的文件名,但扩展名不同(即106.tif和106.jpg),我只想将它们相互比较。
我很难修改可用的脚本以此方式进行SSIM比较。我想使用这个: https://github.com/mostafaGwely/Structural-Similarity-Index-SSIM-/blob/master/ssim.py 但也欢迎其他建议。以下是该代码:
/home/pr/pm/zh_pix2pix/datasets/mousebrain/test/B
,
假生成图像目录的绝对路径是/home/pr/pm/zh_pix2pix/output/fake_B
。这些图像相互对应,如下图所示: 请查看图片 我希望在一对一的基础上比较成千上万个这些图像。我不想将一个图像与多个其他图像进行比较。对应的真实和假图像具有相同的文件名,但扩展名不同(即106.tif和106.jpg),我只想将它们相互比较。
我很难修改可用的脚本以此方式进行SSIM比较。我想使用这个: https://github.com/mostafaGwely/Structural-Similarity-Index-SSIM-/blob/master/ssim.py 但也欢迎其他建议。以下是该代码:
# Usage:
#
# python3 script.py --input original.png --output modified.png
# Based on: https://github.com/mostafaGwely/Structural-Similarity-Index-SSIM-
# 1. Import the necessary packages
#from skimage.measure import compare_ssim
from skimage.metrics import structural_similarity as ssim
import argparse
import imutils
import cv2
# 2. Construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--first", required=True, help="Directory of the image that will be compared")
ap.add_argument("-s", "--second", required=True, help="Directory of the image that will be used to compare")
args = vars(ap.parse_args())
# 3. Load the two input images
imageA = cv2.imread(args["first"])
imageB = cv2.imread(args["second"])
# 4. Convert the images to grayscale
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)
# 5. Compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
#(score, diff) = compare_ssim(grayA, grayB, full=True)
(score, diff) = ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
# 6. You can print only the score if you want
print("SSIM: {}".format(score))
目前使用argparse只能一次处理一张图片,但我希望通过在真实目录和虚假目录之间循环比较它们。欢迎提供建议。