# How to crop an image like MATLAB's imcrop function?

**URL:** <https://forum.opencv.org/t/how-to-crop-an-image-like-matlabs-imcrop-function/4611>\
**Category:** Python\
**Created:** [August 5, 2021, 7:50am UTC](https://forum.opencv.org/t/how-to-crop-an-image-like-matlabs-imcrop-function/4611 "2021-08-05T07:50:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zyder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/zyder/32/2825_2.png) [@Zyder](https://forum.opencv.org/u/Zyder)\
**Post date:** [August 5, 2021, 7:50am UTC](https://forum.opencv.org/t/how-to-crop-an-image-like-matlabs-imcrop-function/4611/1 "2021-08-05T07:50:26Z")

</div>

I have to translate a MATLAB code to Python, and I have to crop an image by using a given window (a rectangle). In MATLAB, the syntax is the next:

recorte = imcrop(im, v)

recorte is the cropped image, im is the image and v the rectangle window I’m using to crop it. How it would work in CV? I’m looking everywhere and didn’t get a solution.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 5, 2021, 8:06am UTC](https://forum.opencv.org/t/how-to-crop-an-image-like-matlabs-imcrop-function/4611/2 "2021-08-05T08:06:30Z")

</div>

> [@Zyder](#):
>
> I’m looking everywhere and didn’t get a solution.

hahahahaha you can have done much, if you missed _that_ …

it’s just a numpy slice here (look it up, please !):

```
crop = img[y:y+h, x:x+w]

```

---

<div class="post-metadata">

**Author:** ![Zyder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/zyder/32/2825_2.png) [@Zyder](https://forum.opencv.org/u/Zyder)\
**Post date:** [August 5, 2021, 8:21am UTC](https://forum.opencv.org/t/how-to-crop-an-image-like-matlabs-imcrop-function/4611/3 "2021-08-05T08:21:39Z")

</div>

but how can I implement this with the code I have? I have seen this before but I don’t know it

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 5, 2021, 8:23am UTC](https://forum.opencv.org/t/how-to-crop-an-image-like-matlabs-imcrop-function/4611/4 "2021-08-05T08:23:13Z")

</div>

> [@Zyder](#):
>
> but how can I implement this with the code I have?

we can only help with what we can see.
