Skip to content
Snippets Groups Projects
Commit 00f85327 authored by Dimitri Tayo Fongang Wembe's avatar Dimitri Tayo Fongang Wembe
Browse files

complete funktions for imgutils

parent 6459ba53
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,13 @@ def image2pixels(image): ...@@ -35,7 +35,13 @@ def image2pixels(image):
A List containing all ``(R, G, B)``-values of the ``image`` together A List containing all ``(R, G, B)``-values of the ``image`` together
with the coordinates ``(X, Y)`` of the respective pixel. with the coordinates ``(X, Y)`` of the respective pixel.
""" """
pass # TODO # TODO
m, n, k = np.shape(image)
result = []
for i in range(m):
for j in range(n):
result.append((image[i][j][0], image[i][j][1], image[i][j][2], j, i))
return result
def pixels2image(pixels): def pixels2image(pixels):
...@@ -54,7 +60,19 @@ def pixels2image(pixels): ...@@ -54,7 +60,19 @@ def pixels2image(pixels):
A NumPy-Array of type ``uint8`` and shape (M, N, 3) representing A NumPy-Array of type ``uint8`` and shape (M, N, 3) representing
the image given by ``pixels``. the image given by ``pixels``.
""" """
pass # TODO # TODO
m, n = (0, 0)
for t in pixels:
if m < t[4]:
m = t[4]
if n < t[3]:
n = t[3]
image = np.zeros((m+1, n+1, 3))
for t in pixels:
image[t[4]][t[3]][0] = t[0]
image[t[4]][t[3]][1] = t[1]
image[t[4]][t[3]][2] = t[2]
return image
def bounding_box(pixels): def bounding_box(pixels):
...@@ -71,7 +89,30 @@ def bounding_box(pixels): ...@@ -71,7 +89,30 @@ def bounding_box(pixels):
A tuple containing the respective minimum and maximum values of A tuple containing the respective minimum and maximum values of
each color in the image represented by ``pixels``. each color in the image represented by ``pixels``.
""" """
pass # TODO # TODO
Rmin = pixels[0][0]
Rmax = pixels[0][0]
Gmin = pixels[0][1]
Gmax = pixels[0][1]
Bmin = pixels[0][2]
Bmax = pixels[0][2]
for p in pixels:
if Rmin > p[0]:
Rmin = p[0]
if Rmax < p[0]:
Rmax = p[0]
if Gmin > p[1]:
Gmin = p[1]
if Gmax < p[1]:
Gmax = p[1]
if Bmin > p[2]:
Bmin = p[2]
if Bmax < p[2]:
Bmax = p[2]
return ((Rmin, Rmax), (Gmin, Gmax), (Bmin, Bmax))
def color_average(pixels): def color_average(pixels):
...@@ -87,7 +128,19 @@ def color_average(pixels): ...@@ -87,7 +128,19 @@ def color_average(pixels):
A tuple containing the average value of red, green, and blue A tuple containing the average value of red, green, and blue
color values in the image represented by ``pixels``. color values in the image represented by ``pixels``.
""" """
pass # TODO # TODO
Ravg, Gavg, Bavg = (0, 0, 0)
for p in pixels:
Ravg += p[0]
Gavg += p[1]
Bavg += p[2]
listLen = len(pixels)
Ravg /= listLen
Gavg /= listLen
Bavg /= listLen
return (np.uint8(round(Ravg, 0)), np.uint8(round(Gavg, 0)), np.uint8(round(Bavg, 0)))
def main(): def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment