Skip to content

Commit da99482

Browse files
committed
Fix style
1 parent b3d9a8e commit da99482

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

2_intermediate/chapter10/practice/img_avg.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
""" Here is the challenge problem for 2d loops:
2-
Images are often represented as 3d arrays,
1+
"""
2+
Image Average
3+
4+
Here is the challenge problem for 2D loops:
5+
Images are often represented as 3D arrays,
36
where the rows and columns are the pixels in the image,
4-
and each pixel has an r, g, and b value.
7+
and each pixel has an RGB (red, green, blue) value
8+
which determines the color of the pixel.
59
610
The interesting thing is that we can iterate over images.
711
The challenge is, given an image, create a program that
@@ -10,18 +14,18 @@
1014
1115
The neighbors of an image are all the pixels that surround it,
1216
1 on each side, and 4 on the diagonals, for 8 in total. Each
13-
pixel doesn't necessarily have 8 neighbors, though (think about why)
17+
pixel doesn't necessarily have 8 neighbors, though (think about why).
1418
1519
The code to grab an image from the internet and make it
1620
into an array is given to you. The code also displays the new image
1721
you create in the end.
1822
19-
NOTE: The image is 3 dimensional because each pixel has rgb values.
23+
NOTE: The image is 3 dimensional because each pixel has RGB values.
2024
To find the average value of all of a pixels neighbors, you must
2125
change the average of the red value to the red value, blue to blue, etc.
22-
For example, if the neighbors of a pixel with value [1,2,3]
23-
were [20,30,40] and [10,120,30], the new pixel that would replace the
24-
original one would be [15,75,35]
26+
For example, if the neighbors of a pixel with value [1, 2, 3]
27+
were [20, 30, 40] and [10, 120, 30], the new pixel that would replace the
28+
original one would be [15, 75, 35]
2529
"""
2630

2731
from PIL import Image

2_intermediate/chapter10/solutions/img_avg.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
""" Here is the challenge problem for 2d loops>
2-
Images are often represented as 3d arrays,
1+
"""
2+
Image Average
3+
4+
Here is the challenge problem for 2D loops:
5+
Images are often represented as 3D arrays,
36
where the rows and columns are the pixels in the image,
4-
and each pixel has an r, g, and b value.
7+
and each pixel has an RGB (red, green, blue) value
8+
which determines the color of the pixel.
59
610
The interesting thing is that we can iterate over images.
711
The challenge is, given an image, create a program that
812
will return a different image where each pixel is the average
913
of the pixels surrounding it in the original image.
1014
11-
The neighbors of an image are all the pixels that surroun it,
12-
1 on each side, and 4 on the diagonals, for 8 in total.
13-
Each pixel doesn't necessarily have 8 neighbors, though (think about why)
15+
The neighbors of an image are all the pixels that surround it,
16+
1 on each side, and 4 on the diagonals, for 8 in total. Each
17+
pixel doesn't necessarily have 8 neighbors, though (think about why).
1418
1519
The code to grab an image from the internet and make it
1620
into an array is given to you. The code also displays the new image
1721
you create in the end.
1822
19-
NOTE: The image is 3 dimensional because each pixel has rgb values.
23+
NOTE: The image is 3 dimensional because each pixel has RGB values.
2024
To find the average value of all of a pixels neighbors, you must
2125
change the average of the red value to the red value, blue to blue, etc.
22-
For example, if the neighbors of a pixel with value [1,2,3]
23-
were [20,30,40] and [10,120,30], the new pixel that would replace the original one would be
24-
[15,75,35]
26+
For example, if the neighbors of a pixel with value [1, 2, 3]
27+
were [20, 30, 40] and [10, 120, 30], the new pixel that would replace the
28+
original one would be [15, 75, 35]
2529
"""
2630

2731
from PIL import Image
@@ -37,9 +41,12 @@
3741

3842
# write code to create newimg here
3943
def solution1():
40-
"""Iterating over the image here. i is a variable from 0 to the width of the image.
41-
j is a variable that ranges from 0 to the height of the image. i is associated with
42-
values"""
44+
"""
45+
Iterating over the image here. i is a variable from
46+
0 to the width of the image.
47+
j is a variable that ranges from 0 to the height of the image.
48+
i is associated with values
49+
"""
4350
for i in range(len(img)):
4451
for j in range(len(img[0])):
4552
x_n = [0]

0 commit comments

Comments
 (0)