Main Content

Read and Write 1-Bit Binary Images

This example shows how to read and write 1-bit binary images.

Check the bit depth of the graphics file containing a binary image, text.png. Note that the file stores the binary image in 1-bit format.

info = imfinfo('text.png');
ans = 1

Read the binary image from the file into the workspace. When you read a binary image stored in 1-bit format, imread represents the data in the workspace as a logical array.

BW = imread('text.png');
  Name        Size             Bytes  Class      Attributes

  BW        256x256            65536  logical              
  ans         1x1                  8  double               
  info        1x1               4566  struct               

Write the binary image to a file in 1-bit format. If the file format supports it, imwrite exports a binary image as a 1-bit image, by default. To verify this, use imfinfo to get information about the newly created file and check the BitDepth field. When writing binary files, imwrite sets the ColorType field to grayscale.

info = imfinfo('test.tif');
ans = 1

See Also

| |

Related Topics