Scikit-image 简明教程
Scikit Image - Using Plotly
Plotly 在 Python 中通常称为“plotly.py”。它是一个免费且开源的绘图库,建立在“plotly.js”之上。Plotly.py 提供了丰富的特性集并支持 40 多种独特的图表类型。它广泛用于财务分析、地理制图、科学可视化、3D 绘图以及数据分析应用程序。
Plotly in Python is commonly referred to as "plotly.py". It is a free and open-source plotting library built on top of "plotly.js". Plotly.py provides a rich set of features and supports more than 40 unique chart types. It is widely used for financial analysis, geographical mapping, scientific visualization, 3D plotting, and data analysis applications.
它提供了一个交互式界面,允许用户探索和与数据可视化进行交互。它提供诸如缩放、平移、工具提示和悬停效果等功能,轻松分析和理解复杂的数据集。
It offers an interactive interface that allows users to explore and interact with data visualizations. It provides functionalities like zooming, panning, tooltips, and hover effects, making it easy to analyse and understand complex datasets.
Scikit Image Using Plotly
Plotly.py 可以与 scikit-image 库一起使用来执行与图像处理相关的各种数据可视化任务。要设置 plotly,您需要确保安装该库并对其进行正确配置。
Plotly.py can be used along with the scikit-image library to achieve various data visualization tasks related to image processing. To set up plotly, you need to ensure that the library is installed and properly configured.
Installing plotly using pip
在命令提示符中执行以下命令以安装 plotly 模块。这是一个从 PyPi 安装 Plotly 最新包的简单方式。
Execute the below commands in the command prompt to install the plotly module. It is an easy way to install the latest package of Plotly from PyPi.
pip install plotly
Installing plotly using conda
如果您已经在系统中使用了 Anaconda 发行版,那么您可以直接使用 conda 包管理器来安装 plotly。
If you’re using the Anaconda distribution already in your system, then you can directly use the conda package manager to install plotly.
conda install -c plotly plotly
一旦安装了 Plotly,您可以使用以下语句将其导入到您的 Python 脚本或交互式会话中 −
Once Plotly is installed, you can import it into your Python scripts or interactive sessions using the following statement −
import plotly
这从 Plotly 导入必要的模块以创建交互式且可自定义的可视化。以下是几个基本的 Python 程序,展示了如何将 Plotly 与 scikit-image 一起使用,以有效地在图像处理任务中执行数据可视化。
This imports the necessary modules from Plotly to create interactive and customizable visualizations. Below are a few basic Python programs that demonstrate how to use the Plotly along with scikit-image to perform data visualization in image processing tasks effectively.
Example 1
以下示例使用 *Plotly.express.imshow() * 方法显示一个 RBG 图像。
The following example displays an RBG image using the *Plotly.express.imshow() * method.
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()
执行上述程序时,你将得到以下输出:
On executing the above program, you will get the following output −
Example 2
以下示例演示了如何使用 scikit-image 将圆形蒙版应用到图像上,并使用 Plotly 并排显示原始图像和有蒙版的图像。
The following example demonstrates how to apply a circular mask to an image using scikit-image and display the original image and the masked image side by side using 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()