-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotclusters3D.py
27 lines (24 loc) · 988 Bytes
/
plotclusters3D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import matplotlib.pyplot as plt
def plotclusters3D(data, labels, peaks):
"""
Plots the modes of the given image data in 3D by coloring each pixel
according to its corresponding peak.
Args:
data: image data in the format [number of pixels]x[feature vector].
labels: a list of labels, one for each pixel.
peaks: a list of vectors, whose first three components can
be interpreted as BGR values.
"""
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
bgr_peaks = np.array(peaks[:, 0:3], dtype=float)
rgb_peaks = bgr_peaks[...,::-1]
rgb_peaks /= 255.0
for idx, peak in enumerate(rgb_peaks):
#color = np.random.uniform(0, 1, 3)
#TODO: instead of random color, you can use peaks when you work on actual images
color = peak
cluster = data[np.where(labels == idx)[0]].T
ax.scatter(cluster[0], cluster[1], cluster[2], c=[color], s=.5)
fig.show()