Skip to content

Commit

Permalink
Fix errors from missing labels image when opacity is set to 0
Browse files Browse the repository at this point in the history
- Rather than always skipping images that are invisible, provide an option for whether to create the `AxesImage` object or not
- Create these images for Atlas Editor plots since they need to be available if the opacity is increased
  • Loading branch information
yoda-vid committed Jan 26, 2020
1 parent d32187c commit 16a73dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion magmap/gui/roi_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ def show_overview(ax_ov, lev, imgs, cmaps, vmins, vmaxs):
show.setdefault("vmaxs", []).append(vmax)
show["alphas"] = libmag.pad_seq(
config.alphas, len(show["imgs2d"]), 0.9)
plot_support.overlay_images(ax_ov, aspect, origin, **show)
plot_support.overlay_images(
ax_ov, aspect, origin, ignore_invis=True, **show)
ax_ov.add_patch(patches.Rectangle(
np.divide(patch_offset, downsample),
*np.divide(roi_size[0:2], downsample),
Expand Down
3 changes: 2 additions & 1 deletion magmap/io/export_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def _build_stack(ax, images, process_fnc, rescale=1, aspect=None,
# a nested list containing a list for each image, which in turn
# contains a list of artists for each channel
ax_imgs = plot_support.overlay_images(
ax, aspect, origin, imgs, None, cmaps_all, alphas)
ax, aspect, origin, imgs, None, cmaps_all, alphas,
ignore_invis=True)
if colorbar and len(ax_imgs) > 0 and len(ax_imgs[0]) > 0:
# add colorbar with scientific notation if outside limits
cbar = ax.figure.colorbar(ax_imgs[0][0], ax=ax, shrink=0.7)
Expand Down
12 changes: 8 additions & 4 deletions magmap/plot/plot_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None,
vmax=None, origin=None, interpolation=None,
norms=None, nan_color=None):
norms=None, nan_color=None, ignore_invis=False):
"""Show multichannel 2D image with channels overlaid over one another.
Applies :attr:`config.transform` with :obj:`config.Transforms.ROTATE`
Expand Down Expand Up @@ -55,6 +55,8 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None,
norms: List of normalizations, which should correspond to ``cmaps``.
nan_color (str): String of color to use for NaN values; defaults to
None to use "black".
ignore_invis (bool): True to give None instead of an ``AxesImage``
object that would be invisible; defaults to False.
Returns:
List of ``AxesImage`` objects.
Expand Down Expand Up @@ -102,7 +104,7 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None,
if is_alpha_seq:
alpha_plane = alpha[chl]
img_chl = None
if alpha_plane > 0:
if not ignore_invis or alpha_plane > 0:
# skip display if alpha is 0 to avoid outputting a hidden image
# that may show up in other renderers (eg PDF viewers)
img_chl = ax.imshow(
Expand All @@ -127,7 +129,7 @@ def imshow_multichannel(ax, img2d, channel, cmaps, aspect, alpha, vmin=None,


def overlay_images(ax, aspect, origin, imgs2d, channels, cmaps, alphas,
vmins=None, vmaxs=None):
vmins=None, vmaxs=None, ignore_invis=False):
"""Show multiple, overlaid images.
Wrapper function calling :meth:`imshow_multichannel` for multiple
Expand Down Expand Up @@ -157,6 +159,8 @@ def overlay_images(ax, aspect, origin, imgs2d, channels, cmaps, alphas,
vmaxs: A list of vmaxs for each image; defaults to None to use
:attr:``config.vmax_overview`` for the first image and None
for all others.
ignore_invis (bool): True to avoid creating ``AxesImage`` objects
for images that would be invisible; defaults to False.
Returns:
Nested list containing a list of ``AxesImage`` objects
Expand Down Expand Up @@ -219,7 +223,7 @@ def fill(fill_with, chls, filled=None, pad=None):
ax_img = imshow_multichannel(
ax, img, channels[i], cmap, aspect, alphas[i], vmin=vmins[i],
vmax=vmaxs[i], origin=origin, interpolation="none",
norms=norm, nan_color=nan_color)
norms=norm, nan_color=nan_color, ignore_invis=ignore_invis)
ax_imgs.append(ax_img)
return ax_imgs

Expand Down

0 comments on commit 16a73dc

Please sign in to comment.