freealise commited on
Commit
9cc7da8
1 Parent(s): 726d00a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -422,18 +422,21 @@ def optimize(v, d):
422
  if v == True:
423
  ddepth = cv2.CV_16S
424
  kernel_size = 3
425
- l = 4
426
 
427
  dcolor = []
428
  for k, f in enumerate(frames):
429
  frame = cv2.imread(frames[k]).astype(np.uint8)
430
 
431
- indices = np.arange(0,256) # List of all colors
432
- divider = np.linspace(0,255,l+1)[1] # we get a divider
433
- quantiz = np.int0(np.linspace(0,255,l)) # we get quantization colors
434
- color_levels = np.clip(np.int0(indices/divider),0,l-1) # color levels 0,1,2..
435
- palette = quantiz[color_levels]
436
- frame = cv2.convertScaleAbs(palette[frame]).astype(np.uint8)
 
 
 
437
 
438
  dcolor.append(bincount(frame))
439
  print(dcolor[k])
 
422
  if v == True:
423
  ddepth = cv2.CV_16S
424
  kernel_size = 3
425
+ l = 16
426
 
427
  dcolor = []
428
  for k, f in enumerate(frames):
429
  frame = cv2.imread(frames[k]).astype(np.uint8)
430
 
431
+ # convert to np.float32
432
+ f = np.float32(frame.reshape((-1,3)))
433
+ # define criteria, number of clusters(K) and apply kmeans()
434
+ criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)
435
+ ret,label,center=cv2.kmeans(f,l,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
436
+ # Now convert back into uint8, and make original image
437
+ center = np.uint8(center)
438
+ res = center[label.flatten()]
439
+ frame = res.reshape((frame.shape))
440
 
441
  dcolor.append(bincount(frame))
442
  print(dcolor[k])