3535transpose = numpy .transpose (img )
3636
3737
38- #write code to create newimg here
38+ # write code to create newimg here
3939def solution1 ():
40- """Iterating over the image here. i is a variable from 0 to the width of the image.
40+ """Iterating over the image here. i is a variable from 0 to the width of the image.
4141 j is a variable that ranges from 0 to the height of the image. i is associated with
4242 values"""
43- for i in range (len (img )):
44- for j in range (len (img [0 ])):
45- x_n = [0 ]
46- y_n = [0 ]
47-
48- if (i == 0 ):
49- x_n .append (1 )
50- elif (i == len (img )- 1 ):
51- x_n .append (- 1 )
52- else :
53- x_n .append (1 )
54- x_n .append (- 1 )
55-
56- if (j == 0 ):
57- y_n .append (1 )
58- elif (j == len (img [0 ])- 1 ):
59- y_n .append (- 1 )
60- else :
61- y_n .append (1 )
62- y_n .append (- 1 )
63-
64- r_avg = - 1 * img [i ][j ][0 ]
65- g_avg = - 1 * img [i ][j ][1 ]
66- b_avg = - 1 * img [i ][j ][2 ]
67- c = - 1
68-
69- for x in x_n :
70- for y in y_n :
71- r_avg += img [i + x ][j + y ][0 ]
72- g_avg += img [i + x ][j + y ][1 ]
73- b_avg += img [i + x ][j + y ][2 ]
74- c += 1
75- r_avg = r_avg / c
76- g_avg = g_avg / c
77- b_avg = b_avg / c
78-
79- newimg [i ][j ] = [r_avg , g_avg , b_avg ]
80-
81-
43+ for i in range (len (img )):
44+ for j in range (len (img [0 ])):
45+ x_n = [0 ]
46+ y_n = [0 ]
47+
48+ if i == 0 :
49+ x_n .append (1 )
50+ elif i == len (img ) - 1 :
51+ x_n .append (- 1 )
52+ else :
53+ x_n .append (1 )
54+ x_n .append (- 1 )
55+
56+ if j == 0 :
57+ y_n .append (1 )
58+ elif j == len (img [0 ]) - 1 :
59+ y_n .append (- 1 )
60+ else :
61+ y_n .append (1 )
62+ y_n .append (- 1 )
63+
64+ r_avg = - 1 * img [i ][j ][0 ]
65+ g_avg = - 1 * img [i ][j ][1 ]
66+ b_avg = - 1 * img [i ][j ][2 ]
67+ c = - 1
68+
69+ for x in x_n :
70+ for y in y_n :
71+ r_avg += img [i + x ][j + y ][0 ]
72+ g_avg += img [i + x ][j + y ][1 ]
73+ b_avg += img [i + x ][j + y ][2 ]
74+ c += 1
75+ r_avg = r_avg / c
76+ g_avg = g_avg / c
77+ b_avg = b_avg / c
78+
79+ newimg [i ][j ] = [r_avg , g_avg , b_avg ]
8280
8381
8482solution1 ()
@@ -87,4 +85,4 @@ def solution1():
8785plt .show ()
8886
8987plt .imshow (transpose )
90- plt .show ()
88+ plt .show ()
0 commit comments