有人能告诉我如何实现图像的上下两部分?这样我可以重叠他们。例如,我有一个图像,我应该把它分开来计算每个部分的像素数量。我是OpenCV的新手,并不完全了解图像的几何形状。将图像分成两个相等的部分python opencv
-2
A
回答
2
您可以水平向下剪切图像的顶部和底部。
打开图片。
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
你可以用轮廓做同样的事情,但它会涉及包围盒。
1
为了简化@ avereux的回答是:
在Python中你可以使用拼接打破图像到子图像。语法如下:
sub_image = full_image[y_start: y_end, x_start:x_end]
请注意,对于图像,原点是图像的左上角。因此,图像第一行(即最上面一行)上的像素将具有坐标x_coordinate = x,y_coordinate = 0
要获取图像的形状,请使用image.shape
。这返回(no_of_rows, no_of_cols)
您可以使用这些来打破您想要的任何方式的图像。
相关问题
- 1. 将饼图分成相等部分jfreechart
- 2. 将视图拆分成相等部分
- 3. 如何将一个NSArray分成两个相等的部分?
- 4. 如何在Android上将一个大图像分成8个相等部分
- 5. 将树拆分成相等部分
- 6. 将文本拆分成相等部分
- 7. Python - 将列表随机分成几乎相等的部分
- 8. 拍摄图像并将其分成3个相同的部分
- 9. 划分一个图像划分成相等的像素数据
- 10. OpenCV Python将图像的某些部分复制到另一个
- 11. 将单独的列表分成两个相等的部分和切片
- 12. 如何在两个相等的部分
- 13. 将矩形分成n个相等的部分
- 14. 将画面划分成N个相等的部分
- 15. 如何将一个数组分成两部分,这两部分的平均值相等?
- 16. 如何在Python中将数字分成多个不相等的部分?
- 17. OpenCV筛选部分图像
- 18. 将在python两个部分
- 19. F#:递归函数:将列表拆分成两个相等部分
- 20. css使用填充将div分成四个相等部分
- 21. 将wordpress分成两部分
- 22. 将PDL分成两部分
- 23. 将列分成两部分
- 24. 如何将图像分成2部分?
- 25. 加法混合两个部分重叠的图像OpenCV的
- 26. 表面细分成相等部分
- 27. 如何将矢量分成N“几乎相等”的部分
- 28. 将屏幕分成与溢出相等的部分
- 29. 如何将长度分成与提醒相等的部分?
- 30. 如何将图片剪成相等的部分?
你能详细说说“水平分割图像的轮廓”吗? –
请阅读[问] – Miki
请阅读关于沟通技巧的书 – Piglet