def test__generate2DGaussianDistributions_max_le_1(self): xdim = 73 ydim = 71 dist = PatternedImage._generate2DGaussianDistribution((xdim, ydim)) maxval = max([max(row) for row in dist]) print("maxval = {}".format(maxval)) self.assertTrue(maxval <= 1.0)
def test__generate2DGaussianDistributions_min_ge_0(self): xdim = 67 ydim = 71 dist = PatternedImage._generate2DGaussianDistribution((xdim, ydim)) minval = min([min(row) for row in dist]) print("minval = {}".format(minval)) self.assertTrue(minval >= 0.0)
import os import random from imagecrosser import ImageCrosser from patternedimage import PatternedImage from shared import shared if __name__ == '__main__': dims = (1080, 1080) dpis = [2880 // i for i in [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16]] print(dpis) # img = PatternedImage.new(PatternedImage.diamonds, dims=dims, colours=[(209, 123, 193), (123, 193, 209), (12, 19, 29)]) # img = PatternedImage.new(PatternedImage.stripedMulti, dims=dims, colours=shared.randomRGBContrasting(5)) # img = PatternedImage.new(PatternedImage.diamonds, dims=dims, colours=shared.randomRGBPair()) currentGen = [PatternedImage.new(dims=dims) for i in range(10)] now = datetime.datetime.now() folder = now.strftime("generations\%Y%m%d_%H%M%S") os.mkdir(folder) for genID in range(12): print("\nWriting generation {}: ".format(genID), end='') count = 0 for img in currentGen: print("{}, ".format(count), end='') # img.save("{}\gen{}_{}.jpg".format(folder, genID, count)) img.save("{}\gen{}_{}.png".format(folder, genID, count)) count += 1
def test__parseColours_tupleList(self): l = [(100, 80, 60), (209, 123, 193), (0, 0, 0), (255, 255, 255)] self.assertEqual(l, PatternedImage._parseColoursList(l))
def test__parseColours_tuple_malformed(self): cs = PatternedImage._parseColoursList((100, 80)) self.assertEqual(1, len(cs)) self.assertEqual(3, len(cs[0])) self.assertEqual((100, 80), cs[0][:2])
def test__generateGaussianFilename_bw(self): filename = PatternedImage._generateGaussianFilename((540, 1080), [(0, 0, 0), (255, 255, 255)]) self.assertEqual("gaussians/540x1080/540x1080_0,0,0_255,255,255", filename)
def test__parseColours_tuple(self): self.assertEqual([(100, 80, 60)], PatternedImage._parseColoursList((100, 80, 60)))
def test__parseColours_255(self): self.assertEqual([(255, 255, 255)], PatternedImage._parseColoursList(255))
def test__parseColours_0(self): self.assertEqual([(0, 0, 0)], PatternedImage._parseColoursList(0))
def test__generate2DGaussianDistributions_size_y(self): xdim = 6 ydim = 7 dist = PatternedImage._generate2DGaussianDistribution((xdim, ydim)) self.assertEqual(ydim, len(dist))
def test__generate2DGaussianDistributions_size_x(self): xdim = 107 ydim = 103 dist = PatternedImage._generate2DGaussianDistribution((xdim, ydim)) self.assertEqual(xdim, len(dist[0]))
def test__generateGaussianDistributionFilename_mus_sigmas(self): filename = PatternedImage._generateGaussianDistributionFilename( (1080, 540), mus=[1080, 540], sigmas=[510, 80]) self.assertEqual( "gaussiandists/1080x540/1080x540_μs(1080,540)_σs(510,80).json", filename)
def test__generateGaussianDistributionFilename_mus(self): filename = PatternedImage._generateGaussianDistributionFilename( (540, 1080), mus=[0, 0]) self.assertEqual("gaussiandists/540x1080/540x1080_μs(0,0).json", filename)
def test__generateGaussianDistributionFilename_default(self): filename = PatternedImage._generateGaussianDistributionFilename( (540, 1080)) self.assertEqual("gaussiandists/540x1080/540x1080.json", filename)
""" Experiment to use Pillow to create Gaussians and help populate the stored distributions """ from patternedimage import PatternedImage from shared import shared if __name__ == '__main__': dims = (1080, 1080) img = PatternedImage.new(PatternedImage.gaussian, dims=dims, colours=[(0, 0, 0), (255, 255, 255), (0, 0, 0)]) # shared.randomRGBContrasting(2)) # [(209, 123, 193), (123, 193, 209)]) img.show()