Example #1
0
def correlationTop(target, directory):
  best = -1
  bestFile = ""
  for libImage in os.listdir(directory):
    if libImage[0] != ".":
      thisCorrelation = oneDPearsonHelp(target, algo2.centerCut(Image.open(directory + libImage)))
      if thisCorrelation > best:
        best = thisCorrelation
        bestFile = libImage
  return (bestFile, best)
Example #2
0
def distanceTop(target, directory):
  best = sys.maxint
  bestFile = ""
  for libImage in os.listdir(directory):
    if libImage[0] != ".":
      thisDist = rawDistanceHelp(target, algo2.centerCut(Image.open(directory + libImage)))
      if thisDist < best:
        best = thisDist
        bestFile = libImage
  return (bestFile, best)
Example #3
0
def correlationTop(target, directory):
    best = -1
    bestFile = ""
    for libImage in os.listdir(directory):
        if libImage[0] != ".":
            thisCorrelation = oneDPearsonHelp(
                target, algo2.centerCut(Image.open(directory + libImage)))
            if thisCorrelation > best:
                best = thisCorrelation
                bestFile = libImage
    return (bestFile, best)
Example #4
0
def distanceTop(target, directory):
    best = sys.maxint
    bestFile = ""
    for libImage in os.listdir(directory):
        if libImage[0] != ".":
            thisDist = rawDistanceHelp(
                target, algo2.centerCut(Image.open(directory + libImage)))
            if thisDist < best:
                best = thisDist
                bestFile = libImage
    return (bestFile, best)
Example #5
0
def classify(target, directory=dropBoxDir):
    target = Image.open(target)
    try:
        target_crop = algo2.centerCut(target)
    except:
        return (None, False, None, None)
    topFileByDist, topDistVal = distanceTop(target_crop, directory)
    if topDistVal < 20:
        #Strong Classification
        return ('library/' + topFileByDist, True, topDistVal, None)
    elif topDistVal < 40:
        #Weak Classification
        return ('library/' + topFileByDist, False, topDistVal, None)
    else:
        topFileByCorr, topCorrVal = correlationTop(target_crop, directory)
        parent = 'library/' + topFileByDist
        if parent != topFileByCorr: parent = None
        return (parent, False, topDistVal, topCorrVal)
Example #6
0
def classify(target, directory = dropBoxDir):
  target = Image.open(target)
  try:
    target_crop = algo2.centerCut(target)
  except:
    return (None, False, None, None)
  topFileByDist, topDistVal = distanceTop(target_crop, directory)
  if topDistVal < 20:
    #Strong Classification
    return ('library/' + topFileByDist, True, topDistVal, None)  
  elif topDistVal < 40: 
    #Weak Classification
    return ('library/' + topFileByDist, False, topDistVal, None)
  else:
    topFileByCorr, topCorrVal = correlationTop(target_crop, directory)
    parent = 'library/' + topFileByDist
    if parent != topFileByCorr: parent = None
    return (parent, False, topDistVal, topCorrVal)