Beispiel #1
0
 def __init__(self, data, width, height):
     """
     Create a new datum from file input (standard MNIST encoding).
     """
     self.height = width
     self.width = height
     if data == None:
         data = [[' ' for i in range(width)] for j in range(height)]
     self.pixels = util.arrayInvert(convertToInteger(data))
Beispiel #2
0
 def getAsciiString(self):
     """
     Renders the data item as an ascii image.
     """
     rows = []
     data = util.arrayInvert(self.pixels)
     for row in data:
         ascii = map(asciiGrayscaleConversionFunction, row)
         rows.append( "".join(ascii) )
     return "\n".join(rows)
Beispiel #3
0
 def getAsciiString(self):
     """
     Renders the data item as an ascii image.
     """
     rows = []
     data = util.arrayInvert(self.pixels)
     for row in data:
         ascii = list(map(asciiGrayscaleConversionFunction, row))
         rows.append( "".join(ascii) )
     return "\n".join(rows)
Beispiel #4
0
 def __init__(self, data,width,height):
     """
     Create a new datum from file input (standard MNIST encoding).
     """
     DATUM_HEIGHT = height
     DATUM_WIDTH=width
     self.height = DATUM_HEIGHT
     self.width = DATUM_WIDTH
     if data == None:
         data = [[' ' for i in range(DATUM_WIDTH)] for j in range(DATUM_HEIGHT)]
     self.pixels = util.arrayInvert(convertToInteger(data))
Beispiel #5
0
 def __init__(self, data,width,height):
     """
     Create a new datum from file input (standard MNIST encoding).
     """
     IMAGE_HEIGHT = height
     IMAGE_WIDTH = width
     self.height = IMAGE_HEIGHT
     self.width = IMAGE_WIDTH
     if data == None:
         data = [[' ' for i in range(IMAGE_WIDTH)] for j in range(IMAGE_HEIGHT)]
     self.pixels = util.arrayInvert(convertToInteger(data))
Beispiel #6
0
 def __init__(self, data,width,height):
   """
   Create a new datum from file input (standard MNIST encoding).
   """
   DATUM_HEIGHT = height
   DATUM_WIDTH=width
   self.height = DATUM_HEIGHT
   self.width = DATUM_WIDTH
   if data == None:
     data = [[' ' for i in range(DATUM_WIDTH)] for j in range(DATUM_HEIGHT)] 
   # print('data inside datum ',convertToInteger(data))
   # for key,value in convertToInteger(data[10]).items():
   #   print(key,value)
   self.pixels = util.arrayInvert(convertToInteger(data)) 
Beispiel #7
0
def getNewDatum(datum, hgetHighlightedArea):
    image = util.arrayInvert(datum.getPixels())
    width = datum.width
    height = datum.height
    for x in range(FACE_DATUM_WIDTH):
        for y in range(FACE_DATUM_HEIGHT):
            if not hgetHighlightedArea[(x, y)]:
                image[y][x] = ' ' 
            elif image[y][x] == 0:
                image[y][x] = ' '
            elif image[y][x]:
                image[y][x] = '+'
    
    newDatum = samples.Datum(image, width, height)
    return newDatum
Beispiel #8
0
def get_labeled_components(datum):
    # get the list of connected components, remove the small component and return the number of components left
    
    image = util.arrayInvert(datum.getPixels()) 
    # now image is a array
    width = len(image)
    height = len(image[0])
    visited = []
    labeledComponents = {}
    for i in range(width):
        for j in range(height):
            if datum.getPixel(i, j) == 0 and (i, j) not in visited:
                label = (i, j)
                labeledComponents[label]= []
                dfs_hole(i, j, datum, visited, labeledComponents, label)
    return labeledComponents, visited
def get_labeled_components(datum):
    # get the list of connected components, remove the small component and return the number of components left
    
    image = util.arrayInvert(datum.getPixels()) 
    # now image is a array
    width = len(image)
    height = len(image[0])
    visited = []
    labeledComponents = {}
    for i in range(width):
        for j in range(height):
            if datum.getPixel(i, j) == 0 and (i, j) not in visited:
                label = (i, j)
                labeledComponents[label]= []
                dfs_hole(i, j, datum, visited, labeledComponents, label)
            
    return labeledComponents, visited
Beispiel #10
0
def blur(datum, radius):
    # radius is 1, 2, 3, ....
    # expand the image
    image = util.arrayInvert(datum.getPixels()) 
    # now image is a array
    width = len(image)
    height = len(image[0])
    
    newWidth = width + radius * 2
    newHeight = height + radius * 2
    
    newImage = []
    for i in range(newWidth):
        l = []
        for j in range(newHeight):
            l.append(0)
        newImage.append(l)
    for i in range(width):
        for j in range(height):
            if image[i][j] == 0:
                newImage[i + radius][j + radius] = 0
            else:
                newImage[i + radius][j + radius] = 1
    
    for i in range(width):
        for j in range(height):
            if image[i][j] > 0:
                image[i][j] = '+'
                continue
            sum = 0
            sum = newImage[i + radius - 1][j + radius] + newImage[i + radius + 1][j + radius] + newImage[i + radius][j + radius - 1] + newImage[i + radius][j + radius + 1]
            """
            for k in range(-1, 2): 
                for l in range(-1, 2):
                    sum += newImage[i + radius + k][j + radius + l]
            if sum / 9.0 > 0.5:
            """
            if sum > 2:
                image[i][j] = '+' 
            else:
                image[i][j] = ' '

    newDatum = samples.Datum(image, width, height)
    return newDatum
def blur(datum, radius):
    # radius is 1, 2, 3, ....
    # expand the image
    image = util.arrayInvert(datum.getPixels()) 
    # now image is a array
    width = len(image)
    height = len(image[0])
    
    newWidth = width + radius * 2
    newHeight = height + radius * 2
    
    newImage = []
    for i in range(newWidth):
        l = []
        for j in range(newHeight):
            l.append(0)
        newImage.append(l)
    for i in range(width):
        for j in range(height):
            if image[i][j] == 0:
                newImage[i + radius][j + radius] = 0
            else:
                newImage[i + radius][j + radius] = 1
    
    for i in range(width):
        for j in range(height):
            if image[i][j] > 0:
                image[i][j] = '+'
                continue
            sum = 0
            sum = newImage[i + radius - 1][j + radius] + newImage[i + radius + 1][j + radius] + newImage[i + radius][j + radius - 1] + newImage[i + radius][j + radius + 1]
            """
            for k in range(-1, 2): 
                for l in range(-1, 2):
                    sum += newImage[i + radius + k][j + radius + l]
            if sum / 9.0 > 0.5:
            """
            if sum > 2:
                image[i][j] = '+' 
            else:
                image[i][j] = ' '

    newDatum = samples.Datum(image, width, height)
    return newDatum
    def __init__(self, data, width, height):
        """
    Create a new datum from file input (standard MNIST encoding).
    """
        DATUM_HEIGHT = height
        DATUM_WIDTH = width
        self.height = DATUM_HEIGHT
        self.width = DATUM_WIDTH
        if data == None:
            data = [[' ' for i in range(DATUM_WIDTH)]
                    for j in range(DATUM_HEIGHT)]

        #############################################################################
        #Edited By Nick Nasta
        #Original: self.pixels = util.arrayInvert(convertToInteger(data))
        for i in range(data.__len__()):
            for j in range(data[i].__len__()):
                data[i][j] = convertToInteger(data[i][j])

        #print(data)
        self.pixels = util.arrayInvert(data)