zoukankan      html  css  js  c++  java
  • 【Numpy应用】--对于图片处理的机器学习库的应用

    一。思路
    二。代码:

    #
    coding:utf-8 import numpy as np import PIL.Image as Image import pickle as p import os class ImageTools(object): image_dir='images/' result_dir='results/' data_file_path='data.bin' def imageToArray(self,files): images=[] for i in range(len(files)): image=Image.open(ImageTools.image_dir+files[i]) r,g,b= image.split() r_array = np.array(r).reshape(62500) g_array = np.array(g).reshape(62500) b_array = np.array(b).reshape(62500) image_arry = np.concatenate((r_array,g_array,b_array)) images=np.concatenate((images,image_arry)) print(images.shape) images =np.array(images).reshape((len(files),(3*62500))) print(images.shape) f =open(ImageTools.data_file_path,'wb') p.dump(images,f) f.close() def readToImage(self,file): f = open(file,'rb') arr = p.load(f) # 30行,187500列 rows = arr.shape[0] new_arr =arr.reshape((rows,3,250,250)) # 把矩阵变成一个高维矩阵 for i in range(rows): r =Image.fromarray(new_arr[i][0]).convert("L") #把每个图片中RGB通道分离 g =Image.fromarray(new_arr[i][1]).convert("L") #把每个图片中RGB通道分离 b =Image.fromarray(new_arr[i][2]).convert("L") #把每个图片中RGB通道分离 image = Image.merge("RGB",(r,g,b)); # 合并RGB通道获得一张图片 # f =open(ImageTools.result_dir+str(i)+'.png','wb') image.save(ImageTools.result_dir+str(i)+'.png',"png") if __name__=="__main__": it = ImageTools() files= os.listdir(ImageTools.image_dir) # it.imageToArray(files) it.readToImage('data.bin')
  • 相关阅读:
    ant desigon Upload控件能否提供隐藏删除图标的属性以及鼠标停留在删除图标上的提示文字怎么设置为中文
    2月5日进度
    2月4日学习进度
    2月3日学习进度
    2月2日学习进度
    大数据之linux环境下jdk hadoop以及hbase,hive等配置
    MVC实例
    MVC简介
    23种设计模式
    xxx系统可用性和易用性分析
  • 原文地址:https://www.cnblogs.com/LHWorldBlog/p/7967911.html
Copyright © 2011-2022 走看看