A. Half the width and half the height of the original image
B. Double the width and double the height of the original image
C. Same size as the original image
D. Width halved but height unchanged
Solution
Step 1: Understand imresize with scale factor
Using imresize(img, 0.5) scales the image to 50% of its original size in both width and height.
Step 2: Determine output size
The output image will have half the width and half the height of the original image.
Final Answer:
Half the width and half the height of the original image -> Option A
Quick Check:
imresize with 0.5 scales both dimensions by 0.5 [OK]
Hint: Scale 0.5 halves both width and height [OK]
Common Mistakes:
Thinking only width or height changes
Assuming scale factor doubles size
Confusing imresize with imcrop
4. Identify the error in this MATLAB code snippet intended to crop an image img to a 100x100 square starting at (20, 20):
cropped_img = imcrop(img, [20 20 100]);
medium
A. The image variable name is incorrect
B. The rectangle vector is missing the height value
C. imcrop cannot crop square images
D. The starting coordinates should be (100, 100)
Solution
Step 1: Check imcrop rectangle vector format
The rectangle vector must have four values: [x y width height]. Here only three values are given.
Step 2: Identify missing parameter
The height value is missing, causing a syntax error or unexpected behavior.
Final Answer:
The rectangle vector is missing the height value -> Option B
Quick Check:
imcrop needs [x y width height] vector [OK]
Hint: Rectangle vector must have 4 values [OK]
Common Mistakes:
Providing only 3 values instead of 4
Confusing coordinates with size
Assuming imcrop auto-fills missing values
5. You want to resize an image img to exactly 200x150 pixels and then crop a 100x100 square from the center. Which MATLAB code sequence correctly achieves this?
Use imresize(img, [150 200]) to set width=200 and height=150.
Step 2: Crop 100x100 square from center
The center of resized image is at (100, 75). To crop 100x100, start at (50, 25) because 50 = 100 - 100/2 and 25 = 75 - 100/2.
Step 3: Verify option correctness
resized = imresize(img, [150 200]); cropped = imcrop(resized, [50 25 100 100]); matches the correct order and coordinates. resized = imresize(img, [200 150]); cropped = imcrop(resized, [50 25 100 100]); swaps width and height. Options C and D crop before resizing, which is not what is asked.