• 吴裕雄 python深度学习与实践(7)


    import cv2
    import numpy as np
    
    img = np.mat(np.zeros((300,300)))
    cv2.imshow("test",img)
    cv2.waitKey(0)
    import cv2
    import numpy as np
    
    img = np.mat(np.zeros((300,300),dtype=np.uint8))
    cv2.imshow("test",img)
    cv2.waitKey(0)
    import cv2
    import numpy as np
    
    image = np.mat(np.zeros((300,300)))
    imageByteArray = bytearray(image)
    print(imageByteArray)
    imageBGR = np.array(imageByteArray).reshape(800,900)
    cv2.imshow("cool",imageBGR)
    cv2.waitKey(0)
    import os
    import cv2
    import numpy as np
    
    randomByteArray = bytearray(os.urandom(120000))
    flatNumpyArray = np.array(randomByteArray).reshape(300,400)
    cv2.imshow("cool",flatNumpyArray)
    cv2.waitKey(0)
    import cv2
    import numpy as np
    img = np.zeros((300,300))
    img[0,0] = 255
    cv2.imshow("img",img)
    cv2.waitKey(0)
    import cv2
    import numpy as np
    
    img = np.zeros((300,300))
    img[:,10] = 255
    img[10,:] = 255
    cv2.imshow("img",img)
    cv2.waitKey(0)
    import cv2
    import numpy as np
    
    from scipy import ndimage
    
    kernel33 = np.array([[-1,-1,-1],
                         [-1,8,-1],
                         [-1,-1,-1]])
    
    kernel33_D = np.array([[1,1,1],
                           [1,-8,1],
                           [1,1,1]])
    
    img = cv2.imread("G:\MyLearning\TensorFlow_deep_learn\data\lena.jpg",0)
    linghtImg = ndimage.convolve(img,kernel33_D)
    cv2.imshow("img",linghtImg)
    cv2.waitKey()

    import numpy as np
    import cv2
    from scipy import ndimage
    
    img = cv2.imread("lena.jpg",0)
    blurred = cv2.GaussianBlur(img,(11,11),0)
    gaussImg = img - blurred
    cv2.imshow("img",gaussImg)
    cv2.waitKey()

    import numpy as np
    
    def convolve(dateMat,kernel):
        m,n = dateMat.shape
        km,kn = kernel.shape
        newMat = np.ones(((m - km + 1),(n - kn + 1)))
        tempMat = np.ones(((km),(kn)))
        for row in range(m - km + 1):
            for col in range(n - kn + 1):
                for m_k in range(km):
                    for n_k in range(kn):
                        tempMat[m_k,n_k] = dateMat[(row + m_k),(col + n_k)] * kernel[m_k,n_k]
                newMat[row,col] = np.sum(tempMat)
        return newMat
    
    dateMat = np.mat([
        [1,2,1,2,0,1,0,1,1],
        [0,3,1,1,0,0,1,0,1],
        [1,2,1,0,2,1,1,0,0],
        [2,2,0,1,1,1,1,1,0],
        [3,1,1,0,1,1,0,0,1],
        [1,0,1,1,1,0,0,1,1],
        [1,1,1,1,0,1,1,1,1],
        [1,0,1,1,0,1,0,1,0],
        [0,1,1,1,1,2,0,1,0]
    ])
    
    kernel = np.mat([
        [1,0,1],
        [0,-4,0],
        [1,0,1]
    ])
    
    newMat = convolve(dateMat,kernel)
    print(np.shape(newMat))
    print(newMat)

  • 相关阅读:
    js遍历删除对象的key
    MYBATIS XML SQL 结果为MAP类型时,KEY为大小问题解决
    Ubuntu SSH 失败
    Navicat 连接 Oracle Docker容器镜像报错:TNS:listener: all appropriate instances are blocking new connections
    Mybatis 定义 Oracle 存储过程,并获取存储输出字符串信息
    python基础之---else(十)
    python基础之---循环简介(九)
    python基础之---条件语句(八)
    python基础之---运算符(七)
    python基础之---转换数据类型(六)
  • 原文地址:https://www.cnblogs.com/tszr/p/10355621.html
Copyright © 2020-2023  润新知