2014-09-04 29 views
0

我想談談我的彩色圖像分爲B & W. 基本上,我想打電話給該ImageMagick的命令:如何使用im4java二值化圖像?

convert input.png -threshold 80% output.png 

但使用im4java庫。我知道IMOperation.threshold()方法,但我不知道如何使用該方法編寫上述命令的等效命令。該方法被重載:

threshold() 

threshold(java.lang.Integer red) 

threshold(java.lang.Integer red, java.lang.Integer green) 

threshold(java.lang.Integer red, java.lang.Integer green, java.lang.Integer blue) 

threshold(java.lang.Integer red, java.lang.Integer green, java.lang.Integer blue, 
    java.lang.Integer opacity) 

threshold(java.lang.Integer red, java.lang.Integer green, java.lang.Integer blue, 
    java.lang.Integer opacity, java.lang.Boolean percent) 

我試着用不同的值作爲參數調用方法的不同重載,但他們沒有產生良好的結果(我通常要麼全白圖像或全黑圖像)。

那麼什麼是「閾值80%」的im4java等價物?

回答

0

很顯然,我需要使用blackThreshold

op.blackThreshold(80.0, true); 

我不知道它是否與我指定的ImageMagick命令相同,輸出看起來像有點不同,但爲了所有實際目的,它給了我所需要的東西。

0

就在你正在考慮其他Java框架的情況下。使用張建東圖像處理框架:

MarvinImage image = MarvinImageIO.loadImage('image.jpg'); 
blackAndWhite(image, 30); 

關於不同BW層次輸出的例子:

enter image description here

相關問題