www.gusucode.com > images 案例代码 matlab源码程序 > images/ReadAndWrite1BitBinaryImagesExample.m
%% 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. % Copyright 2015 The MathWorks, Inc. info = imfinfo('text.png'); info.BitDepth %% % 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 %% % 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|. imwrite(BW,'test.tif'); info = imfinfo('test.tif'); info.BitDepth