Cody

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

Solution 3276053

Submitted on 19 Oct 2020 by Ben Vien
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('image_size.m'); assert(isempty(strfind(filetext, 'eval')), 'eval is forbidden.'); assert(isempty(strfind(filetext, 'str2num')), 'str2num is forbidden.'); assert(isempty(strfind(filetext, 'fopen')), 'fopen is forbidden.'); assert(isempty(strfind(filetext, 'regexp')), 'regexp is forbidden.'); assert(isempty(strfind(filetext, '!')), 'Shell commands are forbidden.'); assert(isempty(strfind(filetext, 'mlock')), 'mlock is forbidden.'); assert(isempty(strfind(filetext, 'munlock')), 'munlock is forbidden.');

2   Pass
w = 3; h = 4; t = 'BW'; assert(strcmp(image_size(w, h, t), '2.00 bytes'));

3   Pass
w = 25; h = 25; t = 'L'; assert(strcmp(image_size(w, h, t), '625.00 bytes'));

4   Pass
w = 11; h = 13; t = 'RGB'; assert(strcmp(image_size(w, h, t), '429.00 bytes'));

5   Pass
% 720p resolution w = 1280; h = 720; t = 'BW'; assert(strcmp(image_size(w, h, t), '112.50 KB'));

6   Pass
% 720p resolution w = 1280; h = 720; t = 'L'; assert(strcmp(image_size(w, h, t), '900.00 KB'));

7   Pass
% 720p resolution w = 1280; h = 720; t = 'RGB'; assert(strcmp(image_size(w, h, t), '2.64 MB'));

8   Pass
% 720p resolution w = 1280; h = 720; t = 'RGBA'; assert(strcmp(image_size(w, h, t), '3.52 MB'));

9   Pass
w = 1925; h = 1083; t = 'BW'; assert(strcmp(image_size(w, h, t), '254.49 KB'));

10   Pass
w = 2000; h = 1007; t = 'BW'; assert(strcmp(image_size(w, h, t), '245.85 KB'));

11   Pass
w = 1117; h = 1050; t = 'BW'; assert(strcmp(image_size(w, h, t), '143.17 KB'));

12   Pass
% UHD resolution w = 3840; h = 2160; t = 'RGB'; assert(strcmp(image_size(w, h, t), '23.73 MB'));

13   Pass
% 4K resolution w = 4096; h = 2160; t = 'L'; assert(strcmp(image_size(w, h, t), '8.44 MB'));

14   Pass
% 8K resolution w = 7680; h = 4320; t = 'BW'; assert(strcmp(image_size(w, h, t), '3.96 MB'));

15   Pass
% 16K resolution w = 15360; h = 8640; t = 'RGBA'; assert(strcmp(image_size(w, h, t), '506.25 MB'));

16   Pass
% 32K resolution w = 30720; h = 17280; t = 'RGB'; assert(strcmp(image_size(w, h, t), '1.48 GB'));

17   Pass
% 32K resolution w = 30720; h = 17280; t = 'RGBA'; assert(strcmp(image_size(w, h, t), '1.98 GB'));

18   Pass
% 64K resolution w = 61440; h = 34560; t = 'RGB'; assert(strcmp(image_size(w, h, t), '5.93 GB'));

19   Pass
% 64K resolution w = 61440; h = 34560; t = 'RGBA'; assert(strcmp(image_size(w, h, t), '7.91 GB'));

20   Pass
% 128K resolution w = 122880; h = 69120; t = 'RGBA'; assert(strcmp(image_size(w, h, t), '31.64 GB'));

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!