From 4d6faedf55b5dddff506fe5495f456985893b3c8 Mon Sep 17 00:00:00 2001 From: Ali Saadati Date: Tue, 12 Jan 2021 15:07:24 +0330 Subject: [PATCH] create filter function in beadfinder class to filter pictures --- beadfinder.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/beadfinder.py b/beadfinder.py index 767139a..957e777 100644 --- a/beadfinder.py +++ b/beadfinder.py @@ -7,6 +7,7 @@ class Blob: ''' The blob object contains the coordinates of connected pixels. ''' + def __init__(self): ''' create new instance of blob object @@ -53,7 +54,32 @@ def __str__(self): class BeadFinder: def __init__(self, pic, tau): - pass + ''' + create new instance of beadfinder object + and initialization self.pic and self.tau + ''' + self.tau = tau + self.pic = picture.Picture(pic) + + def __getavg(self, clr): + ''' + calculate average of R, G, B values of a color + like converting colors to gray scale + ''' + return (clr.getRed()+clr.getGreen()+clr.getBlue())/3 + + def filter(self): + ''' + filter pic according to threshold + colors under tau => black + colors above tau => white + ''' + for i in range(self.pic.width()): + for j in range(self.pic.height()): + if self.__getavg(self.pic.get(i, j)) < self.tau: + self.pic.set(i, j, color.Color(0, 0, 0)) + else: + self.pic.set(i, j, color.Color(255, 255, 255)) def getBeads(self, min_pixels): pass