Skip to content

Commit 87c307e

Browse files
committed
Working recipe for mimage
1 parent 76b0928 commit 87c307e

7 files changed

Lines changed: 164 additions & 0 deletions

File tree

recipes/mimage/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<br/>
2+
<p align="center">
3+
<a href="https://github.com/fnands/mimage">
4+
<img src="image.jpeg" alt="Logo" width="200" height="200">
5+
</a>
6+
7+
<h1 align="center">Mimage</h1>
8+
9+
<p align="center">
10+
A library for reading images in pure* Mojo 🔥
11+
</p>
12+
</p>
13+
14+
<div align="center">
15+
<img src="https://img.shields.io/badge/%F0%9F%94%A5%20Mojo-020B14?style=for-the-badge&link=https%3A%2F%2Fwww.modular.com%2Fmax%2Fmojo" />
16+
</div>
17+
18+
*Not pure Mojo yet, but hopefully soon.
19+
## About The Project
20+
21+
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.
22+
23+
## Quick Start
24+
25+
Basic usage:
26+
27+
```mojo
28+
import mimage as mi
29+
30+
def main():
31+
32+
tensor = mi.imread("my/png/image.png")
33+
34+
```
35+
36+
Try out the tests yourself:
37+
38+
```sh
39+
mojo -I . tests/test_open_png.mojo
40+
```
41+
42+
## Roadmap
43+
44+
### v0.1.0 ✅
45+
- [x] Read simple 8-bit PNGs
46+
47+
### Near term
48+
- [ ] Read jpegs
49+
50+
### Medium term
51+
- [ ] Read more complex PNGs
52+
- [ ] Write PNGs
53+
- [ ] Write jpegs
54+
55+
### Long term
56+
- [ ] v1.0.0 will be achieved when Mimage can open all the same images as Pillow.
57+
58+
59+
## Contributing
60+
61+
Before creating a new issue, please:
62+
* Check if the issue already exists. If an issue is already reported, you can contribute by commenting on the existing issue.
63+
* If not, create a new issue and include all the necessary details to understand/recreate the problem or feature request.
64+
65+
### Creating A Pull Request
66+
67+
1. Fork the Project
68+
2. Create your Feature Branch
69+
3. Commit your Changes
70+
4. Push to the Branch
71+
5. Open a Pull Request
72+
> Once your changes are pushed, navigate to your fork on GitHub. And create a pull request against the original fnands/mimage repository.
73+
> - Before creating a PR make sure it doesn't break any of the unit-tests. (e.g. `mojo -I . tests/test_open_png.mojo`)
74+
> - Introducing new big features requires a new test!
75+
> - In the pull request, provide a detailed description of the changes and why they're needed. Link any relevant issues.
76+
> - If there are any specific instructions for testing or validating your changes, include those as well.
77+
78+
## License
79+
80+
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.
81+
82+
## Acknowledgements
83+
84+
* Built with [Mojo](https://github.com/modularml/mojo) created by [Modular](https://github.com/modularml)

recipes/mimage/image.jpeg

174 KB
Loading

recipes/mimage/recipe.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
context:
2+
version: "0.2.1"
3+
4+
package:
5+
name: "mimage"
6+
version: ${{ version }}
7+
8+
source:
9+
- git: https://github.com/fnands/mimage.git
10+
tag: "0.2.1"
11+
12+
build:
13+
number: 0
14+
script:
15+
- mojo package mimage -o ${{ PREFIX }}/lib/mojo/mimage.mojopkg
16+
requirements:
17+
host:
18+
- max=25.2
19+
run:
20+
- ${{ pin_compatible('max') }}
21+
22+
tests:
23+
- script:
24+
- if: unix
25+
then:
26+
- mojo run -I ${{ PREFIX }}/lib/mojo/mimage.mojopkg tests/test_open_png.mojo
27+
28+
requirements:
29+
run:
30+
- max=25.2
31+
- pillow
32+
- numpy
33+
34+
files:
35+
recipe:
36+
- tests/test_open_png.mojo
37+
- tests/testing_utils.mojo
38+
- tests/__init__.mojo
39+
- tests/images/hopper.png
40+
41+
about:
42+
homepage: https://github.com/fnands/mimage
43+
license: Apache-2.0
44+
license_file: LICENSE
45+
summary: mimage is a library for image processing in Mojo 🔥.
46+
repository: https://github.com/fnands/mimage
47+
48+
extra:
49+
project_name: mimage
50+
maintainers:
51+
- fnands

recipes/mimage/tests/__init__.mojo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .testing_utils import *
29.9 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import mimage as mi
2+
from pathlib import Path
3+
from tests import compare_to_numpy
4+
5+
6+
def main():
7+
hop_tensor = mi.imread("tests/images/hopper.png")
8+
hop_tensor = mi.imread(String("tests/images/hopper.png"))
9+
hop_tensor = mi.imread(Path("tests/images/hopper.png"))
10+
11+
compare_to_numpy(hop_tensor, "tests/images/hopper.png")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from tensor import Tensor
2+
from python import Python
3+
from testing import assert_true
4+
5+
6+
fn compare_to_numpy(mojo_tensor: Tensor, image_path: StringLiteral) raises:
7+
var PillowImage = Python.import_module("PIL.Image")
8+
var np = Python.import_module("numpy")
9+
var py_array = np.array(PillowImage.open(image_path))
10+
11+
for rows in range(mojo_tensor.shape()[0]):
12+
for columns in range(mojo_tensor.shape()[1]):
13+
for channels in range(mojo_tensor.shape()[2]):
14+
assert_true(
15+
mojo_tensor[rows, columns, channels] == py_array[rows][columns][channels].__int__(),
16+
"Pixel values do not match",
17+
)

0 commit comments

Comments
 (0)