Fork me on GitHub

src/arraymancer/io/io_image

  Source Edit

Procs

proc read_image(buffer: seq[byte]): Tensor[uint8] {.
    ...raises: [STBIException, ValueError], tags: [], forbids: [].}

Read an image from a buffer and loads it into a Tensoruint8 of shape Channel x Height x Width. Channel is 1 for greyscale, 3 for RGB.

Supports JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM See stb_image https://github.com/nothings/stb/blob/master/stb_image.h

  Source Edit
proc read_image(filepath: string): Tensor[uint8] {.
    ...raises: [STBIException, ValueError], tags: [], forbids: [].}

Read an image file and loads it into a Tensoruint8 of shape Channel x Height x Width. Channel is 1 for greyscale, 3 for RGB.

Supports JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM See stb_image https://github.com/nothings/stb/blob/master/stb_image.h

Usage example with conversion to 0..1 float: .. code:: nim let raw_img = read_image('path/to/image.png') let img = raw_img.map_inline: x.float32 / 255.0

  Source Edit
proc write_bmp(img: Tensor[uint8]; filepath: string) {....raises: [ValueError],
    tags: [], forbids: [].}
Create an image file from a tensor   Source Edit
proc write_jpg(img: Tensor[uint8]; filepath: string; quality = 100) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Create a jpeg image file from a tensor   Source Edit
proc write_png(img: Tensor[uint8]; filepath: string) {....raises: [ValueError],
    tags: [], forbids: [].}
Create an image file from a tensor   Source Edit
proc write_tga(img: Tensor[uint8]; filepath: string) {....raises: [ValueError],
    tags: [], forbids: [].}
Create an image file from a tensor   Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood