lovely-numpy
  1. ๐Ÿ–ผ๏ธ Image utils
  2. ๐Ÿ”ฒ Pad and frame
  • ๐Ÿ’Ÿ Lovely NumPy
  • ๐Ÿ”Ž Array Representations
    • ๐Ÿงพ View as a summary
    • ๐Ÿ–Œ๏ธ View as RGB images
    • ๐Ÿ“Š View as a histogram
    • ๐Ÿ“บ View channels
  • ๐Ÿ–ผ๏ธ Image utils
    • ๐ŸŽจ color mapping
    • ๐Ÿ”ฒ Pad and frame
    • ๐Ÿ Image grid
  • โœจ Misc
    • ๐Ÿ‘๏ธ Lo and behold!
    • ๐ŸŽญ Matplotlib integration
    • ๐Ÿค” Config

On this page

  • pad_frame
  • pad_frame_gutters
  1. ๐Ÿ–ผ๏ธ Image utils
  2. ๐Ÿ”ฒ Pad and frame

๐Ÿ”ฒ Pad and frame


source

pad_frame

 pad_frame (t:numpy.ndarray, frame_px:int=1, val:float=0)

Pad H and W dimensitons of an image tensor with val of thickness frame_px

Type Default Details
t ndarray torch.Tensor, # 3D+ image tensor, [โ€ฆ,H,W,C]
frame_px int 1 Number of pixels to pad each side.
val float 0 Value to pad with.

Examples

pad_frame(np.zeros((3,3,1)), frame_px=2, val=1).transpose(-1,0,1).astype(int)
array([[[1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 0, 0, 0, 1, 1],
        [1, 1, 0, 0, 0, 1, 1],
        [1, 1, 0, 0, 0, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1]]])
# 1px black frame inside 2px white frame (gutter).
pad_frame(pad_frame(np.ones((3,3,1))), frame_px=2, val=1 ).transpose(-1,0,1).astype(int)
array([[[1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 0, 0, 0, 0, 0, 1, 1],
        [1, 1, 0, 1, 1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1, 1, 0, 1, 1],
        [1, 1, 0, 0, 0, 0, 0, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1]]])

source

pad_frame_gutters

 pad_frame_gutters (t:numpy.ndarray, gutter_px=3, frame_px=1)

Add a black frame and white gutters around an image

Type Default Details
t ndarray 3D+ Tensor image tensor, [โ€ฆ,H,W,C]
gutter_px int 3 Write gutter in pixels.
frame_px int 1 Black frame, in pixels

Examples

Lo(image)
array[3, 196, 196] n=115248 xโˆˆ[-4.053e-09, 1.000] ฮผ=0.361 ฯƒ=0.248
Lo(pad_frame_gutters(image.transpose(1, 2, 0), gutter_px=15, frame_px=3))
array[232, 232, 3] n=161472 xโˆˆ[-4.053e-09, 1.000] ฮผ=0.500 ฯƒ=0.359
def to_pil(x):
    return Image.fromarray(np.uint8(x*255))
    
to_pil(pad_frame_gutters(image.transpose(1, 2, 0), gutter_px=15, frame_px=3))