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.

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

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')

Output

Running the above code gives us the following result −

<matplotlib.image.AxesImage at 0x20980099d30 >
Dispaly Images

Using the io.show() method

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, 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

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()

Output

Running the above code gives us the following result −

Dispaly Images

Example 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()

Output

The above program generates the following output −

Dispaly Images

Following is the second image −

Dispaly Images
Advertisements