NxHighlighter

Image highlighting using Nx and tensors.

Features

Installation

Add nx_highlighter to your list of dependencies in mix.exs:

def deps do
  [
    {:nx_highlighter, "~> 0.1.0"}
  ]
end

Usage

The library handles image loading and saving via stb_image. It preserves the input format: if you pass a binary, you get a binary; if you pass a tensor, you get a tensor.

High-level API

image_bin = File.read!("image.png")
regions = [
  %{x: 10, y: 10, w: 100, h: 20, color: [255, 0, 0]},
  %{x: 120, y: 10, w: 50, h: 20, color: [255, 0, 0]}
]

# Returns {:ok, png_binary}
{:ok, highlighted_png} = NxHighlighter.highlight(image_bin, regions, alpha: 0.5)
File.write!("highlighted.png", highlighted_png)

Tensor API

If you are already working with tensors, you can use highlight_tensor/3 to avoid encoding/decoding overhead.

{:ok, result_tensor} = NxHighlighter.highlight_tensor(my_tensor, regions)

License

This project is licensed under the MIT License - see the LICENSE file for details.