首頁論壇分類作業系統Linux【Linux】使用 ImageMagick Compare 比較功能
【Linux】使用 ImageMagick Compare 比較功能
   編 輯        刪 除      # 5c8224a798066 發表: Odyssey     新增:2018-11-01 14:48:35     更新:2020-02-04 14:57:10

使用比較程序以數學方式和視覺方式註釋圖像與其重建之間的差異。

有關如何構造比較命令的建議,請參閱命令行處理,或參見下列的命令範例用法。

/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之間的值。


選項摘要

-alphaon, activate, off, deactivate, set, opaque, copy, transparent, extract, background, or shape the alpha channel
-authenticate valuedecrypt image with this password
-background colorbackground color
-brightness-contrast geometryimprove brightness / contrast of the image
-channel typeapply option to select image channels
-colorspace typeset image colorspace
-compose operatorset image composite operator
-crop geometrycrop the image
-decipher filenameconvert cipher pixels to plain
-debug eventsdisplay copious debugging information
-define format:optiondefine one or more image format options
-density geometryhorizontal and vertical density of the image
-depth valueimage depth
-dissimilarity-threshold valuemaximum distortion for (sub)image match (default 0.2)
-distort type coefficientsdistort image
-encipher filenameconvert plain pixels to cipher pixels
-extract geometryextract area from image
-fuzz distancecolors within this distance are considered equal
-gravity typehorizontal and vertical text placement
-helpprint program options
-highlight-color coloremphasize pixel differences with this color
-identifyidentify the format and characteristics of the image
-interlace typetype of image interlacing scheme
-level valueadjust the level of image contrast
-limit type valuepixel cache resource limit
-log formatformat of debugging information
-lowlight-color colorde-emphasize pixel differences with this color
-metric typemeasure differences between images with this metric
-negatereplace each pixel with its complementary color
-profile filenameatd, delete, or apply an image profile
-quality valueJPEG/MIFF/PNG compression level
-quantize colorspacereduce image colors in this colorspace
-quietsuppress all warning messages
-read-mask filenameassociate a read mask with the image
-regard-warningspay attention to warning messages.
-repage geometrysize and location of an image canvas
-resize geometryresize the image
-respect-parenthesessettings remain in effect until parenthesis boundary.
-rotate degreesapply Paeth rotation to the image
-sampling-factor geometryhorizontal and vertical sampling factor
-seed valueseed a new sequence of pseudo-random numbers
-separateseparate an image channel into a grayscale image
-set attribute valueset an image attribute
-sigmoidal-contrast geometryincrease the contrast without saturating highlights or shadows
-similarity-threshold valueminimum distortion for (sub)image match (default 0.0)
-size geometrywithh and height of image
-subimage-searchsearch for subimage
-synchronizesynchronize image to storage device
-taintmark the image as modified
-transparent-color colortransparent color
-trimtrim image edges
-verboseprint detailed information about the image
-versionprint version information
-virtual-pixel methodaccess method for pixels outside the boundaries of the image
-read-mask filenameassociate a write mask with the image

參考資料:

Command-line Tools: Compare @ ImageMagick

https://www.imagemagick.org/script/compare.php


夢幻奧德修斯 - OdysseusDream

Website:https://www.odysseusdream.com/

Discord:https://discord.gg/ht4mwMG

FB社團:https://www.facebook.com/groups/OdysseusDream/

FB粉專:https://www.facebook.com/OdysseusDream/

我要回覆
【Linux】使用 ImageMagick Compare 比較功能
首頁論壇分類作業系統Linux【Linux】使用 ImageMagick Compare 比較功能