Skip to content
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

feature request for image show #3595

Closed
YongcaiHuang opened this issue Sep 18, 2024 · 1 comment
Closed

feature request for image show #3595

YongcaiHuang opened this issue Sep 18, 2024 · 1 comment

Comments

@YongcaiHuang
Copy link

What is your suggestion?

feature goal

to request the image show function, like matplotlib.pyplot.imshow

motivating

interaction is the advantages of altair. in image processing and even deep learning image cases, exploration of image is necessary. on the other hands, matplotlib requires more code and final effect is not that good.

expected behavior

below is the example

  1. show the image pixel position and value
  2. interaction with widget, like slider
import matplotlib.pyplot as plt
from matplotlib import widgets
from skimage import data, color

ast_rgb = data.astronaut()
ast_hsv = color.rgb2hsv(ast_rgb)
ast_hsv = (ast_hsv * 255).astype('uint8')

fig = plt.figure()
axs = fig.subplots(4, 1, gridspec_kw={'height_ratios': [5, 5, 1, 1]})
img_origin_ax: plt.Axes = axs[0]
img_one_channel_ax: plt.Axes = axs[1]
threshold_slider_ax: plt.Axes = axs[2]
channel_slider_ax: plt.Axes = axs[3]

ori_img = img_origin_ax.imshow(ast_rgb)
img = img_one_channel_ax.imshow(ast_hsv[..., 0], cmap='gray')
img_origin_ax.axis('off')
img_one_channel_ax.axis('off')
threshold_slider = widgets.Slider(threshold_slider_ax, 'Threshold', 0, 255, valinit=128, valstep=1)
channel_slider = widgets.Slider(channel_slider_ax, 'Channel', 0, 2, valinit=0, valstep=1)

def update(val):
    threshold = threshold_slider.val
    channel = int(channel_slider.val)
    img_one_channel_ax.imshow(ast_hsv[..., channel] > threshold, cmap='gray')
    fig.canvas.draw_idle()

threshold_slider.on_changed(update)
channel_slider.on_changed(update)

plt.show()
Example.mp4

Have you considered any alternative solutions?

No response

@joelostblom
Copy link
Contributor

Thank you for the feature suggestion. I agree that supporting images would be an important improvement, and it is something that needs to be added in VegaLite before it can be added in Altair. I will close this as a duplicate and refer to the following issue to join the discussion of the implementation of image support in Vega-Lite vega/vega-lite#9389

You might also find the discussions in these issues interesting:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants