Overview • Installation • Examples
Mosaic is a cross-platform (macOS and linux) computer vision library for prototyping and production.
By transparently leveraging hardware acceleration and using the latest MLIR compiler technology, Mosaic is the first computer vision library built specifically for heterogenous compute: CPUs, GPUs, XPUs.
It unifies the computer vision workflow into one language that runs on any hardware.
- Easy to use
- Type-safe, memory-safe
- Performant
- Image representation
- Image file encoding and decoding
- Data type specification (at compile time)
- Color space specification (at compile time)
- Image processing
- Filtering
- Geometric transforms
- Fourier transforms
- Video capture (currently only macOS)
- Stream connected cameras
- Video processing (currently only macOS)
- Filter live video using custom processors
- Visualization (currently only macOS)
- Native image and video rendering
- Hardware acceleration
- Parallelization and SIMD on CPUs
- GPU acceleration when available
- Magic (the Mojo environment and package manager)
magic add mosaic
The mojoproject.toml
file should include the Modular community channel and the Mosaic dependency:
[project]
channels = ["https://repo.prefix.dev/modular-community"]
[dependencies]
mosaic = "*"
Clone the repo and build Mosaic:
git clone git@github.com:christianbator/mosaic.git
cd mosaic
magic run build
Run an example file from the examples/
directory like so:
cd examples
magic run mojo load_image.mojo
- Loads an image file and displays it in the visualizer
- Source: examples/load_image.mojo
- Saves an image to a file
- Source: examples/save_image.mojo
- Scales an image to half size using bilinear interpolation
- Source: examples/scale_image.mojo
- Resizes an image to double its width, stretching it in the process
- Source: examples/resize_image.mojo
- Slices the top half of an image
- Image slices are mutable views into the underlying image data
- Source: examples/slice_image.mojo
- Rotates an image by 90° clockwise
- Source: examples/rotate_image.mojo
- Flips an image vertically
- Source: examples/flip_image.mojo
- Pads an image with zeros
- Source: examples/pad_image.mojo
- Starting with a
uint8
image, explicitly converts it tofloat64
- Source: examples/convert_type.mojo
- Converts an RGB image to greyscale
- Source: examples/convert_color_space.mojo
- Converts a
float64
RGB image touint8
greyscale in one method - Source: examples/convert_astype.mojo
- Blurs an image using the built-in Gaussian kernel and reflected border handling
- Source: examples/blur_image.mojo
- Detects edges in an image by smoothing and applying a custom Laplacian kernel
- Source: examples/detect_edges.mojo
- Applies unsharp masking and image stacking to visualize the results
- Source: examples/unsharp_mask.mojo
- Captures a sub-rect of an image and copies it to the top left corner
- Source: examples/picture_in_picture.mojo
- Extracts the green channel of an RGB image
- Source: examples/extract_channel.mojo
- Calculates the spectrum of an image using the Fourier transform
- Source: examples/fourier_transform.mojo
- Recreates an image from a previously calculated spectrum
- Source: examples/inverse_fourier_transform.mojo
- Applies a high-pass filter by discarding low frequencies in the spectrum
- Source: examples/high_pass_filter.mojo
- Opens the first available camera and visualizes the frames
- Source: examples/video_capture.mojo
- Detects edges in the camera stream
- Source: examples/video_processing.mojo