Skip to content

Commit

Permalink
change the function in CutAnnToPatches.py
Browse files Browse the repository at this point in the history
  • Loading branch information
brian220 committed Aug 10, 2018
1 parent e4ef190 commit ab3e0b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
29 changes: 7 additions & 22 deletions CutAnnToPatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,29 @@
dirFolder = r'C:\Users\nctu\Desktop\ScanAnnotation\inAnn'

class cutAnnToPatches(object):
def __init__(self, currentAnn, scan):
def __init__(self, scan, currentAnn) :
self.scan = scan
self.ann = currentAnn
self.annPointGroup = []
self.imgIndex = 0
self.AnnXGroup = []
self.AnnYGroup = []
self.AnnPointGroup = []
self.pointTag = {}
self.patchSize = 10

def cutAnn(self):
AnnPointGroup = self.getAnnPoints()
self.groupXY()
self.pointTag = self.checkPointsInAnn()
self.savePatchInAnn()

#get the points of annotation polygon
def getAnnPoints(self):
self.AnnXGroup = self.dealWithAnnGroup(self.ann.coordinateX)
self.AnnYGroup = self.dealWithAnnGroup(self.ann.coordinateY)
self.AnnPointGroup = self.groupXY()
return self.AnnPointGroup

def dealWithAnnGroup(self, AnnGroup):
AnnGroup = [float(number) for number in AnnGroup]
# It is a Ann polygon so we add the first point to the end to make a closed graph
AnnGroup.append(AnnGroup[0])
return AnnGroup

def groupXY(self):
for i in range(0, len(self.AnnXGroup)):
self.AnnPointGroup.append(point(self.AnnXGroup[i], self.AnnYGroup[i]))
return self.AnnPointGroup
for i in range(0, len(self.ann.coordinateX)):
self.annPointGroup.append(point(float(self.ann.coordinateX[i]), float(self.ann.coordinateY[i])))
self.annPointGroup.append(self.annPointGroup[0])

# Find out if each point is in the Anngon, and use a tag True if it is, tag False if it is not
def checkPointsInAnn(self):
for i in range(self.ann.xMin, self.ann.xMax, self.patchSize):
for j in range(self.ann.yMin, self.ann.yMax, self.patchSize):
if isPointInAnn().isInAnn(point(i, j), self.AnnPointGroup):
if isPointInAnn().isInAnn(point(i, j), self.annPointGroup):
self.pointTag.update({(i, j) : True})
else:
self.pointTag.update({(i, j) : False})
Expand Down
18 changes: 9 additions & 9 deletions IsPointInAnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ class isPointInAnn(object):
def __init__(self):
pass

def isInAnn(self, testPoint, AnnPointGroup):
def isInAnn(self, testPoint, annPointGroup):
inAnn = False
for i in range(0, len(AnnPointGroup) - 1):
if (self.pointLieRight(testPoint, AnnPointGroup[i], AnnPointGroup[i+1])):
for i in range(0, len(annPointGroup) - 1):
if (self.pointLieRight(testPoint, annPointGroup[i], annPointGroup[i+1])):
inAnn = not inAnn
return inAnn

def pointLieRight(self, testPoint, AnnPoint1, AnnPoint2):
def pointLieRight(self, testPoint, annPoint1, annPoint2):
lieRight = False
if min(AnnPoint1.y, AnnPoint2.y) < testPoint.y <= max(AnnPoint1.y, AnnPoint2.y)\
and ( testPoint.x >= AnnPoint1.x or testPoint.x >= AnnPoint2.x):
if min(annPoint1.y, annPoint2.y) < testPoint.y <= max(annPoint1.y, annPoint2.y)\
and ( testPoint.x >= annPoint1.x or testPoint.x >= annPoint2.x):

if (AnnPoint2.x - AnnPoint1.x) == 0:
if (annPoint2.x - annPoint1.x) == 0:
lieRight = True
else:
a = (AnnPoint2.y - AnnPoint1.y) / (AnnPoint2.x - AnnPoint1.x)
b = AnnPoint1.y - a * AnnPoint1.x
a = (annPoint2.y - annPoint1.y) / (annPoint2.x - annPoint1.x)
b = annPoint1.y - a * annPoint1.x
if testPoint.x > ( testPoint.y - b) / a:
lieRight = True
return lieRight
2 changes: 1 addition & 1 deletion ScanAnnotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, sysFilePath, xmlFilePath):

def scanAnnotations(self):
for currentAnn in self.annList:
ann = cutAnnToPatches(currentAnn, self.scan)
ann = cutAnnToPatches( self.scan, currentAnn)
ann.cutAnn()

test = scanAnnotations(sysFilePath, xmlFilePath)
Expand Down

0 comments on commit ab3e0b6

Please sign in to comment.