예제 #1
0
	def __init__(self, image, bands=0):
		data=[]
		if isinstance(image, pil.Image):
			try:
				data = image.histogram()
				bands = min(3, len(image.mode)) # cut A band of RGBA images
				# scale, normalize
				# only if data is extracted from actual image
				while len(data) > bands*32:
					data = scaledown(data)
				# normalize: 255 means entire image is of colors of a bin
				h,w = image.size
				maxx = h*w
				data = [bin * 255. / maxx for bin in data]
			except:
				data = [10]*96
		# if hostogram is given as a list, guess number of color bands
		elif type(image) is list:
			data = image[:]
			if bands < 1:
				bands=1
				if len(data)>64:
					bands=3
		# struct band hists
		self.data = []
		self.bands = bands
		# split array into color histograms
		size=max(len(data)/bands, 32)
		for b in range(0,len(data), size):
			self.data.append(data[b:b+size])
		# prepare median values
		self.mediane = [stats.median_histogram(band)
											for band in self.data]
		self._hex=''
예제 #2
0
def image_histmediane(p):
	mediane=[]
	for offset,channel in enumerate('RGB'):
		off=offset*32%len(p.histogram)
		band=p.histogram[off:off+32]
		#median=sum([i*v for (i,v) in enumerate(band)])/sum(band)
		median=stats.median_histogram(band)
		mediane.append(median)
	return mediane