Reputation: 41
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
Upvotes: 1
Views: 880
Reputation: 53071
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:
Vertical Ramp:
Upvotes: 1
Reputation: 41
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)
Upvotes: 3