Skip to content

Commit

Permalink
Gallery updates (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney authored Jun 29, 2020
1 parent 370052a commit 961c22b
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 269 deletions.
12 changes: 12 additions & 0 deletions arlunio/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def _repr_png_(self):
# Give nice previews in jupyter notebooks
return self.img._repr_png_()

@property
def size(self):
return self.img.size

def alpha_composite(self, im, *args, **kwargs):
"""Composites an image onto this image.
Expand Down Expand Up @@ -85,6 +89,14 @@ def save(self, *args, **kwargs):
"""
self.img.save(*args, **kwargs)

def thumbnail(self, *args, **kwargs):
"""Convert this image into a thumbail.
See :meth:`pillow:PIL.Image.Image.thumbnail`
"""

self.img.thumbnail(*args, **kwargs)


def new(*args, **kwargs):
"""Creates a new image with the given mode and size
Expand Down
23 changes: 17 additions & 6 deletions arlunio/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ def any_(*args: Union[bool, np.ndarray, Mask]) -> Mask:
The arguments can be any mixture of booleans, arrays and masks.
>>> mask.any_(False, mask.Mask([True, False]), np.array([[False, True], [True, False]])) # noqa: E501
>>> mask.any_(
... False,
... mask.Mask([True, False]),
... np.array([[False, True], [True, False]])
... )
Mask([[ True, True],
[ True, False]])
Expand Down Expand Up @@ -265,7 +269,11 @@ def all_(*args: Union[bool, np.ndarray, Mask]) -> Mask:
Arugments can be any mixture of booleans, masks and numpy arrays.
>>> mask.all_(True, mask.Mask([True, False]), np.array([[False, True], [True, False]])) # noqa: E501
>>> mask.all_(
... True,
... mask.Mask([True, False]),
... np.array([[False, True], [True, False]])
... )
Mask([[False, False],
[ True, False]])
Expand Down Expand Up @@ -467,8 +475,9 @@ def Map(width: int, height: int, *, layout=None, legend=None, fill=None) -> Mask
])
map_ = mask.Map(legend=legend, layout=layout)
img = image.fill(map_(width=1080, height=1080), foreground="blue")
img = image.fill(
map_(width=1080, height=1080), foreground="blue", background="white"
)
"""
fill = fill if fill is not None else Empty()

Expand Down Expand Up @@ -556,7 +565,7 @@ def Pixelize(width: int, height: int, *, mask=None, defn=None, scale=16) -> Mask
])
defn = mask.Pixelize(mask=face)
img = image.fill(defn(width=512, height=512))
img = image.fill(defn(width=512, height=512), background="white")
We can also generate the mask directly from another definition.
Expand Down Expand Up @@ -589,7 +598,9 @@ def Ghost(x: math.X, y: math.Y) -> mask.Mask:
return (head(x=x, y=y) - eyes(x=np.abs(x), y=y)) + body
ghost = mask.Pixelize(defn=Ghost(y0=-0.3), scale=32)
img = image.fill(ghost(width=1080, height=1080), foreground="#f00")
img = image.fill(
ghost(width=1080, height=1080), foreground="#f00", background="white"
)
"""
logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion arlunio/raytrace/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def NormalMap(scatter: ScatterPoint):
def LambertianDiffuse(scatter: ScatterPoint, *, color="lightgrey"):
"""Lambertian diffuse material."""

color = getcolorf(color)
color = getcolorf(color, "RGB")
n = scatter.p.shape[0]

origin = scatter.p
Expand Down
22 changes: 12 additions & 10 deletions arlunio/raytrace/render.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import logging

import numpy as np
import PIL.Image as Image

import arlunio as ar
import arlunio.image as image
import arlunio.math as math
from .camera import SimpleCamera
from .data import Rays
from .data import ScatterPoint
from .material import Gradient
from .material import LambertianDiffuse
from arlunio.math import clamp


@ar.definition
def ZDepthRenderer(width: int, height: int, *, camera=None, objects=None):
def ZDepthRenderer(
width: int, height: int, *, camera=None, objects=None
) -> image.Image:
"""A renderer that returns a z-depth pass."""

camera = SimpleCamera() if camera is None else camera
Expand All @@ -32,7 +34,7 @@ def ZDepthRenderer(width: int, height: int, *, camera=None, objects=None):
vs = np.array((depth / np.max(depth)) * 255, dtype=np.uint8)
vs = vs.reshape(height, width)

return Image.fromarray(vs, "L")
return image.fromarray(vs, "L")


@ar.definition
Expand All @@ -45,7 +47,7 @@ def ClayRenderer(
camera=None,
objects=None,
bounces=8,
):
) -> image.Image:
"""A simple clay renderer."""

background = Gradient() if background is None else background
Expand Down Expand Up @@ -171,7 +173,7 @@ def MaterialRenderer(


@ar.definition
def SampledRenderer(width: int, height: int, *, kernel=None, samples=10):
def SampledRenderer(width: int, height: int, *, kernel=None, samples=10) -> image.Image:
"""A renderer is responsible for orchestrating the entire process."""

if kernel is None:
Expand All @@ -188,11 +190,11 @@ def SampledRenderer(width: int, height: int, *, kernel=None, samples=10):
# Gamma correction...
cols = np.sqrt(cols)

r = clamp(cols[:, 0], 0, 0.99999) * 256
g = clamp(cols[:, 1], 0, 0.99999) * 256
b = clamp(cols[:, 2], 0, 0.99999) * 256
r = math.clamp(cols[:, 0], 0, 0.99999) * 256
g = math.clamp(cols[:, 1], 0, 0.99999) * 256
b = math.clamp(cols[:, 2], 0, 0.99999) * 256

color = np.array(np.dstack([r, g, b])[0], dtype=np.uint8)
color = color.reshape(height, width, 3)

return Image.fromarray(color, "RGB")
return image.fromarray(color, "RGB")
Loading

0 comments on commit 961c22b

Please sign in to comment.