Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #
  2. # features:
  3. #
  4.  
  5. class Features:
  6.  
  7. @staticmethod
  8. def getContourPercentage(image, sig):
  9. image = feature.canny(image, sigma=sig)
  10. return np.sum(image) / image.size
  11.  
  12. @staticmethod
  13. def whitepix(db):
  14. minDiff = 150
  15. maxBright = 500
  16.  
  17. arr = np.array([])
  18.  
  19. # through all pictures
  20. for picture in db:
  21. result = 0
  22.  
  23. picture = picture.astype(int)
  24.  
  25. # through row of one picture
  26. for row in picture:
  27. # every pixel
  28. for pixel in row:
  29. # calculate difference in rgb to check whether picture has grayScales
  30. rgDiff = abs(pixel[0]-pixel[1])
  31. gbDiff = abs(pixel[1]-pixel[2])
  32. brDiff = abs(pixel[2]-pixel[0])
  33.  
  34. grayScale = rgDiff + gbDiff + brDiff
  35.  
  36. # calculate whiteShade of the pixel
  37. whiteShade = pixel[0] + pixel[1] + pixel[2]
  38.  
  39. if (grayScale < minDiff and whiteShade > maxBright):
  40. result +=1
  41. arr = np.append(arr, result/(float(picture.size)/3))
  42. return arr
  43.  
  44. @staticmethod
  45. def avgColor(imageList):
  46. meanImageList = []
  47. for pic in imageList:
  48. meanImageList.append([np.mean(pic[:,:,0]),
  49. np.mean(pic[:,:,1]),
  50. np.mean(pic[:,:,2])])
  51. return np.array(meanImageList)/255
  52.  
  53. @staticmethod
  54. def contour_to_feature(images):
  55. contour_percentages = np.zeros((len(images),))
  56.  
  57. for m in range(0,len(images)):
  58. image = images[m]
  59. if image.ndim == 3 :
  60. image = skimage.color.rgb2gray(image)
  61. contour_percentage = getContourPercentage(image, 1)
  62. contour_percentages[m] = contour_percentage
  63. return contour_percentages
  64.  
  65. #contour
  66. print contour_to_feature(tenImages)
  67. #wit
  68. print whitepix(tenImages)
  69. #rood percentage
  70. print avgColor(tenImages)[:,0]
  71. #groen percentage
  72. print avgColor(tenImages)[:,1]
  73. #blauw percentage
  74. print avgColor(tenImages)[:,2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement