def loadSampleImages():

    database = []

    for index in range(0,10):

        digitData = []

        fullPath = os.getcwd() + '/digits/{0}/'.format(index)
        print 'Loading the image files for digit {0}...'.format(index)

        for imageFile in os.listdir(fullPath):
            if imageFile.endswith(".tif") or imageFile.endswith(".tiff"): 

                digitImageAnalysis = {}

                imagePath = fullPath + imageFile
                temporaryDigitImage = Image.open(imagePath).convert('L')
                digitImageArray = numpy.asarray(temporaryDigitImage)

                digitImageAnalysis = ocr_analysis.analyzePreResizeDigitImage(digitImageArray, digitImageAnalysis)          # get aspect ratio, ...

                temporaryDigitImage = temporaryDigitImage.crop(ocr_utils.findEndpoints(digitImageArray))                # crop
                temporaryDigitImage = temporaryDigitImage.resize((resizeWidth, resizeHeight))                                  # resize

                digitImageAnalysis = ocr_analysis.analyzePostResizeDigitImage(temporaryDigitImage, digitImageAnalysis)     # get histogram, ...

                digitData.append(digitImageAnalysis)

        database.append(digitData)

    data = compileImageDatabase(database)

    return data
def getVector(originalImage, data):

    originalImageArray = numpy.asarray(originalImage)
    originalImageAspectRatio = ocr_utils.getAspectRatio(originalImageArray)
    originalImage = originalImage.crop(ocr_utils.findEndpoints(originalImageArray))
    originalImage = originalImage.resize((resizeWidth, resizeHeight))

    original50x25Grid = ocr_utils.createMxNGrid(50,25,numpy.asarray(originalImage))
    original40x20Grid = ocr_utils.createMxNGrid(40,20,numpy.asarray(originalImage))
    original20x10Grid = ocr_utils.createMxNGrid(20,10,numpy.asarray(originalImage))
    original5x1Grid = ocr_utils.createMxNGrid(5,1,numpy.asarray(originalImage))
    original1x5Grid = ocr_utils.createMxNGrid(1,5,numpy.asarray(originalImage))
    originalImageVerticalHistogram = ocr_utils.createVerticalHistogram(numpy.asarray(originalImage))
    originalImageHorizontalHistogram = ocr_utils.createHorizontalHistogram(numpy.asarray(originalImage))

    featureVector = []

    recognized50x25GridDigit = getRecognizedMxNGridDigit(original50x25Grid,data,50,25)
    featureVector.append(recognized50x25GridDigit)

    recognized40x20GridDigit = getRecognizedMxNGridDigit(original40x20Grid,data,40,20)
    featureVector.append(recognized40x20GridDigit)

    recognized20x10GridDigit = getRecognizedMxNGridDigit(original20x10Grid,data,20,10)
    featureVector.append(recognized20x10GridDigit)

    recognized5x1GridDigit = getRecognizedMxNGridDigit(original5x1Grid,data,5,1)
    featureVector.append(recognized5x1GridDigit)

    recognized1x5GridDigit = getRecognizedMxNGridDigit(original1x5Grid,data,1,5)
    featureVector.append(recognized1x5GridDigit)

    recognizedVerticalHistogramDigit = getRecognizedVerticalHistogramDigit(originalImageVerticalHistogram,data)
    featureVector.append(recognizedVerticalHistogramDigit)

    recognizedHorizontalHistogramDigit = getRecognizedHorizontalHistogramDigit(originalImageHorizontalHistogram,data)
    featureVector.append(recognizedHorizontalHistogramDigit)

    recognizedAspectRatioDigit = getRecognizedAspectRatioDigit(originalImageAspectRatio,data)
    featureVector.append(recognizedAspectRatioDigit)

    return featureVector