Пример #1
0
	def similarity(self, pict):
		# distance of sizes
		#dim=sum(map(lambda (x,y):(x-y)**2, zip(self.size, pict.size)))
		#dim/=self.size[0]**2+self.size[1]**2
		msr=[]
		#dimensions=zip(self.size, pict.size)
		#widths=sorted(dimensions[0])
		#heights=sorted(dimensions[1])
		#msr.append(sqr(1.*widths[0]/widths[1]*heights[0]/heights[1]))
		#FIXME: hier irgendwo bleibts haengen, wenn ca. bilder
		# beim instanziieren ihre local copies nicht laden konnten
		dimcor = stats.pearson(self.size, pict.size)
		if dimcor:
			msr.append(dimcor)
		#hst=sum(map(lambda (x,y):(x-y)**2, zip(self.histogram, pict.histogram)))
		hstcor=measure.image_histograms(self, pict)
		if hstcor:
			msr.extend(hstcor)
		mood=measure.image_histmediandist(self, pict)
		if mood:
			msr.append(1.-mood)
		#colorful=measure.image_histrelcor(self, pict)
		#if colorful:
			#msr.extend(colorful)
		#dist = measure.image_hist_dist(self, pict)
		#if dist:
			#msr.append(1.-dist/255.)
		res = 1.
		#while len(msr)>0:
			#res *= msr.pop()
		return sum(msr)/len(msr)
Пример #2
0
def image_histrelcor(p,q):
	corrs=[]
	rel=[image_histrelcol(p), image_histrelcol(q)]
	for bank in range(0,96,32):
		cor=stats.pearson(rel[0][bank:bank+32], rel[1][bank:bank+32])
		corrs.append(cor)
	return corrs
Пример #3
0
def image_histograms(p, q):
	# asume number color tones has been reduced to 32 by Picture class
	# if those two pictures are not in the same colorspace, thats no prob
	# while the first one might visit its B, G, and R histograms, the other
	# one just stays in its black'n'white space.
	# handle maximum colorspace, however
	colspace=sorted([p.mode, q.mode], key=lambda m:len(m))[-1]
	correlations=[]
	for offset,band in enumerate(colspace):
		off1=offset*32%len(p.histogram)
		off2=offset*32%len(q.histogram)
		corr=stats.pearson(p.histogram[off1:off1+32], q.histogram[off2:off2+32])
		correlations.append(corr)
	# now how do we put them together?
	#res=sum(correlations)/len(correlations)
	return correlations
Пример #4
0
def image_histograms(p, q):
	# asume number color tones has been reduced to 32 by Picture class
	# if those two pictures are not in the same colorspace, thats no prob
	# while the first one might visit its B, G, and R histograms, the other
	# one just stays in its black'n'white space.
	# handle maximum colorspace, however
	#colspace=sorted([p.mode, q.mode], key=lambda m:len(m))[-1]
	v = lookup(hist_correlations, p, q)
	if v:
		return v
	bands = max(p.histogram.bands, q.histogram.bands)
	correlations=[]
	for offset in range(bands):
		h1 = p.histogram.array(bands=bands)
		h2 = q.histogram.array(bands=bands)
		off1=offset*32%len(h1)
		off2=offset*32%len(h2)
		corr=stats.pearson(h1[off1:off1+32], h2[off2:off2+32])
		correlations.append(corr)
	# now how do we put them together?
	#res=sum(correlations)/len(correlations)
	register(hist_correlations, p, q, correlations)
	return correlations