MATLAB Answers


monochromatic image with 256 gray levels

SAMET YILDIZ さんによって質問されました 2014 年 9 月 21 日
最新アクティビティ Guillaume
さんによって コメントされました 2014 年 9 月 21 日
Hello everyone, Assuming a monochrome image with 1024 × 1024 pixels and 256 gray levels, I would like to calculate the total file size (in bytes), assuming a header (containing basic information, such as width and height of the image) of 32 bytes and w/o compression. Can you please help me on this? I have a doubt how to look at the header information on a gray scale image. Thanks

  2 件のコメント

Hello Samet,
Good question, although this is a MATLAB furom and I don't see a relation between your question and MATLAB at all!
Why don't you google your question?
David Young
2014 年 9 月 21 日
Would it be possible to write the image to a file using imwrite and then look to see how big the file is?

サインイン to comment.

2 件の回答

回答者: Jan
2014 年 9 月 21 日

The question seems to be trivial. The header has 32 bytes, 256 gray-scales can be store in a UINT8, which is a byte. So you get a file size of:
1024 * 1024 + 32 = 1'048'608 bytes
I do not see, where your doubts about looking at the header play a role for this question.

  1 件のコメント

Well, actually some image formats (BMP for e.g.) ensure that each row is aligned on a 32-bit boundary, so depending on the image format there may be some padding (although not for a 1024 pixel wide image since it is a multiple of 4).
However, since the author never specified the image format, your answer is as good as any.

サインイン to comment.

Image Analyst
回答者: Image Analyst
2014 年 9 月 21 日

Just try it and see. Of course it depends on the image and how many neighboring pixels are alike:
grayImage = imread('cell.tif'); % Read in sample image.
grayImage = imresize(grayImage, [1024, 1024]); % Make it 1024*1024
imwrite(grayImage, 'tiff uncompressed.tif', 'Compression', 'none');
uncompressedFileInfo = dir('tiff uncompressed.tif')
imwrite(grayImage, 'tiff compressed.tif', 'Compression', 'lzw');
compressedFileInfo = dir('tiff compressed.tif')
In the command window:
uncompressedFileInfo =
name: 'tiff uncompressed.tif'
date: '21-Sep-2014 10:30:07'
bytes: 1049286
isdir: 0
datenum: 735863.437581019
compressedFileInfo =
name: 'tiff compressed.tif'
date: '21-Sep-2014 10:30:07'
bytes: 361118
isdir: 0
datenum: 735863.437581019
Note that the header for the built-in imwrite seems to have a different header size than 32 bytes like you said.

  1 件のコメント

I'm not aware of any file format that has a header as short as 32 bytes. Even, BMP which has one of the simplest header is at least 40 bytes.

サインイン to comment.

Translated by