If I imwrite
a binarized image, it only creates a grayscale image file not an indexed=2 file. What options do I need on the imwrite
to accomplish this? I would also like LZW compression if possible.
orig = cv2.imread('rgb.tiff')
work = cv2.cvtColor(orig, cv2.COLOR_BGR2GRAY)
work = cv2.ximgproc.niBlackThreshold(work, 255, cv2.THRESH_BINARY, 41, -0.2,
binarizationMethod=cv2.ximgproc.BINARIZATION_NICK)
cv2.imwrite('bw.tiff', work)
If you really, really want a bi-level LZW-compressed TIFF, you can write one with wand like this:
Input:
Result:
Note that you can save OpenCV images like this, but you must first convert from its BGR order to conventional RGB order first. You can use:
or pure Numpy:
Keywords: Python, image processing, wand, TIFF, TIF, LZW, compressed, compression, bilevel, bi-level