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
Problem Comments
-
1 Comment
Brendan
on 7 Dec 2022
NIce!
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
116 Solvers
-
317 Solvers
-
635 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
828 Solvers
-
5182 Solvers
More from this Author5
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!