Shadi
Shadi

Reputation: 689

Matlab write 1-bit bmp

How can I write a 1-bit bmp image in Matlab using imwrite or any other function. the default of imwrite for bmp is 8-bit.

Thanks a lot :)

Upvotes: 2

Views: 4388

Answers (2)

gnovice
gnovice

Reputation: 125854

According to the IMWRITE documentation:

If the input array is of class logical, imwrite assumes the data is a binary image and writes it to the file with a bit depth of 1, if the format allows it. BMP, PNG, or TIFF formats accept binary images as input arrays.

Therefore, if you convert your image data to a logical matrix before giving it to IMWRITE, you should be able to create a 1-bit BMP image:

imwrite(logical(imageData),'image.bmp');

Upvotes: 1

Jonas
Jonas

Reputation: 74940

You have to convert the image to logical (i.e. 1-bit) before the call to imwrite.

%# assuming the image is stored in a variable 'img'
imwrite(logical(img),'test.bmp','bmp')

Upvotes: 2

Related Questions