Python numpy Initializes a matrix of images

Source: Internet
Author: User

Mask_all = Np.zeros ((at (), dtype= ' uint8 ') Single channel

Mask_all_enlarge = Np.zeros ((3), dtype= ' uint8 ' three channels

#为三通道图像赋值, I'm using loops here, because there's a simpler way.

Img_base = Np.zeros ((3), np.uint8)

For I in range (256):
For j in Range (256):
Img_base[i, j, 0] = np.uint8 (123.7)
Img_base[i, j, 1] = Np.uint8 (116.8)
Img_base[i, J, 2] = Np.uint8 (103.9)

#为图像的一部分赋值为另外一附图像
img_base[64:192, 104:152] = img

#两幅图像之间可以直接进行或运算:

Mask_all = Mask_all | r[' Masks ' [:,:, I]

Mask_all = Mask_all | r[' Masks ' [:,:, Person_index]

#将单通道图像依次填充到三通道图像中:

mask_all_enlarge[:,:, 0] = Mask_all
mask_all_enlarge[:,:, 1] = Mask_all
mask_all_enlarge[:,:, 2] = Mask_all

#两个三通道图像可以直接进行乘法运算:

Image_mask = Mask_all_enlarge * img_base

In addition Python uses cv2 read and write images and Skimage.io. When reading and writing images, the order of three channels is not the same, the use of the best uniform use of the same, if accidentally with a read, another write, back can also read into the write to exchange, is more trouble.

Python numpy Initializes a matrix of images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.