Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

divide image into two equal parts python opencv

can someone tell me how to implement a bisection of the image into upper and lower part? so that I could overlap them. for example, I have an image and I should divide it to calculate a number of pixels on each part. I am new to OpenCV and don't exactly understand the geometry of the image.

like image 858
AinurZhappass Avatar asked Nov 27 '22 20:11

AinurZhappass


1 Answers

To simplify @avereux's answer:

In Python you can use splicing to break down an image into sub-images. The syntax for this is:

sub_image = full_image[y_start: y_end, x_start:x_end]

Note that for images, the origin is the top-left corner of the image. So a pixel on the first row of the image (that is the topmost row) would have coordinates x_coordinate = x, y_coordinate = 0

To get the shape of the image, use image.shape. This returns (no_of_rows, no_of_cols)

You can use these to break down the image any which way you want.

like image 72
Shawn Mathew Avatar answered Dec 04 '22 08:12

Shawn Mathew