[+] A1 p4
This commit is contained in:
@@ -65,6 +65,9 @@ def add_pepper(pixel_data: list, k: int) -> list:
|
||||
Because of the randomness, we can't specify an exact doctest.
|
||||
"""
|
||||
|
||||
# I don't know why I have to use divide_channels here. I can just use (0,0,0)
|
||||
return [random.choice([pixel] * k + [divide_channels(pixel, 256)]) for pixel in pixel_data]
|
||||
|
||||
|
||||
def add_salt(pixel_data: list, k: int) -> list:
|
||||
"""Return a new list of pixels formed from the corresponding pixels in pixel_data that has some
|
||||
@@ -84,6 +87,9 @@ def add_salt(pixel_data: list, k: int) -> list:
|
||||
Because of the randomness, we can't specify an exact doctest.
|
||||
"""
|
||||
|
||||
# I don't know why I have to use maximize_channels here. I can just use (255,255,255)
|
||||
return [random.choice([pixel] * k + [maximize_channels(pixel, 255)]) for pixel in pixel_data]
|
||||
|
||||
|
||||
def add_salt_and_pepper(pixel_data: list, k: int) -> list:
|
||||
"""Return a new list of pixels formed from the corresponding pixels in pixel_data
|
||||
@@ -94,6 +100,9 @@ def add_salt_and_pepper(pixel_data: list, k: int) -> list:
|
||||
|
||||
Because of the randomness, we can't specify an exact doctest.
|
||||
"""
|
||||
pixel_data = add_pepper(pixel_data, k)
|
||||
pixel_data = add_salt(pixel_data, k)
|
||||
return pixel_data
|
||||
|
||||
|
||||
def run_salt_and_pepper_example(source: str, destination: str, k: int) -> None:
|
||||
@@ -112,10 +121,12 @@ if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
||||
# run_salt_and_pepper_example('images/horses.png', 'images/noisy-horses.png', 16)
|
||||
|
||||
# When you are ready to check your work with python_ta, uncomment the following lines.
|
||||
# (Delete the "#" and space before each line.)
|
||||
# import python_ta
|
||||
# python_ta.check_all(config={
|
||||
# 'extra-imports': ['random', 'a1_image'],
|
||||
# 'max-line-length': 100
|
||||
# })
|
||||
import python_ta
|
||||
python_ta.check_all(config={
|
||||
'extra-imports': ['random', 'a1_image'],
|
||||
'max-line-length': 100
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user