Problem 44958. Crop an Image
A grayscale image is represented as a matrix in MATLAB. Each matrix element represents a pixel in the image. An element value represents the intensity of the pixel at that location.
Create a cropped image matrix Icrop using inputs given in the following order:
- I - Grayscale input image
- Rmin - Lowest row number to retain
- Cmin - Lowest column number to retain
- Rpix - Number of pixels along rows to retain
- Cpix - Number of pixels along columns to retain

For example, if your image was:
I = [1 2 3 4
5 6 7 8]
And you called crop_image with inputs
Icrop = crop_image(I, 2, 2, 1, 3)
The output Icrop should be
[6 7 8]
Solution Stats
Problem Comments
-
27 Comments
Show
24 older comments
Rich
on 11 Mar 2025 at 20:05
I got stuck on this one for a long time. Can someone explain why you can't use the imcrop function?
Christian Schröder
on 12 Mar 2025 at 7:14
@Rich imcrop() is part of the Image Processing Toolbox, and toolboxes are not available on Cody.
Dyuman Joshi
on 13 Mar 2025 at 12:35
Which is specified here -
https://in.mathworks.com/matlabcentral/content/cody/about.html
Notes bulletin - "Cody supports MATLAB and not the toolboxes."
Solution Comments
Show commentsGroup

High School Challenge
- 50 Problems
- 98 Finishers
- Times 2 - START HERE
- Add two numbers
- Laws of motion 3
- Laws of motion 6
- Force and Motion 2
- Force and Motion 3
- Velocity Conversion
- Potential energy calculation
- An Ohm's Law Calculator
- Electrical Diode Current Calculation
- Resistance of a light bulb
- Calculate Parallel Resistance
- Current through resistor
- Energy Conversion 2
- Mass Conversion 1
- Convert from Fahrenheit to Celsius
- Return area of square
- Area Conversion 1
- Create times-tables
- Triangle Numbers
- How long do each of the stages of the rocket take to burn?
- Finding Perfect Squares
- Magnitude of Balancing Force
- Mechanical Advantage of a Gear Train
- Calculate load on arm 1
- Find the mass of a rod
- Find the force required to support a lever
- Coefficient of Kinetic friction
- Calculate the acceleration of a crate
- Coefficient of Sliding Friction
- Coefficient of Static friction
- Linear Motion 1
- Linear Motion 2
- Linear Motion 3
- Linear Motion 4
- Linear Motion 5
- Linear Motion 6
- Linear Motion 7
- Basic Mathematics 1
- Basic Mathematics 2
- Basic Mathematics 3
- Basic Mathematics 4
- Basic Mathematics 5
- Basic Mathematics 6
- Basic Mathematics 7
- Basic Mathematics 8
- Resistance of a robot
- Voltage in a lamp
- Resistance in a circuit
- Calculate supply voltage and total current
Problem Recent Solvers7596
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!