Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用im4java对图像进行二值化?_Java_Image Processing_Colors_Imagemagick_Im4java - Fatal编程技术网

如何使用im4java对图像进行二值化?

如何使用im4java对图像进行二值化?,java,image-processing,colors,imagemagick,im4java,Java,Image Processing,Colors,Imagemagick,Im4java,我想把我的彩色图像变成黑白。 基本上,我想调用这个ImageMagick命令: convert input.png -threshold 80% output.png 但是使用im4java库。我知道IMOperation.threshold方法,但我不知道如何使用该方法编写与上述命令等效的命令。该方法已重载: threshold() threshold(java.lang.Integer red) threshold(java.lang.Integer red, java.lang.

我想把我的彩色图像变成黑白。 基本上,我想调用这个ImageMagick命令:

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) 
我尝试使用不同的值作为参数来调用方法的不同重载,但没有一个能产生好的结果,我通常会得到全白图像或全黑图像


那么,im4java与阈值80%的等效值是多少呢?

如果您正在考虑其他Java框架的话。使用Marvin图像处理框架:

MarvinImage image = MarvinImageIO.loadImage('image.jpg');
blackAndWhite(image, 30);
关于不同BW级别的输出示例:


显然,我需要使用blackThreshold:

我不确定它是否等同于我指定的ImageMagick命令,输出似乎有点不同,但出于所有实际目的,它提供了我所需要的

op.blackThreshold(80.0, true);