Exemplo n.º 1
0
 def genImage(self, filename):
     "generate this image"
     image = PIL.Image.open(filename)
     if image.mode != self.getConfig('color'):
         image = image.convert(self.getConfig('color'))
     crop_left = self.getConfig('crop_left')
     crop_upper = self.getConfig('crop_upper')
     crop_right = self.getConfig('crop_right')
     crop_lower = self.getConfig('crop_lower')
     if crop_right and crop_lower:
         image = image.crop((crop_left, crop_upper, crop_right, crop_lower))
     (x, y) = image.size
     if x > self.width:
         y = y * self.width / x
         x = self.width
     if y > self.height:
         x = x * self.height / y
         y = self.height
     if x == 0:
         x = 1
     if y == 0:
         y = 1
     image = image.resize((x, y))
     tempFile = utility.saveImage(image, self.getConfig('format'))
     if not self.image:
         self.manage_addProduct['Image'].manage_addImage(
             'image', tempFile, 'image')
     else:
         self.image.manage_upload(tempFile)
     self.image.width = int(x)
     self.image.height = int(y)
     self.setFileSize()
Exemplo n.º 2
0
 def resizeImage(self, filename):
     "generate this image"
     image=PIL.Image.open(filename)
     if image.mode != self.getConfig('color'):
         image=image.convert(self.getConfig('color'))
     maxWidth = self.getConfig('width')
     maxHeight = self.getConfig('height')
     crop_left = self.getConfig('crop_left')
     crop_upper =  self.getConfig('crop_upper')
     crop_right =  self.getConfig('crop_right')
     crop_lower = self.getConfig('crop_lower')
     if crop_right and crop_lower:
         image = image.crop((crop_left, crop_upper, crop_right, crop_lower))
     (x, y) = image.size
     if x> maxWidth:
         y = y * maxWidth / x
         x = maxWidth
     if y> maxHeight:
         x = x * maxHeight / y
         y = maxHeight
     if x == 0:
         x = 1
     if y == 0:
         y = 1
     image = image.resize((x, y))
     tempFile = utility.saveImage(image, self.getConfig('format'))
     self.data.manage_upload(tempFile)
     self.data.width = x
     self.data.height = y
Exemplo n.º 3
0
    def makeThumbnail(self, filename):
        """
        Makes a thumbnail image given an image Id when called on a Zope
        folder.

        The thumbnail is a Zope image object that is a small JPG
        representation of the original image. The thumbnail has a
        'original_id' property set to the id of the full size image
        object.
        """
        size=30
        data = self.data or self.image
        content_type = magicfile.magic(filename)
        if content_type.startswith('image'):
            image=Image.open(filename)
            image=image.convert('RGB')
            (x,y) = image.size
            if x > size: x = size
            if y > size: y = size
            image = image.resize((x,y))
            thumbnail_file = utility.saveImage(image, 'JPEG')
            thumbnail_id = "thumbnail"
            if not getattr(self, thumbnail_id):
                self.manage_addProduct['Image'].manage_addImage(thumbnail_id, thumbnail_file, thumbnail_id)
            else:
                self._getOb(thumbnail_id).manage_upload(thumbnail_file)
Exemplo n.º 4
0
 def genImage(self, filename):
     "generate this image"
     image=PIL.Image.open(filename)
     if image.mode != self.getConfig('color'):
         image=image.convert(self.getConfig('color'))
     crop_left = self.getConfig('crop_left')
     crop_upper =  self.getConfig('crop_upper')
     crop_right =  self.getConfig('crop_right')
     crop_lower = self.getConfig('crop_lower')
     if crop_right and crop_lower:
         image = image.crop((crop_left, crop_upper, crop_right, crop_lower))
     (x, y) = image.size
     if x> self.width:
         y = y * self.width / x
         x = self.width
     if y> self.height:
         x = x * self.height / y
         y = self.height
     if x == 0:
         x = 1
     if y == 0:
         y = 1
     image = image.resize((x, y))
     tempFile = utility.saveImage(image, self.getConfig('format'))
     if not self.image:
         self.manage_addProduct['Image'].manage_addImage('image', tempFile, 'image')
     else:
         self.image.manage_upload(tempFile)
     self.image.width = int(x)
     self.image.height = int(y)
     self.setFileSize()
Exemplo n.º 5
0
 def resizeImage(self, filename):
     "generate this image"
     image = PIL.Image.open(filename)
     if image.mode != self.getConfig('color'):
         image = image.convert(self.getConfig('color'))
     maxWidth = self.getConfig('width')
     maxHeight = self.getConfig('height')
     crop_left = self.getConfig('crop_left')
     crop_upper = self.getConfig('crop_upper')
     crop_right = self.getConfig('crop_right')
     crop_lower = self.getConfig('crop_lower')
     if crop_right and crop_lower:
         image = image.crop((crop_left, crop_upper, crop_right, crop_lower))
     (x, y) = image.size
     if x > maxWidth:
         y = y * maxWidth / x
         x = maxWidth
     if y > maxHeight:
         x = x * maxHeight / y
         y = maxHeight
     if x == 0:
         x = 1
     if y == 0:
         y = 1
     image = image.resize((x, y))
     tempFile = utility.saveImage(image, self.getConfig('format'))
     self.data.manage_upload(tempFile)
     self.data.width = x
     self.data.height = y
Exemplo n.º 6
0
    node_shape = ((80, 52), (74, 46), (34, 20))
    filter_shift_list = ((1, 1), (2, 2))
    input_shape = [80, 52]
    filter_shape = [7, 7]

    data_list = load_image(data_path, file_num, isRGB)

    makeFolder()

    # 時間計測
    time1 = time.clock()

    cnn1 = CNN(data_list, filter_shape, filter_shift_list[0], input_shape, node_shape[1], pre_train_lr, pre_train_epoch)

    output_list = cnn1.output()
    saveImage(output_list, node_shape[1], 'cnn1_before_training')

    cnn1.pre_train()
    output_list = cnn1.output()
    saveImage(output_list, node_shape[1], 'cnn1_after_training')

    # for i in xrange(pre_train_epoch):
    # 	cnn1.pre_train()
    # 	output_list = cnn1.output()
    # 	saveImage(output_list, (74,46))

    cnn2 = CNN(cnn1.output(), filter_shape, filter_shift_list[1], node_shape[1], node_shape[2], pre_train_lr, pre_train_epoch)
    output_list = cnn2.output()
    saveImage(output_list, node_shape[2], 'cnn2_before_train')

    cnn2.pre_train()
Exemplo n.º 7
0
    result_path = 'data/kouryu_room/cnn2_after_training'
    result_data = load_result_image(result_path, file_num, isRGB)

    # result_path = 'data/4position_rumba/image7000/rbm1_train3434'
    # result_W = loadW(result_path)

    makeFolder()

    # def __init__(self, W, input, data_size,input_size, output_size, isDropout):
    rbm1 = RBM(None, result_data, file_num, rbm_size_list[0], rbm_size_list[1])
    for i in xrange(pre_train_epoch):
        print 'rbm1 pre_train:' + str(i)
        rbm1.contrast_divergence(i)
    reinput = rbm1.reconstruct_from_input(rbm1.input)
    saveImage(reinput, node_shape[2], 'rbm1_after_train')
    saveW(rbm1.getW(), 'rbm1_after_train')

    rbm2 = RBM(None, rbm1.output(), file_num, rbm_size_list[1], rbm_size_list[2])
    for i in xrange(pre_train_epoch):
        print 'rbm2 pre_train:' + str(i)
        rbm2.contrast_divergence(i)
    reinput = rbm2.reconstruct_from_input(rbm2.input)
    reinput = rbm1.reconstruct_from_output(reinput)
    saveImage(reinput, node_shape[2], 'rbm2_after_train')
    saveW(rbm2.getW(), 'rbm2_after_train')

    rbm3 = RBM(None, rbm2.output(), file_num, rbm_size_list[2], rbm_size_list[3])
    for i in xrange(pre_train_epoch):
        print 'rbm3 pre_train:' + str(i)
        rbm3.contrast_divergence(i)