tags:

views:

34

answers:

2

Hello,

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 :)

+2  A: 

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')
Jonas
Thank you. Your answer is true. However, I can not mark two answers as my accepted answer. Thanks a lot.
Shadi
@Shadi: You're welcome.
Jonas
+1  A: 

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');
gnovice