📘
Crop Image
EasyImage Processing
Implement a function to extract a rectangular region from an image, given the top-left corner coordinates (row,col) and the dimensions (height,width). This task involves image processing and region of interest extraction.
The concept of cropping an image is fundamental in computer vision, as it allows for focusing on specific parts of an image, reducing noise, and improving processing efficiency. In mathematical terms, the cropped image can be represented as a subset of the original image pixels, defined by the bounds row≤y≤row+height and col≤x≤col+width.
To achieve this, consider the following steps:
- Identify the top-left corner coordinates (row,col).
- Determine the dimensions (height,width) of the region to be extracted.
- Extract the sub-image using the specified bounds.
This technique is widely used in image editing and object detection applications.
Example:
Input:
crop([[1,2,3],[4,5,6],[7,8,9]], 0, 0, 2, 2)
Output:
[[1,2],[4,5]]
Reasoning:
Extract 2x2 region from top-left corner
Constraints:
- The crop region must be within image bounds
- Return the cropped sub-image
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.