Problem 46913. How many bytes an image requires from RAM?

Several algorithms store compressed images at our computers; types such as FIG, JPG, or PNG help software to identify them. On the other hand, whenever we visualize an image on a display screen, it must be decompressed to its total size: displaying a compressed image is utterly incomprehensible to humans. Your task is to compute this total size.
An image total size in bits is calculated with the following formula: , in which w is its width, h is its height, δ is its pixel depth, the number of bits used to store color intensity. Usually, image dimensions are easily obtained from any software, but its pixel depth is not always available. Nevertheless, it is easy to guess the latter since:
Black-and-white (BW) images have 1-bit pixel depth.
Grayscale (L) images have 8-bit pixel depth.
RGB (colored) images have 24-bit pixel depth.
RGBA (transparency) images has 32-bit pixel depth.
Compute how many bytes an image requires from RAM, given its w, h, and a string informing the type of the image: BW, L, RGB, or RGBA. Moreover, make the results more human-readable by showing them with units: bytes (), KB (), MB (), GB () rounded to 2 decimal places. There must be at least a non-zero integer value to display it in some units, you should always use the greatest unit possible, and data cannot be stored in less than 1 byte (8 bits).
Next:
How many bytes a video requires from RAM?

Solution Stats

22.41% Correct | 77.59% Incorrect
Last Solution submitted on Sep 01, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers13

Suggested Problems

More from this Author5

Community Treasure Hunt

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

Start Hunting!