Mercurial > ift6266
comparison transformations/slant.py @ 45:f8a92292b299
merge de 4 fevrier
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Thu, 04 Feb 2010 10:27:58 -0500 |
parents | 0f1337994716 |
children |
comparison
equal
deleted
inserted
replaced
44:5deccb161307 | 45:f8a92292b299 |
---|---|
4 ''' | 4 ''' |
5 Author: Youssouf | 5 Author: Youssouf |
6 | 6 |
7 this module add a slant effect to the image. | 7 this module add a slant effect to the image. |
8 | 8 |
9 To obtain the slant effect, each row of the array is shifted proportionately by a step | 9 To obtain the slant effect, each row of the array is shifted proportionately by a step controlled by the complexity. |
10 controlled by the complexity. | |
11 | 10 |
12 ''' | 11 ''' |
13 | 12 |
14 import numpy | 13 import numpy |
15 | 14 |
72 | 71 |
73 return output | 72 return output |
74 | 73 |
75 | 74 |
76 # Test function | 75 # Test function |
76 # Load an image in local and create several samples of the effect on the | |
77 # original image with different parameter. All the samples are saved in a single image, the 1st image being the original. | |
78 | |
77 def test_slant(): | 79 def test_slant(): |
78 img_name = "3.png" | 80 import scipy |
79 dest_img_name = "slanted.png" | 81 img_name = "test_img/mnist_0.png" |
80 im = Image.open(img_name,) | 82 dest_img_name = "test_img/slanted.png" |
83 nb_samples = 10 | |
84 im = Image.open(img_name) | |
81 im = im.convert("L") | 85 im = im.convert("L") |
82 image = numpy.asarray(im) | 86 image = numpy.asarray(im) |
83 | 87 |
88 image_final = image | |
89 slant = Slant() | |
90 for i in range(nb_samples): | |
91 slant.regenerate_parameters(1) | |
92 image_slant = slant.transform_image(image) | |
93 image_final = scipy.hstack((image_final,image_slant)) | |
84 | 94 |
85 slant = Slant() | 95 im = Image.fromarray(image_final.astype('uint8'), "L") |
86 slant.regenerate_parameters(1) | |
87 image = slant.transform_image(image) | |
88 | |
89 im = Image.fromarray(image.astype('uint8'), "L") | |
90 im.save(dest_img_name) | 96 im.save(dest_img_name) |
91 | 97 |
92 # Test | 98 # Test |
93 if __name__ == '__main__': | 99 if __name__ == '__main__': |
94 import sys, os, fnmatch | 100 import sys, os, fnmatch |