# How to crop this image?

**URL:** <https://forum.opencv.org/t/how-to-crop-this-image/16208>\
**Category:** Python\
**Created:** [January 19, 2024, 7:16am UTC](https://forum.opencv.org/t/how-to-crop-this-image/16208 "2024-01-19T07:16:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keki](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/keki/32/9567_2.png) [@keki](https://forum.opencv.org/u/keki)\
**Post date:** [January 19, 2024, 7:16am UTC](https://forum.opencv.org/t/how-to-crop-this-image/16208/1 "2024-01-19T07:16:46Z")

</div>

Hi,

I’m wondering if it would be possible to crop this image so that all the white around the outside of the black is removed. It’s important that the white inside the black shape remains though.

Thanks in advance

 ![new](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/a/a3f1189cf823c614182d36a1f9d93fa52f821751.jpeg)

---

<div class="post-metadata">

**Author:** ![anoduck](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anoduck/32/9825_2.png) [@anoduck](https://forum.opencv.org/u/anoduck)\
**Post date:** [January 29, 2024, 1:08pm UTC](https://forum.opencv.org/t/how-to-crop-this-image/16208/2 "2024-01-29T13:08:04Z")

</div>

Pillow is probably going to be your easiest route to avoid getting stuck in a type error.

```python
from PIL import Image

# Read the image
im = Image.open("sample-image.png")

# Rotate image
angle = 10
rotated = im.rotate(angle)
w, h = yourImage.size
cropped = out.crop((0, 30, w, h-30))
cropped.save('rotate-output.png')

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 29, 2024, 1:54pm UTC](https://forum.opencv.org/t/how-to-crop-this-image/16208/3 "2024-01-29T13:54:21Z")

</div>

I think OP meant masking, not cropping.
