# How can scikit learn library be used to upload and view an image in Python?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Pre-processing data refers to cleaning of data, removing invalid data, noise, replacing data with relevant values and so on. This doesn’t always mean text data; it could also be images or video processing as well.

Data pre-processing basically refers to the task of gathering all the data (which is collected from various resources or a single resource) into a common format or into uniform datasets (depending on the type of data). Since real-world data is never ideal, there is a possibility that the data would have missing cells, errors, outliers, discrepancies in columns, and much more.

Sometimes, images may not be correctly aligned, or may not be clear or may have a very large size. The goal of pre-processing is to remove these discrepancies and errors.

Let us take the example of uploading an image and viewing it on console using scikit-learn library −

## Example

from skimage import io
path = "path to puppy.PNG"
io.imshow(img)
print("Image printed on console")

## Explanation

• The required libraries are imported.
• The path where the image is stored is defined.
• The ‘imread’ function is used to visit the path and read the image.
• After the image is read, the pixel values are stored in the form of an array.
• This array is nothing but a Numpy array.
• The image is read and converted into an array.
• The ‘imshow’ function is used to display the image on the console.
• The data is displayed on the console.
Updated on 11-Dec-2020 11:30:33