使用比較程序以數學方式和視覺方式註釋圖像與其重建之間的差異。
有關如何構造比較命令的建議,請參閱命令行處理,或參見下列的命令範例用法。
/usr/local/ImageMagick/bin/magick compare -help
在此列出一些比較命令的範例,以說明其有用性和易用性。
首先,將圖像與已銳化的圖像進行比較:
/usr/local/ImageMagick/bin/magick convert rose.jpg -sharpen 0x1 reconstruct.jpg
/usr/local/ImageMagick/bin/magick compare rose.jpg reconstruct.jpg difference.png
/usr/local/ImageMagick/bin/magick compare -compose src rose.jpg reconstruct.jpg difference.png
差異圖像的紅色區域強調(突出顯示)受圖像銳化影響的像素,而白色去強調(低亮度)銳化處理未觸及的像素。
除了對圖像差異的視覺解釋及其重建之外,我們還報告了差異的數學度量:
/usr/local/ImageMagick/bin/magick compare -verbose -metric mae rose.jpg reconstruct.jpg difference.png
rose.jpg JPEG 70x46 70x46+0+0 8-bit sRGB 4069B 0.000u 0:00.000
reconstruct.jpg JPEG 70x46 70x46+0+0 8-bit sRGB 4294B 0.000u 0:00.000
Image: rose.jpg
Channel distortion: MAE
red: 1290.35 (0.0196894)
green: 1351.8 (0.0206272)
blue: 1343.1 (0.0204945)
all: 1328.42 (0.0202704)
rose.jpg=>difference.png JPEG 70x46 70x46+0+0 8-bit sRGB 15020B 0.010u 0:00.009
或者,若只想要紅色通道失真,使用以下命令:
/usr/local/ImageMagick/bin/magick compare -channel red -metric PSNR rose.jpg reconstruct.jpg difference.png
29.6941
或者,若只想要整體圖像失真,使用以下命令:
/usr/local/ImageMagick/bin/magick compare -metric PSNR rose.jpg reconstruct.jpg difference.png
29.6157
若重建的圖像是圖像的子圖像,則比較程序返回最佳匹配偏移。
此外,返回相似圖像,使得精確匹配位置完全為白色,若沒有像素匹配,則為黑色,否則為中間的某些灰度級:
/usr/local/ImageMagick/bin/magick compare -metric RMSE -subimage-search logo.png wizard.jpg similarity.gif
85.05 (0.00129778) @ 353,157
可以在命令行中找到在 Graphics from the Command Line 使用比較的其他範例。
可以從命令行的 More Graphics from the Command Line 和 Examples of ImageMagick Usage 中進一步討論。
如果根據指定的度量和模糊值的差異為0,則認為兩個圖像是相似的,除了歸一化的互相關度量(NCC),其中兩個圖像在它們的歸一化互相關為1時被認為是相似的。默認度量是NCC。
比較程序在出錯時返回2,如果圖像相似則返回0,如果它們不相似則返回0到1之間的值。
-alpha | on, activate, off, deactivate, set, opaque, copy, transparent, extract, background, or shape the alpha channel |
---|---|
-authenticate value | decrypt image with this password |
-background color | background color |
-brightness-contrast geometry | improve brightness / contrast of the image |
-channel type | apply option to select image channels |
-colorspace type | set image colorspace |
-compose operator | set image composite operator |
-crop geometry | crop the image |
-decipher filename | convert cipher pixels to plain |
-debug events | display copious debugging information |
-define format:option | define one or more image format options |
-density geometry | horizontal and vertical density of the image |
-depth value | image depth |
-dissimilarity-threshold value | maximum distortion for (sub)image match (default 0.2) |
-distort type coefficients | distort image |
-encipher filename | convert plain pixels to cipher pixels |
-extract geometry | extract area from image |
-fuzz distance | colors within this distance are considered equal |
-gravity type | horizontal and vertical text placement |
-help | print program options |
-highlight-color color | emphasize pixel differences with this color |
-identify | identify the format and characteristics of the image |
-interlace type | type of image interlacing scheme |
-level value | adjust the level of image contrast |
-limit type value | pixel cache resource limit |
-log format | format of debugging information |
-lowlight-color color | de-emphasize pixel differences with this color |
-metric type | measure differences between images with this metric |
-negate | replace each pixel with its complementary color |
-profile filename | atd, delete, or apply an image profile |
-quality value | JPEG/MIFF/PNG compression level |
-quantize colorspace | reduce image colors in this colorspace |
-quiet | suppress all warning messages |
-read-mask filename | associate a read mask with the image |
-regard-warnings | pay attention to warning messages. |
-repage geometry | size and location of an image canvas |
-resize geometry | resize the image |
-respect-parentheses | settings remain in effect until parenthesis boundary. |
-rotate degrees | apply Paeth rotation to the image |
-sampling-factor geometry | horizontal and vertical sampling factor |
-seed value | seed a new sequence of pseudo-random numbers |
-separate | separate an image channel into a grayscale image |
-set attribute value | set an image attribute |
-sigmoidal-contrast geometry | increase the contrast without saturating highlights or shadows |
-similarity-threshold value | minimum distortion for (sub)image match (default 0.0) |
-size geometry | withh and height of image |
-subimage-search | search for subimage |
-synchronize | synchronize image to storage device |
-taint | mark the image as modified |
-transparent-color color | transparent color |
-trim | trim image edges |
-verbose | print detailed information about the image |
-version | print version information |
-virtual-pixel method | access method for pixels outside the boundaries of the image |
-read-mask filename | associate a write mask with the image |
參考資料:
Command-line Tools: Compare @ ImageMagick
https://www.imagemagick.org/script/compare.php
新增時間 | 2020-02-05 |
最後更新 | 2022-02-09 |