简体   繁体   中英

Numpy Array combining arrays

I don't know if this question is asked already but I don't know how to word it correctly in order to find a solution.

I basicly want to add extra values to BGR-colorvalues of an image. The current ndarray is of the following shape: (352, 640, 3), where 352 and 640 are the width and height and the 3 are the Blue Green and Red color values. Extra values are to be added to the last 'column?'. I have a (352, 640) shaped array ready to add to the image array. The desired shape is (352, 640, 4).

The code is something like this:

image = cv.imread(*image_name*) # Shape (352, 640, 3)
dog_filtered = some_dog_filter(img) # Shape (352, 640)

# Some way the dog_filtered (grayscale image) needs to be added to the 3 colorvalues of the original image

Can anyone help?

I found the answer!

np.dstack seemed to give the correct result.

result = np.dstack((image, dog_filtered))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM