File size: 4,317 Bytes
50f9d3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd5682
 
50f9d3b
bdd5682
 
 
50f9d3b
 
 
 
 
 
 
bdd5682
 
50f9d3b
 
 
bdd5682
 
 
222a385
50f9d3b
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
import os
import matplotlib
from randimage import get_random_image, show_array
from randimage import GaussianBlobMask, NormalMask, SaltPepperMask, EPWTPath, ProbabilisticPath, ColoredPath, show_array
import random
class make_im():
    self.c_maps=['Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Grays', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_grey', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gist_yerg', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'grey', 'hot', 'hot_r', 'hsv', 'hsv_r', 'inferno', 'inferno_r', 'jet', 'jet_r', 'magma', 'magma_r', 'nipy_spectral', 'nipy_spectral_r', 'ocean', 'ocean_r', 'pink', 'pink_r', 'plasma', 'plasma_r', 'prism', 'prism_r', 'rainbow', 'rainbow_r', 'seismic', 'seismic_r', 'spring', 'spring_r', 'summer', 'summer_r', 'tab10', 'tab10_r', 'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c', 'tab20c_r', 'terrain', 'terrain_r', 'turbo', 'turbo_r', 'twilight', 'twilight_r', 'twilight_shifted', 'twilight_shifted_r', 'viridis', 'viridis_r', 'winter', 'winter_r']
    
    self.img_size = (256,256)
    
    
    #mask = SaltPepperMask(img_size).get_mask()
    #mask = NormalMask(img_size).get_mask()
    self.mask = GaussianBlobMask(img_size).get_mask(3)
    
    # show_array(mask, cmap='gray')
    
    # mask = GaussianBlobMask().get_mask()
    
    self.epwtpath = EPWTPath(mask).get_path()
    self.ppath = ProbabilisticPath(mask).get_path()
    
    #cmap = 'Spectral'
    #cmap = 'terrain'
    def run_all(self):
        for ea in c_maps:
            cmap = ea
            self.epwtimg = ColoredPath(self.epwtpath, self.mask.shape).get_colored_path(cmap)
            self.pimg = ColoredPath(self.ppath, self.mask.shape).get_colored_path(cmap)
            if not os.path.isdir(f"./image_alls/{ea}"):
                os.mkdir(f'./images_all/{ea}')
            else: pass
            matplotlib.image.imsave(f"./images_all/{ea}/{ea}_mask.png", self.mask, cmap='gray')
            matplotlib.image.imsave(f"./images_all/{ea}/{ea}_epwt.png", self.epwtimg)
            matplotlib.image.imsave(f"./images_all/{ea}/{ea}_prob.png", self.pimg)
    
    def run_1(self,img_size=[128,128],cmap='flag_r',key=0):
        randvar = random.randint(2,10)
        self.mask = GaussianBlobMask(img_size).get_mask(randvar)
        self.epwtpath = EPWTPath(self.mask).get_path()
        sel.ppath = ProbabilisticPath(self.mask).get_path()
    
        if not os.path.isdir(f"./images"):
            os.mkdir(f'./images')
        self.epwtimg = ColoredPath(self.epwtpath, self.mask.shape).get_colored_path(cmap)
        self.pimg = ColoredPath(self.ppath, self.mask.shape).get_colored_path(cmap)
    
        matplotlib.image.imsave(f"./images/{key}_mask.png", self.mask, cmap='gray')
        matplotlib.image.imsave(f"./images/{key}_epwt.png", self.epwtimg)
        matplotlib.image.imsave(f"./images/{key}_prob.png", self.pimg)
        return self.pimg
    #img = get_random_image(img_size)  #returns numpy array
    #print(img)
    #print(dir(img))
    #img_out = Image.frombytes(img.tobytes())
    #show_array(img) #shows the image
    #img_out.save("rand_im.png")
    ##matplotlib.image.imsave("randimage.png", img)
    #for ea in range(10):
    #    run_1(img_size=[256,256],key=ea)