Blame view

complexnn/create_rgb.py 1.75 KB
8a1d43c41   Parcollet Titouan   V1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  # Author: Titouan Parcollet
  
  from PIL import Image
  import numpy as np
  import sys
  import os
  
  def reconstruct(size):
      path = "Results/"+str(size)
      if not os.path.exists(str(path)):
          os.makedirs(str(path))
  
      if not os.path.exists(str(path)+"/TRAIN"):
          os.makedirs(str(path)+"/TRAIN")
  
      if not os.path.exists(str(path)+"/TEST"):
          os.makedirs(str(path)+"/TEST")
  
      ######## Process Train pictures
      data = open(path+'_train.dat')
      a = data.readlines()
      z=0
      for line in a:
          line = line.split(" ")
          img = Image.new( 'RGB', (32,32), "black" ) # create a new black image
          pixels = img.load()                        # create the pixel map
          for i in range(0,img.size[0]):             # for every pixel:
              for j in range(0,img.size[1]):
                  
                  pixels[j,i] = (int(float(line[(i*(img.size[0])*3)+(j*3)])), int(float(line[(i*(img.size[0])*3)+(j*3)+1])), int(float(line[(i*(img.size[0])*3)+(j*3)+2]))) 
          z+=1
          img.save(path+"/TRAIN/train"+str(z)+".jpg", "JPEG")
  
      ######## Process Test pictures
      data = open(path+'_test.dat')
      a = data.readlines()
      z=0
      for line in a:
          line = line.split(" ")
          img = Image.new( 'RGB', (32,32), "black" ) # create a new black image
          pixels = img.load()                        # create the pixel map
          for i in range(0,img.size[0]):             # for every pixel:
              for j in range(0,img.size[1]):
                  pixels[j,i] = (int(float(line[(i*(img.size[0])*3)+(j*3)])), int(float(line[(i*(img.size[0])*3)+(j*3)+1])), int(float(line[(i*(img.size[0])*3)+(j*3)+2]))) 
          z+=1
          img.save(path+"/TEST/test"+str(z)+".jpg", "JPEG")
      return