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'); info.BitDepth
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'); whos
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
imwrite(BW,'test.tif'); info = imfinfo('test.tif'); info.BitDepth
ans = 1