Scikit-image 简明教程
Scikit Image - Displaying Images
显示 或可视化图像在图像处理和计算机视觉任务中发挥着至关重要的作用。执行图像处理操作(例如裁剪、调整大小、旋转或应用各种滤镜)时,可视化图像非常有必要。
*Displaying * or visualizing images plays a crucial role in image processing and computer vision tasks. It is necessary to visualize images when performing image processing operations such as cropping, resizing, rotating, or applying various filters.
显示图像指的是在屏幕或其他输出设备上可视化或呈现数字图像的过程。它使我们能够以可视化格式查看和解释图像的内容。
Displaying images refers to the process of visualizing or presenting digital images on a screen or other output devices. It allows us to view and interpret the content of images in a visual format.
在 scikit-image 库中, io module 提供了诸如 imshow() and show() 以便在屏幕上显示图像的函数。这些函数可用于显示图像处理操作的结果。
In the scikit-image library, the io module offers functions like imshow() and show() for displaying images on a screen. These functions are useful for displaying the results of image manipulation operations.
Using the io.imshow() method
skimage.io.imshow() 方法用于显示图像。它打开一个窗口并使用指定的或默认图像插件显示图像。下面是该方法的语法和参数 -
The skimage.io.imshow() method is used to display an image. It opens a window and displays the image using the specified or default image plugins. Following is the syntax and parameters of this method −
skimage.io.imshow(arr, plugin=None, **plugin_args)
以下是该函数的参数 -
Following are the parameters of this function −
-
arr − An ndarray or a string representing image data or the name of an image file.
-
plugin − A string specifying the name of the plugin to be used. If not provided, the function will attempt to find a suitable plugin from the available options, starting with "imageio".
-
**plugin_args − Additional keyword arguments that are passed to the chosen plugin.
Example
以下示例将使用默认图像插件显示图像。
The following example will display the image using the default image plugin.
from skimage import io
# Displaying image using the image name
io.imshow('Images/logo-w.png')
运行以上代码将产生以下结果 -
Running the above code gives us the following result −
<matplotlib.image.AxesImage at 0x20980099d30 >
Using the io.show() method
skimage.io.show() 函数用于显示 scikit-image 中未处理的图像。它启动当前 GUI 插件的事件循环,并显示使用 imshow() 函数排队要显示的所有图像。在使用非交互式脚本时,此功能特别有用。以下是该方法的语法 -
The skimage.io.show() function is used to display pending images in scikit-image. It launches the event loop of the current GUI plugin and shows all images that have been queued for display using the imshow() function. This is particularly useful when working with non-interactive scripts. Following is the syntax of this method −
skimage.io.show()
Note, 如果您在交互式环境(例如 Jupyter Notebook 或交互式 Python shell)中工作,则可以使用 imshow() 显示图像。但是,如果您正在运行非交互式脚本,则最好在最后加入 show() 以确保在脚本终止之前显示所有图像。
Note, If you are working in an interactive environment, such as Jupyter Notebook or an interactive Python shell, you can simply use imshow() to display the image. However, if you are running a non-interactive script, it is best to include show() at the end to ensure that all images are displayed before the script terminates.
Example 1
以下示例将使用 imshow() 和 show() 方法显示图像。
The following example will display an image using the imshow() and show() methods.
from skimage import io
# Read the image from an URL
image = io.imread('https://www.tutorialspoint.com/images/logo.png')
# Display an image
io.imshow(image)
io.show()
运行以上代码将产生以下结果 -
Running the above code gives us the following result −
Example 2
以下示例将使用 imshow() 和 show() 方法显示 2 个图像。
The following example will display the 2 images using the imshow() and show() methods.
from skimage import io
import numpy as np
import time
image1 = np.random.randint(0, 256, size=(50, 50, 3), dtype=np.uint8)
image2 = np.random.randint(0, 256, size=(50, 50), dtype=np.uint8)
# Displaying the image1
io.imshow(image1)
io.show()
# Displaying the image2
io.imshow(image2)
io.show()
上述程序生成以下输出 −
The above program generates the following output −
以下是第二张图片 −
Following is the second image −