我正在嘗試使用 ImageMagick 7 來檢測影像中的特定通道是否主要是純黑色和純白色(加上一點抗鋸齒,并且影像有可能是純黑色)。這是為了與另一種共享命名約定但在 r/g/b 通道中具有類似照片的影像資料的影像區分開來。
(基本上這兩種影像型別都是來自不同引擎的高光貼圖。我在這里試圖區分的一種更現代,并且在藍色通道中具有金屬貼圖;另一種則要舊得多,并且在 RGB 通道中僅具有高光顏色和alpha 中的光澤貼圖。)
目前,我正在將通道與應用了 50% 閾值的自身克隆進行比較,使用 AE 指標來查看除了少量抗鋸齒之外它是否基本相同,以及 1% 的模糊以解決偶爾的問題與純黑/白的像差。此命令有效,但當然目前它只回傳失真像素的數量:
magick ( "file.png" -channel b -separate ) ^
( clone -channel b -separate -threshold 50% ) ^
-fuzz 1% -metric AE -compare ^
-format "%[distortion]" info:
因為輸入影像的大小會有所不同,所以我想將失真除以影像中的像素總數,以獲得不是純黑/白的影像的相對數量——在我的手冊中到目前為止,低于 10% 似乎不錯測驗——但我無法正確獲取格式語法。我嘗試過的一切——例如"%[fx:%[distortion]/w*h]"——都給出了magick: undefined variable `[distortion]' @ error/fx.c/FxGetSymbol/1169錯誤。
我應該使用什么語法?(如果有更好的方法來做我正在做的事情,我總是很感激!)
uj5u.com熱心網友回復:
我相信以下是您在 Imagemagick 中想要的。基本上你保存-set option:引數中的失真,然后在-fx以后使用它。
但是, clone只給你 b 通道,所以你的第二行應該不需要-channel b -separate。
magick ( "file.png" -channel b -separate ) ^
( clone -threshold 50% ) ^
-fuzz 1% -metric AE -compare ^
-set option:distort "%[distortion]" ^
-format "%[fx:distort/(w*h)]" info:
uj5u.com熱心網友回復:
Fred (@fmw42) 已經提供了一個很好的方法。還有另一種方法可以將純黑白影像與具有更完整色調等級的灰度影像區分開來,您可能會感興趣。感謝 Anthony Thyssen 對

如果您現在檢查兩個曝光影像的平均值和標準偏差:
magick {a,b}-sol.jpg -format "%f, mean: %[mean], stdev: %[standard-deviation]\n" info:
a-sol.jpg, mean: 2328.91, stdev: 3175.67
b-sol.jpg, mean: 16319.5, stdev: 9496.04
you can see that the mean and standard deviation of the first (pure black and white) image is low because all the bright whites have folded to near blacks, whereas the mean and standard deviation of the greyscale image are both higher because the tones are more spread out.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424377.html
上一篇:變換表結構
