Пример #1
0
def tile_slices_to_image_uint8(X, tile_shape=None):
    """
    .. todo::

        WRITEME
    """
    if str(X.dtype) != 'uint8':
        raise TypeError(X)
    if tile_shape is None:
        #how many tile rows and cols
        (TR, TC) = most_square_shape(X.shape[0])
    H, W = X.shape[1], X.shape[2]

    Hs = H + 1  #spacing between tiles
    Ws = W + 1  #spacing between tiles

    trows, tcols = most_square_shape(X.shape[0])
    outrows = trows * Hs - 1
    outcols = tcols * Ws - 1
    out = numpy.zeros((outrows, outcols, 3), dtype='uint8')
    tr_stride = 1 + X.shape[1]
    for tr in range(trows):
        for tc in range(tcols):
            Xrc = X[tr * tcols + tc]
            if Xrc.ndim == 2:  # if no color channel make it broadcast
                Xrc = Xrc[:, :, None]
            #print Xrc.shape
            #print out[tr*Hs:tr*Hs+H,tc*Ws:tc*Ws+W].shape
            out[tr * Hs:tr * Hs + H, tc * Ws:tc * Ws + W] = Xrc
    ensure_Image()
    img = Image.fromarray(out, 'RGB')
    return img
Пример #2
0
def tile_slices_to_image_uint8(X, tile_shape=None):
    """
    .. todo::

        WRITEME
    """
    if str(X.dtype) != 'uint8':
        raise TypeError(X)
    if tile_shape is None:
        #how many tile rows and cols
        (TR, TC) = most_square_shape(X.shape[0])
    H, W = X.shape[1], X.shape[2]

    Hs = H+1 #spacing between tiles
    Ws = W+1 #spacing between tiles

    trows, tcols= most_square_shape(X.shape[0])
    outrows = trows * Hs - 1
    outcols = tcols * Ws - 1
    out = numpy.zeros((outrows, outcols,3), dtype='uint8')
    tr_stride= 1+X.shape[1]
    for tr in range(trows):
        for tc in range(tcols):
            Xrc = X[tr*tcols+tc]
            if Xrc.ndim==2: # if no color channel make it broadcast
                Xrc=Xrc[:,:,None]
            #print Xrc.shape
            #print out[tr*Hs:tr*Hs+H,tc*Ws:tc*Ws+W].shape
            out[tr*Hs:tr*Hs+H,tc*Ws:tc*Ws+W] = Xrc
    ensure_Image()
    img = Image.fromarray(out, 'RGB')
    return img
Пример #3
0
def save_tiled_raster_images(tiled_img, filename):
    """Save a a return value from `tile_raster_images` to `filename`.

    Returns the PIL image that was saved
    """
    if tiled_img.ndim==2:
        ensure_Image()
        img = Image.fromarray( tiled_img, 'L')
    elif tiled_img.ndim==3:
        ensure_Image()
        img = Image.fromarray(tiled_img, 'RGBA')
    else:
        raise TypeError('bad ndim', tiled_img)

    img.save(filename)
    return img
Пример #4
0
 def get_img(self):
     #print 'image range '+str((self.image.min(), self.image.max()))
     x = np.cast['uint8'](self.image * 255.0)
     if x.shape[2] == 1:
         x = x[:, :, 0]
     ensure_Image()
     img = Image.fromarray(x)
     return img
Пример #5
0
 def get_img(self):
     #print 'image range '+str((self.image.min(), self.image.max()))
     x = np.cast['uint8'](self.image * 255.0)
     if x.shape[2] == 1:
         x = x[:, :, 0]
     ensure_Image()
     img = Image.fromarray(x)
     return img