mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-13 00:34:46 +03:00
Added some comments
This commit is contained in:
parent
6f3e77b617
commit
9c0f98aa59
|
@ -1287,7 +1287,6 @@ class Image:
|
||||||
:returns: An unsorted list of (pixel) values.
|
:returns: An unsorted list of (pixel) values.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.load()
|
|
||||||
if self.mode in ("F", "I", "L", "P"):
|
if self.mode in ("F", "I", "L", "P"):
|
||||||
channels = 1
|
channels = 1
|
||||||
elif self.mode in ("RGB", "YCbCr", "LAB", "HSV"):
|
elif self.mode in ("RGB", "YCbCr", "LAB", "HSV"):
|
||||||
|
@ -1314,11 +1313,13 @@ class Image:
|
||||||
# Formatted as (pixel_cluster, center)
|
# Formatted as (pixel_cluster, center)
|
||||||
centroids.append(([pixels_and_counts[i]], pixels_and_counts[i][0]))
|
centroids.append(([pixels_and_counts[i]], pixels_and_counts[i][0]))
|
||||||
|
|
||||||
|
# Begin k-means clustering
|
||||||
for iter in range(maxiter):
|
for iter in range(maxiter):
|
||||||
cluster = {}
|
cluster = {}
|
||||||
for i in range(numcolors):
|
for i in range(numcolors):
|
||||||
cluster[i] = []
|
cluster[i] = []
|
||||||
|
|
||||||
|
# Calculates all pixel distances from each center to add to the cluster
|
||||||
for pixel in pixels_and_counts:
|
for pixel in pixels_and_counts:
|
||||||
smallest_distance = float("Inf")
|
smallest_distance = float("Inf")
|
||||||
|
|
||||||
|
@ -1330,6 +1331,7 @@ class Image:
|
||||||
|
|
||||||
cluster[idx].append(pixel)
|
cluster[idx].append(pixel)
|
||||||
|
|
||||||
|
# Adjusting the center of each cluster
|
||||||
difference = 0
|
difference = 0
|
||||||
for i in range(numcolors):
|
for i in range(numcolors):
|
||||||
previous = centroids[i][1]
|
previous = centroids[i][1]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user