First of all, thank you for the fantastic efforts in building this library. How can I convert an image using JIMP to black and white, I am not talking about grayscale but about binary image.
I believe it would work if you did .grayscale() and then .contrast(1)
http://codepen.io/strandedcity/pen/QdEYYX?editors=1000#0
.posterize(2) also works, but since there are currently no controls for the threshold, you'd frequently end up with an all-black or all-white image. By using contrast instead, your threshold ends up right in the middle.
Closing issue, please comment if that's not working for you.
Better late than never, I found this little gem.. Maybe should be included in Jimp, but easy to add.
https://www.npmjs.com/package/floyd-steinberg
var Jimp = require("jimp")
,floydSteinberg = require('floyd-steinberg')
, filename = process.argv[2]
Jimp.read(filename, function (err, image) {
if (err) throw err;
image.autocrop().scaleToFit(256, 256)
//.rgba(false).greyscale().contrast(1).posterize(2)
image.bitmap = floydSteinberg(image.bitmap)
image.write("out.png")
})
I use the output as input to Tesseract-OCR. I found .rgba(false) together with .greyscale() gave better OCR results, and results were better with without .contrast()
Most helpful comment
Better late than never, I found this little gem.. Maybe should be included in Jimp, but easy to add.
https://www.npmjs.com/package/floyd-steinberg
var Jimp = require("jimp")
,floydSteinberg = require('floyd-steinberg')
, filename = process.argv[2]
Jimp.read(filename, function (err, image) {
if (err) throw err;
image.autocrop().scaleToFit(256, 256)
//.rgba(false).greyscale().contrast(1).posterize(2)
image.bitmap = floydSteinberg(image.bitmap)
image.write("out.png")
})