Skip to content

Commit f8653d3

Browse files
authored
Working recipe for mimage (#102)
* Working recipe for mimage * bump mimage version * Add CodeQL
1 parent 8764f04 commit f8653d3

File tree

7 files changed

+163
-0
lines changed

7 files changed

+163
-0
lines changed

recipes/mimage/README.md

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