Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python 

2# coding=utf-8 

3 

4 

5"""Test utilities""" 

6 

7 

8import numpy 

9 

10 

11def count_bw(b): 

12 """Calculates totals of black and white pixels in a binary image 

13 

14 

15 Parameters 

16 ---------- 

17 

18 b : PIL.Image.Image 

19 A PIL image in mode "1" to be used for calculating positives and 

20 negatives 

21 

22 Returns 

23 ------- 

24 

25 black : int 

26 Number of black pixels in the binary image 

27 

28 white : int 

29 Number of white pixels in the binary image 

30 """ 

31 

32 boolean_array = numpy.array(b) 

33 white = boolean_array.sum() 

34 return (boolean_array.size - white), white