Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # features:
- #
- class Features:
- @staticmethod
- def getContourPercentage(image, sig):
- image = feature.canny(image, sigma=sig)
- return np.sum(image) / image.size
- @staticmethod
- def whitepix(db):
- minDiff = 150
- maxBright = 500
- arr = np.array([])
- # through all pictures
- for picture in db:
- result = 0
- picture = picture.astype(int)
- # through row of one picture
- for row in picture:
- # every pixel
- for pixel in row:
- # calculate difference in rgb to check whether picture has grayScales
- rgDiff = abs(pixel[0]-pixel[1])
- gbDiff = abs(pixel[1]-pixel[2])
- brDiff = abs(pixel[2]-pixel[0])
- grayScale = rgDiff + gbDiff + brDiff
- # calculate whiteShade of the pixel
- whiteShade = pixel[0] + pixel[1] + pixel[2]
- if (grayScale < minDiff and whiteShade > maxBright):
- result +=1
- arr = np.append(arr, result/(float(picture.size)/3))
- return arr
- @staticmethod
- def avgColor(imageList):
- meanImageList = []
- for pic in imageList:
- meanImageList.append([np.mean(pic[:,:,0]),
- np.mean(pic[:,:,1]),
- np.mean(pic[:,:,2])])
- return np.array(meanImageList)/255
- @staticmethod
- def contour_to_feature(images):
- contour_percentages = np.zeros((len(images),))
- for m in range(0,len(images)):
- image = images[m]
- if image.ndim == 3 :
- image = skimage.color.rgb2gray(image)
- contour_percentage = getContourPercentage(image, 1)
- contour_percentages[m] = contour_percentage
- return contour_percentages
- #contour
- print contour_to_feature(tenImages)
- #wit
- print whitepix(tenImages)
- #rood percentage
- print avgColor(tenImages)[:,0]
- #groen percentage
- print avgColor(tenImages)[:,1]
- #blauw percentage
- print avgColor(tenImages)[:,2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement