Scikit-image 简明教程

Scikit Image - Using Plotly

Plotly 在 Python 中通常称为“plotly.py”。它是一个免费且开源的绘图库,建立在“plotly.js”之上。Plotly.py 提供了丰富的特性集并支持 40 多种独特的图表类型。它广泛用于财务分析、地理制图、科学可视化、3D 绘图以及数据分析应用程序。

它提供了一个交互式界面,允许用户探索和与数据可视化进行交互。它提供诸如缩放、平移、工具提示和悬停效果等功能,轻松分析和理解复杂的数据集。

Scikit Image Using Plotly

Plotly.py 可以与 scikit-image 库一起使用来执行与图像处理相关的各种数据可视化任务。要设置 plotly,您需要确保安装该库并对其进行正确配置。

Installing plotly using pip

在命令提示符中执行以下命令以安装 plotly 模块。这是一个从 PyPi 安装 Plotly 最新包的简单方式。

pip install plotly

Installing plotly using conda

如果您已经在系统中使用了 Anaconda 发行版,那么您可以直接使用 conda 包管理器来安装 plotly。

conda install -c plotly plotly

一旦安装了 Plotly,您可以使用以下语句将其导入到您的 Python 脚本或交互式会话中 −

import plotly

这从 Plotly 导入必要的模块以创建交互式且可自定义的可视化。以下是几个基本的 Python 程序,展示了如何将 Plotly 与 scikit-image 一起使用,以有效地在图像处理任务中执行数据可视化。

Example 1

以下示例使用 *Plotly.express.imshow() * 方法显示一个 RBG 图像。

import plotly.express as px
from skimage import io

# Read an image
image = io.imread('Images/Tajmahal.jpg')
# Display the image using Plotly
fig = px.imshow(image)
fig.show()

执行上述程序时,你将得到以下输出:

plotly 1

Example 2

以下示例演示了如何使用 scikit-image 将圆形蒙版应用到图像上,并使用 Plotly 并排显示原始图像和有蒙版的图像。

import matplotlib.pyplot as plt
from skimage import io
import numpy as np

# Load the image
image_path = 'Images_/Zoo.jpg'
image = io.imread(image_path)
image_copy = np.copy(image)

# Create circular mask
rows, cols, _ = image.shape
row, col = np.ogrid[:rows, :cols]
center_row, center_col = rows / 2, cols / 2
radius = min(rows, cols) / 2
outer_disk_mask = ((row - center_row)**2 + (col - center_col)**2 > radius**2)

# Apply mask to image
image[outer_disk_mask] = 0

# Display the original and masked images using Matplotlib
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 5))
axes[0].imshow(image_copy)
axes[0].set_title('Original Image')
axes[0].axis('off')
axes[1].imshow(image)
axes[1].set_title('Masked Image')
axes[1].axis('off')
plt.tight_layout()
plt.show()
plotly 2