Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions recipes/mimage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<br/>
<div align="center">
<a href="https://github.com/fnands/mimage">
<img src="image.jpeg" alt="Logo" width="200" height="200">
</a>

<h1 align="center">Mimage</h1>

<p align="center">
A library for reading images in pure* Mojo 🔥

![Language Badge](https://img.shields.io/badge/language-mojo-orange)
![CodeQL](https://github.com/fnands/mimage/workflows/CodeQL/badge.svg)
</p>
</div>

*Not pure Mojo yet, but hopefully soon.
## About The Project

Mimage is a image manipulation library loosely based on Python's [Pillow](https://github.com/python-pillow/Pillow). The goal is to be able to read and write the most popular image formats directly from Mojo.

## Quick Start

Basic usage:

```mojo
import mimage as mi

def main():

tensor = mi.imread("my/png/image.png")

```

Try out the tests yourself:

```sh
mojo -I . tests/test_open_png.mojo
```

## Roadmap

### v0.1.0 ✅
- [x] Read simple 8-bit PNGs

### Near term
- [ ] Read jpegs

### Medium term
- [ ] Read more complex PNGs
- [ ] Write PNGs
- [ ] Write jpegs

### Long term
- [ ] v1.0.0 will be achieved when Mimage can open all the same images as Pillow.


## Contributing

Before creating a new issue, please:
* Check if the issue already exists. If an issue is already reported, you can contribute by commenting on the existing issue.
* If not, create a new issue and include all the necessary details to understand/recreate the problem or feature request.

### Creating A Pull Request

1. Fork the Project
2. Create your Feature Branch
3. Commit your Changes
4. Push to the Branch
5. Open a Pull Request
> Once your changes are pushed, navigate to your fork on GitHub. And create a pull request against the original fnands/mimage repository.
> - Before creating a PR make sure it doesn't break any of the unit-tests. (e.g. `mojo -I . tests/test_open_png.mojo`)
> - Introducing new big features requires a new test!
> - In the pull request, provide a detailed description of the changes and why they're needed. Link any relevant issues.
> - If there are any specific instructions for testing or validating your changes, include those as well.

## License

Distributed under the Apache 2.0 License with LLVM Exceptions. See [LICENSE](https://github.com/fnands/mimage/blob/main/LICENSE) and the LLVM [License](https://llvm.org/LICENSE.txt) for more information.

## Acknowledgements

* Built with [Mojo](https://github.com/modularml/mojo) created by [Modular](https://github.com/modularml)
Binary file added recipes/mimage/image.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions recipes/mimage/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
context:
version: "0.2.3"

package:
name: "mimage"
version: ${{ version }}

source:
- git: https://github.com/fnands/mimage.git
tag: "0.2.3"

build:
number: 0
script:
- mojo package mimage -o ${{ PREFIX }}/lib/mojo/mimage.mojopkg
requirements:
host:
- max=25.2
run:
- ${{ pin_compatible('max') }}

tests:
- script:
- if: unix
then:
- mojo run -I ${{ PREFIX }}/lib/mojo/mimage.mojopkg tests/test_open_png.mojo

requirements:
run:
- max=25.2
- pillow
- numpy

files:
recipe:
- tests/test_open_png.mojo
- tests/testing_utils.mojo
- tests/__init__.mojo
- tests/images/hopper.png

about:
homepage: https://github.com/fnands/mimage
license: Apache-2.0
license_file: LICENSE
summary: mimage is a library for image processing in Mojo 🔥.
repository: https://github.com/fnands/mimage

extra:
project_name: mimage
maintainers:
- fnands
1 change: 1 addition & 0 deletions recipes/mimage/tests/__init__.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .testing_utils import *
Binary file added recipes/mimage/tests/images/hopper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions recipes/mimage/tests/test_open_png.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mimage as mi
from pathlib import Path
from tests import compare_to_numpy


def main():
hop_tensor = mi.imread("tests/images/hopper.png")
hop_tensor = mi.imread(String("tests/images/hopper.png"))
hop_tensor = mi.imread(Path("tests/images/hopper.png"))

compare_to_numpy(hop_tensor, "tests/images/hopper.png")
17 changes: 17 additions & 0 deletions recipes/mimage/tests/testing_utils.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from tensor import Tensor
from python import Python
from testing import assert_true


fn compare_to_numpy(mojo_tensor: Tensor, image_path: StringLiteral) raises:
var PillowImage = Python.import_module("PIL.Image")
var np = Python.import_module("numpy")
var py_array = np.array(PillowImage.open(image_path))

for rows in range(mojo_tensor.shape()[0]):
for columns in range(mojo_tensor.shape()[1]):
for channels in range(mojo_tensor.shape()[2]):
assert_true(
mojo_tensor[rows, columns, channels] == py_array[rows][columns][channels].__int__(),
"Pixel values do not match",
)