Load from St.Jan

This commit is contained in:
Ruben 2017-03-11 11:49:47 +01:00
parent 9125d33bcb
commit 61453a707f
4226 changed files with 6531 additions and 276 deletions

View file

@ -5,7 +5,8 @@ from lxml import etree
def createPie(data, gaps = 0): def createPie(data, gaps = 0):
total = sum(data.values()) total = sum(data.values())
colours = ['#268ED7','#6A4F8D', '#A03D4F','#DC7432','#F6DC3B','#76B33B', '#267B60'] colours = ['#268ED7','#6A4F8D', '#A03D4F','#DC7432','#F6DC3B','#76B33B', '#267B60']
svg = '<svg viewBox="-115 -115 230 230" xmlns="http://www.w3.org/2000/svg">' className = "hoverTitles" if len(data) > 9 else ""
svg = '<svg viewBox="-115 -115 230 230" xmlns="http://www.w3.org/2000/svg" class="%s">' % className
numbers = "" numbers = ""
position = 90 position = 90
i = 0 i = 0
@ -18,8 +19,9 @@ def createPie(data, gaps = 0):
d = describeArc(float(diff['x']), float(diff['y']), 60, position, position+arc) d = describeArc(float(diff['x']), float(diff['y']), 60, position, position+arc)
# print(position, arc) # print(position, arc)
svg += '<path fill="none" stroke="%s" stroke-width="60" d="%s" />' % (colours[i%len(colours)], d) svg += '<path fill="none" stroke="%s" stroke-width="60" d="%s" />' % (colours[i%len(colours)], d)
# tRadius = 105 if i%2 else 95
t = polarToCartesian(0,0, 100, position+0.5*arc) t = polarToCartesian(0,0, 100, position+0.5*arc)
numbers += '<text x="%s" y="%s" font-family="sans-serif" font-size="14" style=" stroke:color: black;" text-anchor="middle" transform="rotate(%s %s,%s)">%s</text>' % (t['x'], t['y'], position+0.5*arc, t['x'],t['y'], e) svg += '<text x="%s" y="%s" font-family="sans-serif" font-size="12" style=" stroke:color: black;" text-anchor="middle" transform="rotate(%s %s,%s)">%s</text>' % (t['x'], t['y'], position+0.5*arc, t['x'],t['y'], e)
position += arc position += arc
i+=1 i+=1

109
colour.py
View file

@ -7,13 +7,15 @@ import codecs
import colorsys import colorsys
import math import math
import numpy as np import numpy as np
import sklearn.cluster
from PIL import Image
NUM_CLUSTERS = 64 NUM_CLUSTERS = 64
def getColourAsHex(colour): def getColourAsHex(colour):
return '#' + ''.join(format(c, '02x') for c in colour.astype(int)) return '#' + ''.join(format(c, '02x') for c in colour.astype(int))
def getColoursForImageByClusters(image): def getColoursForImageByKMeansClusters(image):
""" """
Adapted on answers by Adapted on answers by
Peter Hansen (http://stackoverflow.com/a/3244061) Peter Hansen (http://stackoverflow.com/a/3244061)
@ -43,6 +45,62 @@ def getColoursForImageByClusters(image):
# print(colours) # print(colours)
return list(zip(codes, percentages)) return list(zip(codes, percentages))
def getColoursForImageByMeanShiftClusters(image, saveImgName = False):
"""
Adapted on answers by
Peter Hansen (http://stackoverflow.com/a/3244061)
& Johan Mickos (http://stackoverflow.com/a/34140327)
Now using MeanShift clustering
if saveImgName set to the path/prefix_ for the layer images, save images of each cluster matched pixels
"""
imgSize = (170,170)
# imgSize = (int(targetWidth), int(image.size[1] / (image.size[0]/targetWidth)))
im = image.copy() # optional, to reduce time
im.thumbnail(imgSize)
imgSize = im.size
print("\tRender image of", image.size,"for", imgSize)
imgAr = scipy.misc.fromimage(im)
shape = imgAr.shape
ar = imgAr.reshape(scipy.product(shape[:2]), shape[2])
total = len(ar)
# print( 'finding clusters')
# codes, dist = scipy.cluster.vq.kmeans(ar.astype(float), NUM_CLUSTERS)
bandwidth = sklearn.cluster.estimate_bandwidth(ar.astype(float), quantile=0.1, n_samples=500)
ms = sklearn.cluster.MeanShift(bandwidth=bandwidth)
ms.fit(ar.astype(float))
labels = ms.labels_ # labels per point
cluster_centers = ms.cluster_centers_ # centers of found clusters
labels_unique = np.unique(labels)
n_clusters_ = len(labels_unique)
print("\tClusters found:", n_clusters_)
colours = []
for k in labels_unique:
cluster_center = cluster_centers[k] # np.array with rgb
mask = labels == k # True/False map of flattened array
# m = np.ma.masked_where(labels != k, labels)
count = len(ar[mask]) # nr of pixels for this label
# pass on percentages:
colours.append((cluster_center, 100 * count / total))
if saveImgName:
# save image as RGBA with transparent pixels, except for there where label == k
layer = np.array([np.append(ar[i],255) if l == k else [0,0,0,0] for i,l in enumerate(list(labels))], dtype=np.uint8)
layerImgAr = layer.reshape((imgSize[1],imgSize[0],4)) # layers are stacked: vertical, horizontal, rgba
layerImg = Image.fromarray(layerImgAr, mode="RGBA")
layerFilename = saveImgName + '-%s.png' % k
layerImg.save(layerFilename)
print(layerFilename)
# display(HTML("<span style='background:%s'>%s</span>" % (getColourAsHex(cluster_center),getColourAsHex(cluster_center))))
return colours
def getColoursForImageByPxAvg(image): def getColoursForImageByPxAvg(image):
im = image.copy().resize((8, 8)) im = image.copy().resize((8, 8))
pixels = np.concatenate(scipy.misc.fromimage(im)) pixels = np.concatenate(scipy.misc.fromimage(im))
@ -54,36 +112,41 @@ def getColoursAsHTML(colours):
return " ".join(['<span style="background:%s">%s - (%s %%)</span>' % (getColourAsHex(colour[0]), getColourAsHex(colour[0]), colour[1]) for colour in colours]); return " ".join(['<span style="background:%s">%s - (%s %%)</span>' % (getColourAsHex(colour[0]), getColourAsHex(colour[0]), colour[1]) for colour in colours]);
def loadColoursFromDbImages(images): def loadColoursFromDbImages(images):
return [i.colours for i in images] return [i.colours for i in images if not i.colours is None]
def getSvgFromDbImages(images, elId = ""): def getSvgFromDbImages(images, elId = ""):
# sum concatenates all colour arrays # sum concatenates all colour arrays
allColours = [] # allColours = []
for c in loadColoursFromDbImages(images): # for c in loadColoursFromDbImages(images):
allColours += c # allColours += c
# box 160, because center or circle = 100 => +/- 50 => + r of colour circle (max: 10) => 160 # box 160, because center or circle = 100 => +/- 50 => + r of colour circle (max: 10) => 160
svg = '<svg viewBox="-160 -160 320 320" xmlns="http://www.w3.org/2000/svg" id="%s">' % elId svg = '<svg viewBox="-160 -160 320 320" xmlns="http://www.w3.org/2000/svg" id="%s">' % (elId, )
radius = 100 radius = 100
for colour in allColours: for image in images:
rgb, percentage = colour if image.colours is None:
rgbNorm = rgb/255 continue
hsv = colorsys.rgb_to_hsv(rgbNorm[0], rgbNorm[1], rgbNorm[2])
# find position on circle for i, colour in enumerate(image.colours):
radians = 2 * math.pi * hsv[0] colourId = '%s-%s' % (image.id, i)
x = math.cos(radians) rgb, percentage = colour
y = math.sin(radians) rgbNorm = rgb/255
hsv = colorsys.rgb_to_hsv(rgbNorm[0], rgbNorm[1], rgbNorm[2])
# based on saturation, we move inwards/outwards # find position on circle
# min = 0.5, max = 1.5 (dus + 0.5) radians = 2 * math.pi * hsv[0]
pos = np.array([x,y]) * (0.5 + hsv[1]) * radius x = math.cos(radians)
# Posibilitiy: determine position based on avg(saturation, value) => dark & grey inside, shiney and colourful outside y = math.sin(radians)
# pos = np.array([x,y]) * (0.5 + (hsv[1]+hsv[2])/2) * radius
r = max(1,-10/percentage+10) # as r, we converge to maximum radius 10, but don't want to get smaller radi then 1 # based on saturation, we move inwards/outwards
c = '<circle cx="%s" cy="%s" r="%s" style="fill:%s" />' % (pos[0], pos[1], r, getColourAsHex(rgb)) # min = 0.5, max = 1.5 (dus + 0.5)
svg += c pos = np.array([x,y]) * (0.5 + hsv[1]) * radius
# Posibilitiy: determine position based on avg(saturation, value) => dark & grey inside, shiney and colourful outside
# pos = np.array([x,y]) * (0.5 + (hsv[1]+hsv[2])/2) * radius
r = max(1,-10/percentage+10) # as r, we converge to maximum radius 10, but don't want to get smaller radi then 1
c = '<circle cx="%s" cy="%s" r="%s" style="fill:%s" onmouseover="triggerover(\'%s\', this)" />' % (pos[0], pos[1], r, getColourAsHex(rgb), colourId)
svg += c
svg += "</svg>" svg += "</svg>"
return svg return svg

BIN
images.db

Binary file not shown.

BIN
images/1-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
images/1-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
images/1-10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

BIN
images/1-11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 853 B

BIN
images/1-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
images/1-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
images/1-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/1-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
images/1-6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/1-7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
images/1-8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

BIN
images/1-9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
images/10-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
images/10-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
images/10-10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

BIN
images/10-11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

BIN
images/10-12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

BIN
images/10-13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

BIN
images/10-14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

BIN
images/10-15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

BIN
images/10-16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

BIN
images/10-17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

BIN
images/10-18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

BIN
images/10-19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

BIN
images/10-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

BIN
images/10-20.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

BIN
images/10-21.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/10-22.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

BIN
images/10-23.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

BIN
images/10-24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

BIN
images/10-25.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

BIN
images/10-26.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

BIN
images/10-27.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

BIN
images/10-28.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

BIN
images/10-29.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

BIN
images/10-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

BIN
images/10-30.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

BIN
images/10-31.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

BIN
images/10-32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

BIN
images/10-33.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

BIN
images/10-34.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

BIN
images/10-35.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

BIN
images/10-36.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

BIN
images/10-37.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

BIN
images/10-38.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

BIN
images/10-39.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

BIN
images/10-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

BIN
images/10-40.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

BIN
images/10-41.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

BIN
images/10-42.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

BIN
images/10-43.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

BIN
images/10-44.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

BIN
images/10-45.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

BIN
images/10-46.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
images/10-47.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

BIN
images/10-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

BIN
images/10-49.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

BIN
images/10-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

BIN
images/10-50.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

BIN
images/10-51.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
images/10-52.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

BIN
images/10-53.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

BIN
images/10-54.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

BIN
images/10-55.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

BIN
images/10-56.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
images/10-57.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

BIN
images/10-58.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

BIN
images/10-59.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

BIN
images/10-6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

BIN
images/10-60.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

BIN
images/10-61.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

BIN
images/10-62.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

BIN
images/10-63.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

BIN
images/10-64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
images/10-65.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

BIN
images/10-66.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

BIN
images/10-67.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

BIN
images/10-68.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

BIN
images/10-69.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
images/10-7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

BIN
images/10-70.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
images/10-71.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

BIN
images/10-8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

BIN
images/10-9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
images/100-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
images/100-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
images/100-10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

BIN
images/100-11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B

BIN
images/100-12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

BIN
images/100-13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

BIN
images/100-14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
images/100-15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

BIN
images/100-16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

BIN
images/100-17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

BIN
images/100-18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

BIN
images/100-19.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

BIN
images/100-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Some files were not shown because too many files have changed in this diff Show more