from regionGrowth import *
def condition1(img, currentPoint, seedMark):
thickness, width, height = img.shape
V = (img[currentPoint.x, currentPoint.y, currentPoint.z] + 1024) / 249
connects = domain(6)
absList = []
for i in range(6):
tempX = currentPoint.x + connects[i].x
tempY = currentPoint.y + connects[i].y
tempZ = currentPoint.z + connects[i].z
if tempX < 0 or tempY < 0 or tempZ < 0 or tempX >= height or tempY >= width or tempZ >= thickness:
continue
tempPoint = Point(tempX, tempY, tempZ)
if seedMark[tempPoint.x, tempPoint.y, tempPoint.z] !=0:
absList.append(abs(img[currentPoint.x, currentPoint.y, currentPoint.z] - img[tempX, tempY, tempZ]))
if len(absList):
G = min(absList) / 255
else:
G = 0
H = V + G
return True if H <0.4 else False
def morphoDetection(img, trdPoints, fstPoints, seedMark, label, num):
while(len(trdPoints)):
tempPoint = trdPoints.pop()
connects = domain(6)
thickness, width, height = img.shape
flag = 0
for i in range(6):
tempX = tempPoint.x + connects[i].x
tempY = tempPoint.y + connects[i].y
tempZ = tempPoint.z + connects[i].z
if tempX < 0 or tempY < 0 or tempZ < 0 or tempX >= height or tempY >= width or tempZ >= thickness:
continue
tempPoint1 = Point(tempX, tempY, tempZ)
if seedMark[tempPoint1.x, tempPoint1.y, tempPoint1.z] !=0:
flag += 1
if flag >= 2:
fstPoints.append(tempPoint)
seedMark[tempPoint.x, tempPoint.y, tempPoint.z] = label
num += 1
elif condition1(img, tempPoint, seedMark):
fstPoints.append(tempPoint)
seedMark[tempPoint.x, tempPoint.y, tempPoint.z] = label
num += 1
#else:
# trdPoints.append(tempPoint)
return seedMark, fstPoints, num