9. Exploring Image Data With ImShow#
Plotly is a powerful graphing and imagery library widely used for data visualization. Unlike many other libraries, Plotly focuses on creating interactive plots, allowing you to build dynamic visualizations that offer deeper insights into your data.
One essential feature in Plotly for working with image data is the imshow() function. This function enables the visualization of 2D arrays or image-like data, making it a valuable tool for exploring and understanding image datasets. Whether you’re working with scientific images or any form of visual data, Plotly’s interactive capabilities can provide an edge in scientific communication.
In this guide, we’ll explore how to use imshow() to work with image data in Plotly, creating visuals that not only communicate your findings but also enhance your understanding of the data itself.
import plotly.express as px
import numpy as np
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
[[0, 255, 0], [0, 0, 255], [255, 0, 0]]
], dtype=np.uint8)
fig = px.imshow(img_rgb)
fig.show()
import plotly.express as px
from skimage import io
img = io.imread('https://oceancv.org/_images/WormTower.jpg')
fig = px.imshow(img)
#fig.update_layout(coloraxis_showscale=False)
#fig.update_xaxes(showticklabels=False)
#fig.update_yaxes(showticklabels=False)
fig.show()
Credit: UW/NSF-OOI/WHOI; J2-1666, V24.
import plotly.express as px
import plotly.graph_objects as go
from skimage import data
img = io.imread('https://oceancv.org/_images/OctopusCrawling.jpg')
fig = px.imshow(img, color_continuous_scale='gray')
fig.add_trace(go.Contour(z=img, showscale=False,
contours=dict(start=0, end=70, size=70, coloring='lines'),
line_width=2))
fig.add_trace(go.Scatter(x=[230], y=[100], marker=dict(color='red', size=16)))
fig.show()
Credit: UW/NSF-OOI/WHOI; J2-1609; V24.
from plotly.subplots import make_subplots
from skimage import data
img = io.imread('https://oceancv.org/_images/SeapigParty.jpg')
fig = make_subplots(1, 2)
fig.add_trace(go.Image(z=img), 1, 1)
for channel, color in enumerate(['red', 'green', 'blue']):
fig.add_trace(go.Histogram(x=img[..., channel].ravel(), opacity=0.5,
marker_color=color, name='%s channel' %color), 1, 2)
fig.update_layout(height=400)
fig.show()