使用鼠标交互实现区域生长算法
© Fu Xianjun. All Rights Reserved
素材
代码
import cv2
import numpy as np
class Point(object):
def init(self,x,y):
self.x = x
self.y = y
def getX(self):
return self.x
def getY(self):
return self.y
#计算像素之间的偏差
def getGrayDiff(img,currentPoint,tmpPoint):
return abs(int(img[currentPoint.x,currentPoint.y]) - int(img[tmpPoint.x,tmpPoint.y]))
#设定八邻域或四邻域(我对原程序进行改动,只选择了八邻域)
#def selectConnects§:
def selectConnects():
#if p != 0:
connects = [Point(-1, -1), Point(0, -1), Point(1, -1), Point(1, 0), Point(1, 1),
Point(0, 1), Point(-1, 1), Point(-1, 0)]#八邻域
#else:
#connects = [ Point(0, -1), Point(1, 0),Point(0, 1), Point(-1, 0)]#四邻域
re