Ask Your Question
0

How to crop images using python?

asked 2020-03-03 04:19:26 -0600

kanankhan gravatar image

Hello, I have image like this: image description

I have found contours of black regions and using moments I found out their centers ,I need to crop them out now. Which method do you suggest for me to crop them ? thanks in advance.

edit retag flag offensive close merge delete

Comments

You want cropped each black?

supra56 gravatar imagesupra56 ( 2020-03-05 20:46:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-03 07:03:58 -0600

kbarni gravatar image

If you need the individual regions, use connectedComponentsWithStats. It will give you the bounding box of each region, then use this to crop the image.

If you need to crop out the zone which contains all the black patches, make a horizontal and vertical sum on the image using cv2.reduce. Then look for the first and last column/row where the sum of elements is greater than 0.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-03-03 04:19:26 -0600

Seen: 626 times

Last updated: Mar 03 '20