convert bright.png -colorspace gray -equalize \
-define convolve:scale='!' \
-define morphology:compose=Lighten \
-morphology Convolve 'Sobel:>' bright_sobel.png
convert dull.png -colorspace gray -equalize \
-define convolve:scale='!' \
-define morphology:compose=Lighten \
-morphology Convolve 'Sobel:>' dull_sobel.png
convert other.png -colorspace gray -equalize \
-define convolve:scale='!' \
-define morphology:compose=Lighten \
-morphology Convolve 'Sobel:>' other_sobel.png
compare -metric ncc bright_sobel.png dull_sobel.png null:
0.688626
compare -metric ncc bright_sobel.png other_sobel.png null:
0.0756445
convert bright.png -equalize bright_eq.png
convert dull.png -equalize dull_eq.png
convert other.png -equalize other_eq.png
compare -metric NCC bright_eq.png dull_eq.png null:
0.861087
compare -metric NCC bright_eq.png other_eq.png null:
0.204296
redist 50,50,50 bright.png bright_rdist.png
redist 50,50,50 dull.png dull_rdist.png
redist 50,50,50 other.png other_rdist.png
convert bright_rdist.png -canny 0x1+10%+30% bright_rdist_canny.png
convert dull_rdist.png -canny 0x1+10%+30% dull_rdist_canny.png
convert other_rdist.png -canny 0x1+10%+30% other_rdist_canny.png
比较 -metric ncc bright_rdist_canny.png dull_rdist_canny.png null: 0.345919compare -metric ncc bright_rdist_canny.png other_rdist_canny.png null:
0.0323863
rainy.png
,sunny.png
和other.png
。然后,当图像完全相同时,NCC为1,当它们没有共同之处时,NCC为0。
因此,将 rainy.png
与 sunny.png
进行比较,它们相似度达到了83%:
convert -metric NCC sunny.png rainy.png -compare -format "%[distortion]" info:
0.831495
rainy.png
与other.png
进行比较,它们相似度为21%。convert -metric NCC rainy.png other.png -compare -format "%[distortion]" info:
0.214111
sunny.png
与 other.png
进行比较,它们相似度为22%。convert -metric NCC sunny.png other.png -compare -format "%[distortion]" info:
0.22060
ImageMagick 还提供其他度量方式,例如平均绝对误差(Mean Absolute Error)、结构相似性(Structural Similarity)等。要获取选项列表,请使用:
identify -list metric
样例输出
选择所需的指标,然后使用-metric SSIM
代替-metric NCC
,如果您需要结构相似性而不是归一化互相关系数。