Facebook
From Hot Motmot, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 266
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Mar  7 11:14:23 2019
  4.  
  5. @author: Student
  6. """
  7.  
  8. #class VectorExample():
  9. #    def __init__(self, input_list):
  10. #        self.vector = input_list
  11. #        
  12. #    def foreach(self, other, input_function):
  13. #        return VectorExample([input_function(self.vector[i], other.vector[i]) for i in range(len(self.vector))])
  14. #        
  15. #    def __add__(self,other):
  16. #        return self.foreach(other, lambda a,b: a+b)
  17. #    
  18. #    def __sub__(self, other):
  19. #        return self.foreach(other, lambda a,b: a-b)
  20. #    
  21. #    def __mul__(self, other):
  22. #        return self.foreach(other, lambda a,b: a*b)
  23. #    
  24. #    def __truediv__(self,other):
  25. #        return self.foreach(other, lambda a,b: a/b)
  26. #    
  27. #    def __str__(self):
  28. #        return str(self.vector)
  29. #
  30. #
  31. #def run():
  32. #    vector_1 = VectorExample([1, 13, 4])
  33. #    vector_2 = VectorExample([3, -2, 2])
  34. #
  35. #    print(vector_1 + vector_2)
  36. #    print(vector_1 - vector_2)
  37. #    print(vector_1 * vector_2)
  38. #    print(vector_1 / vector_2)
  39. #    
  40. #if __name__== "__main__":
  41. #   run()
  42.  
  43. import os
  44. import numpy as np
  45. from matplotlib  import pyplot as plt
  46. from skimage import io
  47. import random
  48.  
  49. #def run():
  50. #    example_array = np.array([
  51. #            [8,1,1,1],
  52. #            [9,7,5,3],
  53. #            [4,6,8,10],
  54. #            [2,3,5,7]
  55. #    
  56. #    ])
  57. #    
  58. #    noise_1 = np.random.randn(128,256)
  59. #    noise_2 = np.random.randn(128,256)
  60. #    
  61. #    vmin=-0.5;vmax=0.5
  62. #    plt.figure()
  63. #    plt.subplot(2,1,1)
  64. #    plt.imshow(noise_1,cmap='gray', vmin=vmin, vmax=vmax)
  65. #    plt.axis('off')
  66. #    plt.subplot(2,1,2)
  67. #    plt.imshow(noise_2, cmap='gray', vmin=vmin, vmax=vmax)
  68. #    plt.axis('off')
  69. #    plt.show()
  70. #    
  71. #    
  72. #
  73. #run()
  74.    
  75.  
  76. #def run():
  77. #    
  78. #    x_size = 512
  79. #    y_size = 512
  80. #    number_of_points = 500
  81. #    vector1 = np.random.uniform(0,x_size,number_of_points)
  82. #    vector2 = np.random.uniform(0,y_size,number_of_points)
  83. #    
  84. #    x_origin=256
  85. #    y_origin=256
  86. #    radius=100
  87. #    is_inside=np.square(vector1-x_origin) + np.square(vector2-y_origin) < radius*radius
  88. #    
  89. #    image = np.zeros((y_size,x_size))
  90. #    grid_x, grid_y = np.meshgrid(np.arange(x_size), np.arange(y_size))
  91. #    
  92. #    image[np.square(grid_x - x_origin)+np.square(grid_y - y_origin)<radius*radius] = 1
  93. #    
  94. ##    plt.figure()
  95. ##    plt.subplot(1,2,1)
  96. ##    plt.imshow(grid_x, cmap='gray')
  97. ##    plt.subplot(1,2,2)
  98. ##    plt.imshow(grid_y, cmap='gray')
  99. ##    plt.show()
  100. #    
  101. #    vector1_inside = vector1[is_inside]
  102. #    vector2_inside = vector2[is_inside]
  103. #    
  104. #    vector1_outside = vector1[np.logical_not(is_inside)]
  105. #    vector2_outside = vector2[np.logical_not(is_inside)]    
  106. #    
  107. #    plt.figure()
  108. #    plt.imshow(image, cmap='gray')
  109. #    plt.plot(vector1_inside, vector2_inside,"r.")
  110. #    plt.plot(vector1_outside, vector2_outside, "b.")
  111. #    plt.xlabel("X Coordinates")
  112. #    plt.ylabel("Y Coordinates")
  113. #    plt.xlin([0, x_size])
  114. #    plt.ylin([0, y_size])
  115. #    plt.legend(["Outside","Inside"])
  116. #    plt.show()
  117. #    
  118. #run()
  119.    
  120.    
  121. def run():
  122.  
  123.     current_path = os.path.abspath(os.path.dirname(__file__))
  124.     image_folder=os.path.join(current_path, "sample_cifar")
  125.     file_names = os.listdir(image_folder)
  126.    
  127.     random.shuffle(file_names)
  128.     file_names = file_names[0:25]
  129.    
  130.     print(file_names)
  131.    
  132.     plt.figure()
  133.     i=1
  134.     for file_name in file_names:
  135.         current_class = file_name.split('_')[1].split('.')[0].capitalize()
  136.         plt.subplot(5,5,i)
  137.         image_path = os.path.join(image_folder, file_name)
  138.         image = io.imread(image_path)
  139.         i+=1
  140.         plt.axis('off')
  141.         plt.title(current_class)
  142.     plt.show()
  143.    
  144. run()
  145.    
  146.    
  147.    
  148.