-
-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notebook updates #131
Notebook updates #131
Changes from 15 commits
648926c
c6162a2
d2e3d9b
4611376
8305880
a55302f
0a640e9
85792d9
b29bb29
9fa158b
1f9577b
b659fdc
fdbea1e
9e864c7
c44573f
4ea5fff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
|
||
from .colors import rgb | ||
from .composite import composite_op_lookup, source | ||
from .composite import composite_op_lookup, over | ||
from .utils import ngjit | ||
|
||
|
||
|
@@ -61,7 +61,7 @@ def stack(*imgs, **kwargs): | |
return Image(out, coords=imgs[0].coords, dims=imgs[0].dims) | ||
|
||
|
||
def eq_hist(data, mask=None, nbins=256): | ||
def eq_hist(data, mask=None, nbins=256*256): | ||
"""Return a numpy array after histogram equalization. | ||
|
||
For use in `interpolate`. | ||
|
@@ -114,7 +114,7 @@ def _normalize_interpolate_how(how): | |
raise ValueError("Unknown interpolation method: {0}".format(how)) | ||
|
||
|
||
def interpolate(agg, low=None, high=None, cmap=None, how='cbrt'): | ||
def interpolate(agg, low=None, high=None, cmap=None, how='eq_hist'): | ||
"""Convert a 2D DataArray to an image. | ||
|
||
Data is converted to an image either by interpolating between a `low` and | ||
|
@@ -161,6 +161,8 @@ def interpolate(agg, low=None, high=None, cmap=None, how='cbrt'): | |
offset = agg.data[agg.data > 0].min() | ||
data = how(agg.data - offset, mask.data) | ||
span = [np.nanmin(data), np.nanmax(data)] | ||
if isinstance(cmap,type(reversed(list()))): | ||
cmap = list(cmap) | ||
if isinstance(cmap, list): | ||
rspan, gspan, bspan = np.array(list(zip(*map(rgb, cmap)))) | ||
span = np.linspace(span[0], span[1], len(cmap)) | ||
|
@@ -180,7 +182,7 @@ def interpolate(agg, low=None, high=None, cmap=None, how='cbrt'): | |
return Image(img, coords=agg.coords, dims=agg.dims) | ||
|
||
|
||
def colorize(agg, color_key, how='cbrt', min_alpha=20): | ||
def colorize(agg, color_key, how='eq_hist', min_alpha=20): | ||
"""Color a CategoricalAggregate by field. | ||
|
||
Parameters | ||
|
@@ -245,7 +247,7 @@ def set_background(img, color=None): | |
if color is None: | ||
return img | ||
background = np.uint8(rgb(color) + (255,)).view('uint32')[0] | ||
data = source(img.data, background) | ||
data = over(img.data, background) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change this? This doesn't set the background, it overlays an image over a background of that color. For images that use alpha to indicate magnitude (output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct, and intended. The problem was that previously, if one tried to set the background to black, it only changed the fully transparent pixels, which had very strange results -- if you take such an image and view it in e.g. Preview on a Mac, it's all garbled: the fully transparent pixels are black, but Preview's default gray background shines through (to a greater or lesser extent, depending on alpha) all the others. So I don't think that set_background was doing something useful before; changing only the fully transparent pixels while removing their transparency yet leaving other pixels transparent doesn't result in a usable image in any scenario I can think of, and certainly not in the use cases I had in mind for set_background. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second look, I think I see what you're saying here, but I don't think it's true. I.e., you're worried that the alpha channel will simply be discarded from the top image? The code isn't discarding the src alpha, as far as I can see; it's using it to control how the src gets mixed with the background, which is what we want here. Try comparing census.ipynb with set_background using over and source for comparison, and you should see what I mean... |
||
return Image(data, coords=img.coords, dims=img.dims) | ||
|
||
|
||
|
@@ -326,8 +328,7 @@ def _square_mask(px): | |
def _circle_mask(r): | ||
"""Produce a circular mask with a diameter of ``2 * r + 1``""" | ||
x = np.arange(-r, r + 1, dtype='i4') | ||
bound = r + 0.5 if r > 1 else r | ||
return np.where(np.sqrt(x**2 + x[:, None]**2) <= bound, True, False) | ||
return np.where(np.sqrt(x**2 + x[:, None]**2) <= r+0.5, True, False) | ||
|
||
|
||
_mask_lookup = {'square': _square_mask, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(cmap, collections.Iterator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's better, thanks. Done.