From bdd32fcca5e61b98f9bb62864ea10d0138c36124 Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Fri, 16 Mar 2018 14:09:53 +0000 Subject: [PATCH] Use numpy.all function to filter white pixels rather than a loop --- Anaconda-files/Program_18b.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Anaconda-files/Program_18b.py b/Anaconda-files/Program_18b.py index 4ec728c..78ef44b 100644 --- a/Anaconda-files/Program_18b.py +++ b/Anaconda-files/Program_18b.py @@ -9,17 +9,11 @@ fig1 = plt.figure() plt.imshow(face) -width, height, _ = face.shape +height, width, _ = face.shape print('Image dimensions: {}x{}'.format(width, height)) -white_pixels = np.zeros((width, height)) -def white_pixel_filter(pixel, threshold): - return 1 if all(value > threshold for value in pixel) else 0 - -for i, row in enumerate(face): - for j, pixel in enumerate(row): - white_pixels[i, j] = white_pixel_filter(pixel, threshold=180) +white_pixels = np.all(face > 180, axis=2) fig2 = plt.figure() plt.imshow(white_pixels, cmap='gray')