簡體   English   中英

如何在(os x)bash腳本中比較2個(圖像)文件,而忽略最后更改/修改的日期標頭?

[英]How to compare 2 (image) files in a (os x) bash script ignoring the last changed/modified date headers?

我想遞歸比較目錄中的屏幕快照文件。 我嘗試使用cmp但是它總是返回差異-即使圖像在視覺上沒有差異-我猜文件中的差異必須是last changedlast modified日期。

有沒有辦法我只能比較圖像文件的像素內容,而忽略這些標頭?

如何使用ImageMagic軟件套件( http://www.imagemagick.org )中的比較。 適用於Mac和所有現代Linux發行版。

我對圖像比較不熟悉,但是我嘗試創建一些樣本並按照以下代碼片段運行,

$ compare -identify -metric MAE same1.png same2.png null
>> same1.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.010u 0:00.009
>> same2.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.010u 0:00.000
>> 0 (0)

$ compare -identify -metric MAE same1.png diff.png null
>> same1.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.010u 0:00.020
>> diff.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 6.01KB 0.000u 0:00.009
>> 209.225 (0.00319257)

它似乎按預期工作。

希望有幫助!

編輯,DigitalTrauma的要點是,在不同格式/壓縮算法之間進行比較可能是一個問題,

$ compare -identify -metric MAE same1.png same2.xcf null
>> same1.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.080u 0:00.040
>> same2.xcf[0] XCF 640x400 640x400+0+0 8-bit DirectClass 2.73KB 0.070u 0:00.030
>> 0 (0)

$ compare -identify -metric MAE same1.png same2.bmp null
>> same1.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.010u 0:00.010
>> same2.bmp[0] BMP 640x400 640x400+0+0 8-bit DirectClass 768KB 0.000u 0:00.000
>> 0 (0)

$ compare -identify -metric MAE same1.png same2.jpg null
>> same1.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.010u 0:00.019
>> same2.jpg[0] JPEG 640x400 640x400+0+0 8-bit DirectClass 3.65KB 0.000u 0:00.009
>> 0.196766 (3.00245e-06)

因此,與jpeg進行比較時,即使圖片“看起來”相同,我們也會有所不同。 這絕對不是我的專長,但是我認為將圖片轉換為相同格式不會有任何區別,因為壓縮(或使圖片不同的方式)已經應用於圖片。

$ convert same2.jpg same2-from-jpg.png
$ compare -identify -metric MAE same2.png same2-from-jpg.png null
>> same2.png[0] PNG 640x400 640x400+0+0 8-bit PseudoClass 256c 1.38KB 0.040u 0:00.020
>> same2-from-jpg.png[0] PNG 640x400 640x400+0+0 8-bit DirectClass 1.64KB 0.010u 0:00.000
>> 0.196766 (3.00245e-06)

上面我們將jpg轉換回png,然后將其與原始圖像進行比較,但仍然有所不同。

無論如何,也許這會給您一些見識。 在處理圖片時,我絕對可以推薦ImageMagick。

我發現以下OSX軟件可以按圖像內容識別重復的圖像:

pdiff肯定可以通過bash腳本工作。 其余的更面向GUI,但也可能具有命令行界面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM