图像分解python_将图像等分为两部分python open

这篇博客介绍了如何使用Python的OpenCV库将图像水平分割成两部分。首先,通过`cv2.imread`读取图像,然后获取图像的高度和宽度。接着,根据图像高度的50%作为分割点,进行裁剪操作,分别得到图像的上半部分和下半部分。最后,显示裁剪后的图像,并计算每个部分的像素数量。
摘要由CSDN通过智能技术生成

您可以将图像的顶部和底部水平裁剪到中间。

打开图像。import cv2

import numpy as np

image = cv2.imread('images/blobs1.png')

cv2.imshow("Original Image", image)

cv2.waitKey(0)

使用image.shape让我们捕获高度和宽度变量。height, width = image.shape[:2]

print image.shape

现在我们可以开始修剪了。# Let's get the starting pixel coordiantes (top left of cropped top)

start_row, start_col = int(0), int(0)

# Let's get the ending pixel coordinates (bottom right of cropped top)

end_row, end_col = int(height * .5), int(width)

cropped_top = image[start_row:end_row , start_col:end_col]

print start_row, end_row

print start_col, end_col

cv2.imshow("Cropped Top", cropped_top)

cv2.waitKey(0)

cv2.destroyAllWindows()

# Let's get the starting pixel coordiantes (top left of cropped bottom)

start_row, start_col = int(height * .5), int(0)

# Let's get the ending pixel coordinates (bottom right of cropped bottom)

end_row, end_col = int(height), int(width)

cropped_bot = image[start_row:end_row , start_col:end_col]

print start_row, end_row

print start_col, end_col

cv2.imshow("Cropped Bot", cropped_bot)

cv2.waitKey(0)

cv2.destroyAllWindows()

最后,我们可以使用image.size来给出每个部分的像素数。cropped_top.size

cropped_bot.size

您可以对轮廓执行相同的操作,但它将涉及边界框。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值