def print_digit(pixels): width = DIGIT_DATUM_WIDTH height = DIGIT_DATUM_HEIGHT pixels = pixels[:width*height] image = pixels.reshape((width, height)) datum = samples.Datum(samples.convertToTrinary(image),width,height) print(datum)
def print_image(self, pixels, ax=None): """ Prints a Datum object that contains all pixels in the provided list of pixels. This will serve as a helper function to the analysis function you write. Pixels should take the form [(2,2), (2, 3), ...] where each tuple represents a pixel. """ image = samples.Datum(None, self.width, self.height) for pix in pixels: try: # This is so that new features that you could define which # which are not of the form of (x,y) will not break # this image printer... x, y = pix image.pixels[x][y] = 2 except: print("new features:", pix) continue if ax: pixels = np.asarray(np.asarray(image.pixels).T) im = np.zeros((pixels.shape[0], pixels.shape[1], 3)) im[pixels >= 1] = [0, 1, 0] im[pixels < 1] = [0, 0, 0] ax.imshow(im, interpolation='nearest') else: print(image)
def printImage(pixels, width, height): """ Generates a Datum object that contains all pixels in the provided list of pixels. This will serve as a helper function to the analysis function you write. """ image = samples.Datum(None, width, height) for x, y in pixels: image.pixels[x][y] = 2 print image
def printImage(self, pixels): image = samples.Datum(None, self.width, self.height) for pix in pixels: try: # This is so that new features that you could define which # which are not of the form of (x,y) will not break # this image printer... x, y = pix image.pixels[x][y] = 2 except: print "new features:", pix continue print image
def load1Data(file, n, width, height): #fin = samples.readlines(filename) #fin.reverse() data = [] for j in range(height): data.append(list(file[(n * height) + j])) if (len(data[0]) < width - 1): # we encountered end of file... print(("Truncating at %d examples (maximum)" % i)) break item = samples.Datum(data, width, height) return item
def printImage(pixels, width, height): """ Generates a Datum object that contains all pixels in the provided list of pixels. This will serve as a helper function to the analysis function you write. Pixels should take the form [(2,2), (2, 3), ...] where each double represents a pixel. """ image = samples.Datum(None, width, height) for x, y in pixels: image.pixels[x][y] = 2 print image
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
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 printImage(self, pixels): """ Prints a Datum object that contains all pixels in the provided list of pixels. This will serve as a helper function to the analysis function you write. Pixels should take the form [(2,2), (2, 3), ...] where each tuple represents a pixel. """ image = samples.Datum(None, self.width, self.height) for pix in pixels: try: # This is so that new features that you could define which # which are not of the form of (x,y) will not break # this image printer... x, y = pix image.pixels[x][y] = 2 except: print "new features:", pix continue print image