Skip to content

[ENH]: directional antialiasing filter #29711

Open
@anntzer

Description

@anntzer

Problem

Currently, the antialiasing filter used by imshow() is applied both in the x and the y direction. There are cases where "image-like" data is highly sampled in one direction (requiring antialiasing) but not in the other, and also has some nans; an example is a kymograph like subfigure 1c at https://www.nature.com/articles/s41467-017-01462-y/figures/1

For such data, the current default interpolation settings (antialiased + rgba (because one of the directions is oversampled) can yield not nice artefacts, in particular at the boundary between "data" and "nan":

from pylab import *

vals = np.full((50, 500), np.nan)
for i, row in enumerate(vals):
    n = 200 + np.random.randint(300)
    row[:n] = np.sin(np.arange(n) / 10 + i / 5)  # make some fake data
axs = figure(layout="constrained", figsize=(10, 10)).subplots(
    3, 3, subplot_kw={"xticks": [], "yticks": []})
for i, interpolation in enumerate([None, "none", "antialiased"]):
    for j, stage in enumerate([None, "data", "rgba"]):
        axs[i, j].text(0, 0, f"{interpolation=}, {stage=}", bbox={"fc": "w"})
        axs[i, j].imshow(vals.T, aspect="auto", origin="lower",
                         interpolation=interpolation, interpolation_stage=stage)
show()

Image

For this specific dataset, the best settings currently available is probably to go back to interpolation="data". But ideally, it would be nice if it was possible to have a separable antialiasing filter (I don't actually know if the current one is separable), so that one can apply it (here) only in the vertical direction (ideally in rgba space).

Proposed solution

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions