使用OpenCV线性梯度掩码

发布于 2025-01-26 11:42:35 字数 311 浏览 1 评论 0原文

首先,对不起,我的英语不好。这里问题的答案绝对是我正在寻找的答案,我正在寻找使用OpenCV或创建线性梯度掩码,但我想将此带垂直。我该怎么做? @hanshirse

First of all, sorry for my bad english. The answer to the question here is definitely the answer I was looking for Creating a Linear Gradient Mask using opencv or but I want to make this strip vertical. How can I do that? @HansHirse

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤痕我心 2025-02-02 11:42:35

我找到了我问题的答案。我创建了一个名为Mask3的掩码,然后将其等同于NP.Rot90(Mask1)

mask3 = np.rot90(mask1)

I found the answer to my question. I created a third mask called mask3 and I equated it to np.rot90(mask1)

mask3 = np.rot90(mask1)
烟火散人牵绊 2025-02-02 11:42:35

这是如何在Python/OpenCV/Numpy中制作水平和垂直线性梯度图像。不同之处在于,转置操作是在瓷砖操作内部还是外部。

import cv2
import numpy as np

# horizontal gradient ramp
ramp_width = 500
ramp_height = 200
ramp = np.linspace(0, 255, ramp_width, dtype=np.uint8)
ramp_horizontal = np.tile(np.transpose(ramp), (ramp_height,1))
ramp_horizontal = cv2.merge([ramp_horizontal,ramp_horizontal,ramp_horizontal])
cv2.imshow("horizontal_ramp", ramp_horizontal)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("horizontal_ramp.jpg", ramp_horizontal)

# vertical gradient ramp
ramp_width = 200
ramp_height = 500
ramp = np.linspace(0, 255, ramp_height, dtype=np.uint8)
ramp_vertical = np.transpose(np.tile(ramp, (ramp_width,1)))
cv2.merge([ramp_vertical,ramp_vertical,ramp_vertical])
cv2.imshow("vertical_ramp", ramp_vertical)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("vertical_ramp.jpg", ramp_vertical)

水平坡道:

“在此处输入图像描述”

垂直坡道:

Here is how to make both horizontal and vertical linear gradient image in Python/OpenCV/Numpy. The difference is whether the transpose operation is inside or outside the tile operation.

import cv2
import numpy as np

# horizontal gradient ramp
ramp_width = 500
ramp_height = 200
ramp = np.linspace(0, 255, ramp_width, dtype=np.uint8)
ramp_horizontal = np.tile(np.transpose(ramp), (ramp_height,1))
ramp_horizontal = cv2.merge([ramp_horizontal,ramp_horizontal,ramp_horizontal])
cv2.imshow("horizontal_ramp", ramp_horizontal)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("horizontal_ramp.jpg", ramp_horizontal)

# vertical gradient ramp
ramp_width = 200
ramp_height = 500
ramp = np.linspace(0, 255, ramp_height, dtype=np.uint8)
ramp_vertical = np.transpose(np.tile(ramp, (ramp_width,1)))
cv2.merge([ramp_vertical,ramp_vertical,ramp_vertical])
cv2.imshow("vertical_ramp", ramp_vertical)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("vertical_ramp.jpg", ramp_vertical)

Horizontal Ramp:

enter image description here

Vertical Ramp:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文