zoukankan      html  css  js  c++  java
  • python numpy初始化一个图像矩阵

    mask_all = np.zeros((256, 256), dtype='uint8')  单通道

    mask_all_enlarge = np.zeros((256, 256, 3), dtype='uint8'  三通道

    #为三通道图像赋值,这里我用的是循环,因该还有更简单的方式

    img_base = np.zeros((256, 256, 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

    另外python中使用cv2读写图像与skimage.io.读写图像时,三个通道之间的顺序是不相同的,使用的时候最好统一使用同一个,如果一不小心用一个读,另一个写,后面还可以再读入写出进行调换,就是比较麻烦了。

  • 相关阅读:
    soj#547 bzoj5046 分糖果游戏
    soj#551 loj#2833 帐篷
    nb哒LCA
    soj#532 set p3175
    p4042 [AHOI2014/JSOI2014]骑士游戏
    p1501 [国家集训队]Tree II
    908G New Year and Original Order
    908D New Year and Arbitrary Arrangement
    EZOJ #258
    EZOJ #257
  • 原文地址:https://www.cnblogs.com/rainsoul/p/7940400.html
Copyright © 2011-2022 走看看