zoukankan      html  css  js  c++  java
  • 使用矩阵存图,读图

    #把30张图片存成矩阵
    import numpy as np,os
    import PIL.Image as pim#处理图片的工具库
    import pickle as pic#矩阵的序列化和反序列化
    class imagew:
        def imageToArray(self,dir):
            image_list=[];
            sdir=os.listdir(dir)
    
            for i in sdir:
                path=os.path.join(dir,i)
                im=pim.open(path,"r")
                r,g,b=im.split()#得到一张图片的rgb值
                rgb1=np.array(r).reshape((921600,))
                rgb2=np.array(g).reshape((921600,))
                rgb3=np.array(b).reshape((921600,))
                timage=np.hstack((rgb1,rgb2,rgb3))#一张图片
    
                fiimalist=np.concatenate((image_list,timage))
            allimage=fiimalist.reshape(len(sdir),2764800)
    
            with open("image.bat",mode="wb") as f:
                pic.dump(fiimalist,f)
            os.close(1)
    
    
        @staticmethod
        def readImage(file):
            f=open(file,"rb")
            allimage=pic.load(f)
            # image_count=allimage.shape[0]#图片个数
            all_array=np.reshape(allimage,(3,1280,720))
            for i in range(0,0):
    
                r=pim.fromarray(all_array[i][0],mode="RGB")
                g=pim.fromarray(all_array[i][0],mode="RGB")
                b=pim.fromarray(all_array[i][0],mode="RGB")
                imares=pim.merge("RGB",[r,g,b])
                imares.show()
                pim.save("result%s.jpg","jpeg")
    class test:
        if __name__ == '__main__':
            i = imagew()
            i.imageToArray("image")
            i.readImage("image.bat")
    

      

  • 相关阅读:
    获取窗口句柄,并向窗口发送自定义消息
    双向链表总结
    循环链表总结
    顺序队列总结
    链式栈总结
    顺序栈的总结
    链式队列总结
    源码网址
    通用型动态数组的总结
    单链表的链式存储总结
  • 原文地址:https://www.cnblogs.com/huiandong/p/9550963.html
Copyright © 2011-2022 走看看