sips is a command-line tool to process images on Mac OS X and BSD Unix.
sips stands for Scriptable Image Processing System.
I have a 1-bit black and white uncompressed TIFF image. The following
sips command compresses it with LZW compression.
sips -s format tiff -s formatOptions lzw sample.tif --out lzw.tif
However, the resultant TIFF image has black and white inverted when displayed on a certain viewer. This inversion is related to "Photometric Interpretation" as explained below.
Each pixel in a Black and White image is represented by a single bit. A 1-bit TIFF image has no palette, and can only be black and white. An "on" bit and an "off" bit can represent either black or white depending on the photometric tag (ID262) of the TIFF image. The typical photometric orientation of a black and white TIFF image is 0 = White and 1 = Black, which corresponds to a photometric tag value of 0. The opposite, 0 = Black, 1 = White corresponds to a photometric tag value of 1. Some image viewers ignore the photometric tag completely always assuming 0 = White, most notably the Windows XP Image Viewer. (source: atalasoft /KB/article.aspx?id=10069)
Black and white is inverted because the viewer prefers white to be 0, while
sips uses white as 1 when generating the TIFF image.
The input file sample.tif has white as 0.
The output file lzw.tif has white as 1.
To check whether white is 0 or 1 (or whether 0 is white or black), that is, whether "Photometric Interpretation" is 0 or 1, at least the following two methods are available.
exiftool, which can be obtained from
exiftool -S lzw.tif -PhotometricInterpretation
Preview.app on Mac OS X.
Tools > Show Inspector (Command-I) > TIFF
My question: How can
sips be forced to use white as 0 when creating a 1-bit black and white TIFF image?
As I said, I have a 1-bit black and white uncompressed TIFF image. In fact, I have thousands of this kind. Thus, instead of manually processing them on GIMP or Photoshop, I need a command-line tool to automate the process.
sips cannot do what I want, then I will perhaps post a new question asking for a command-line tool which
- runs on Mac OS X;
- takes a 1-bit black and white uncompressed TIFF image;
- outputs a 1-bit black and white LZW-compressed TIFF image with white as 0.
(My default shell is bash.)
Meanwhile, I will wait to see whether
As a sample image, I am trying to upload a 1-bit black and white uncompressed TIFF image, which consists of black letters on white background, and whose Photometric Interpretation is 0 (WhiteIsZero). However, the image-uploading mechanism at stackexchange automatically converts TIFF into PNG.
sips command near the top of this post takes an uncompressed TIFF and outputs an LZW-compressed TIFF. The following
sips command takes a PNG and outputs an LZW-compressed TIFF.
sips -s format tiff -s formatOptions lzw Cqdg2.png --out Cqdg2.tif
This resultant TIFF image Cqdg2.tif has the same problem as the earlier resultant TIFF image lzw.tif concerning the inversion and the Photometric Interpretation.