oI have a binary image which is the segmented form of another color image .
As you know, a binary image is 2-d but an RGB image is 3-d, how can I multiply them together? please hope
Convert your image and mask to numpy arrays. Element-wise multiplication with numpy arrays can simply be done without any special treatment. For example:
a = np.random.randint(0,10,(3,2,2)) # RGB of size 2x2
b = np.random.randint(0,2,(2,2)) # Binary mask of size 2x2
c = a*b
Output:
a = array([ [[7, 6],
[5, 8]],
[[1, 3],
[8, 5]],
[[1, 8],
[4, 4]]])
b = array( [[1, 0],
[0, 1]])
c = array([ [[7, 0],
[0, 8]],
[[1, 0],
[0, 5]],
[[1, 0],
[0, 4]]])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.