Challenge - 5 Problems
Image Display Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this image display code?
Consider the following MATLAB code that reads and displays an image. What will be the result shown in the figure window?
MATLAB
img = imread('peppers.png'); imshow(img); title('Original Image');
Attempts:
2 left
💡 Hint
Remember that 'imread' loads the image as a matrix and 'imshow' displays it as is.
✗ Incorrect
The 'imread' function loads the image in its original color format. 'imshow' then displays it correctly in a figure window. The title is added on top as specified.
❓ Predict Output
intermediateWhat happens if you try to display a grayscale image with imshow?
Given this MATLAB code snippet, what will be the output?
MATLAB
img = imread('cameraman.tif');
imshow(img);Attempts:
2 left
💡 Hint
Check how 'imshow' handles grayscale images.
✗ Incorrect
'imshow' can display grayscale images correctly without any extra arguments. The image appears as expected in grayscale.
🔧 Debug
advancedWhy does this code produce an error when displaying an image?
Look at this MATLAB code. It tries to read and display an image but causes an error. What is the cause?
MATLAB
img = imread('nonexistent.jpg');
imshow(img);Attempts:
2 left
💡 Hint
Check if the image file path is correct and the file exists.
✗ Incorrect
'imread' requires the image file to exist in the path or current folder. If the file is missing, it throws an error before 'imshow' runs.
🧠 Conceptual
advancedWhat is the class type of the variable after reading an image with imread?
After running this code, what is the data type (class) of the variable 'img'?
MATLAB
img = imread('peppers.png');Attempts:
2 left
💡 Hint
Most images are stored as 8-bit unsigned integers for each color channel.
✗ Incorrect
'imread' returns image data as 'uint8' by default for standard images, representing pixel intensities from 0 to 255.
❓ Predict Output
expertWhat is the size of the image matrix after reading a color image?
Given this code, what will be the size of the variable 'img'?
MATLAB
img = imread('peppers.png');
size_img = size(img);Attempts:
2 left
💡 Hint
Color images have three layers for red, green, and blue channels.
✗ Incorrect
The 'peppers.png' image is 384 pixels tall and 512 pixels wide with 3 color channels, so size returns [384 512 3].
