monochromatic image with 256 gray levels

7 vues (au cours des 30 derniers jours)
SAMET YILDIZ
SAMET YILDIZ le 21 Sep 2014
Commenté : Guillaume le 21 Sep 2014
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 commentaires
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh le 21 Sep 2014
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?
Tnx
David Young
David Young le 21 Sep 2014
Would it be possible to write the image to a file using imwrite and then look to see how big the file is?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 21 Sep 2014
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 commentaire
Guillaume
Guillaume le 21 Sep 2014
Modifié(e) : Guillaume le 21 Sep 2014
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 21 Sep 2014
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 commentaire
Guillaume
Guillaume le 21 Sep 2014
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Display Image dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by