zhJ il y a 9 mois
Parent
commit
8bd40592f5
1 fichiers modifiés avec 11 ajouts et 8 suppressions
  1. 11 8
      LigneForce.py

+ 11 - 8
LigneForce.py

@@ -260,6 +260,7 @@ def findSaliantLineCluster(gradient4d,allLines,allLinesIndex,ws, orgW, orgH ):
     npWeightList = np.array(weightList)
     sortWeightList = npWeightList.argsort()[::-1]   # [::-1] inverse a list, range from large to small
     # top 300 weighted candidates, about 0.14% of the total lines
+    # initialization of the first group of the leading lines
     for n,wId in enumerate(sortWeightList[:300]):
         if n == 0:
             groupMask = clusterRegion(allLinesIndex[wId], fineGrained0, ws)
@@ -285,6 +286,7 @@ def findSaliantLineCluster(gradient4d,allLines,allLinesIndex,ws, orgW, orgH ):
     fineGrained = 7
     wGrained = 3
     intePrec = 0.7
+    # regrouping and filtering leading lines, reture center lines and line groups
     for i in range(10000):
         
         if len(forceLinesRoughNew) == len(forceLinesRoughOrg):
@@ -294,6 +296,7 @@ def findSaliantLineCluster(gradient4d,allLines,allLinesIndex,ws, orgW, orgH ):
         
         forceLinesRoughOrg = forceLinesRoughNew
         forceLinesRoughNew = refine(forceLinesRoughNew, fineGrained, wGrained, intePrec, ws)
+        # update parameters
         if fineGrained > 4:
             fineGrained = fineGrained-1
         if intePrec > 0.6:
@@ -301,8 +304,6 @@ def findSaliantLineCluster(gradient4d,allLines,allLinesIndex,ws, orgW, orgH ):
         if wGrained < 10:
             wGrained = wGrained + 1
       
-            
-    
     forceLines = []
     
     for l in forceLinesRoughNew:
@@ -317,7 +318,9 @@ def findSaliantLineCluster(gradient4d,allLines,allLinesIndex,ws, orgW, orgH ):
     return forceLines, forceLinesCluster,HWS
 
 
-
+# Judging whether a line belongs to an existing group of leading lines
+# if a line spatially belongs to the group and the weight are within the threshold, add it to the group;
+# else if the weights are beyond the threshold range(which means it is weakly significant),do not add it to the group, ignore
 def judgeVertexAdvanced(line1,v1, v1w, forceL, wSeuil = 4, intersectPrecent = 0.7):
     v1 = np.array(v1)
     newGroup = False
@@ -333,7 +336,7 @@ def judgeVertexAdvanced(line1,v1, v1w, forceL, wSeuil = 4, intersectPrecent = 0.
 
     return False, forceL
     
- 
+# compute leading lines of the image and generate an image with leading lines
 def getLeadingLine(imgpath, outPath):
     windowSize = 64
     allLines, allLinesIndex = getBaseLines(windowSize)
@@ -347,14 +350,14 @@ def getLeadingLine(imgpath, outPath):
             
         resizeImg = resize(img,(windowSize,windowSize))
 
-         # Add contrast
+        # add contrast
         logImg = exposure.adjust_log(resizeImg, 1)
 
-        
+        # get grayscale image
         grayImg = rgb2gray(logImg)
-            
+        # calculating the gradient
         gradient4d= gradient4D(grayImg)
-        
+        # grouping for leading lines
         forceLines, forceLinesCluster, scale = findSaliantLineCluster(gradient4d,allLines,allLinesIndex,windowSize, orgW, orgH )
         drawGroupLine(imgpath, forceLines, forceLinesCluster, scale, 'forceLines', 'red', outPath)