def getRotateBoxTest(self): if not self._rotBoxTest: grayImg = self.image.toGray() diff = grayImg - self._boxFilter(grayImg, 35) result = [0]*18 if not self.ellipse.error and self.ellipse.a > 0 and self.ellipse.b > 0: res = countInWindowEst(diff.threshold(6).getGrayNumpy(), 5) res = self._getRotatedAndScaledGalImg(Image(res)) if res != None: res = res.getGrayNumpy() img = Image(res) ellipse = self.ellipse center = (img.width/2, img.height/2) width = 10 diameter = int(max(ellipse.a, ellipse.b)*2) mask = np.zeros_like(img.getGrayNumpy(), dtype=np.bool) mask[center[0]-width/2:center[0]+width/2, center[1]-diameter/2:center[1]+diameter/2] = True mask = Image(mask).threshold(0) maxI = 0 maxThetaVal = 0 values = [] for i, theta in enumerate(xrange(-90, 90, 10)): masked = (img & mask.rotate(theta, point=(img.width/2, img.height/2))).getGrayNumpy() val = np.sum(masked)/float(img.width*img.height) values.append(val) if val > maxThetaVal: maxThetaVal = val maxI = i result[0:len(values)-maxI] = values[maxI:] result[len(values)-maxI:] = values[0:maxI] self._rotBoxTest = result return self._rotBoxTest
def getFlattenedDiskImg(self): if not self._flattenedDiskImage: grayImg = self.image.toGray() diff = grayImg - self._boxFilter(grayImg, 35) if not self.ellipse.error: res = countInWindowEst(diff.threshold(6).getGrayNumpy(), 5) res = self._getRotatedAndScaledGalImg(Image(res)) if res != None: res = res.getGrayNumpy() res = generateFlattenedDiskImg(res, int(res.shape[0]/2), int(res.shape[0]/2), res.shape[0]/2) if res != None: res = normalizeImageStart(res) self._flattenedDiskImage = Image(res) return self._flattenedDiskImage