
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can scikit-learn library be used to get the resolution of an image in Python?
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.
To get the resolution of an image, a built-in function named ‘shape’ is used. After the image is read, the pixel values are stored in the form of an array. This array is nothing but a Numpy array. Once the image is read and converted into an array, the shape function can be called on this image to understand its resolution.
Let us take an example of uploading an image and getting the resolution of the image on console using scikit-learn library −
Example
from skimage import io path = "path to puppy.PNG" img = io.imread(path) print("Image being read") io.imshow(img) print("Image printed on console") print("The image resolution is ") print(img.shape)
Output
Image being read Image printed on console The image resolution is (397, 558, 4)
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.
- The ‘imshow’ function is used to display the image on the console.
- The function ‘shape’ is used to get the resolution of the image.
- The output’s third value shows 4, which means it has 4 channels- R, G, B and alpha values.
- The data is displayed on the console.
- Related Articles
- How can scikit learn library be used to upload and view an image in Python?
- How can scikit learn library be used to preprocess data in Python?
- How can scikit-learn library be used to load data in Python?
- How can scikit-learn be used to convert an image from RGB to grayscale in Python?
- How can data be scaled using scikit-learn library in Python?
- Explain how scikit-learn library can be used to split the dataset for training and testing purposes in Python?
- Explain how L1 Normalization can be implemented using scikit-learn library in Python?
- Explain how L2 Normalization can be implemented using scikit-learn library in Python?
- How to find contours of an image using scikit-learn in Python?
- Explain the basics of scikit-learn library in Python?
- How to view the pixel values of an image using scikit-learn in Python?
- How can scikit-learn package be used to transform an array of specific size to a different size?
- How can a specific tint be added to grayscale images in scikit-learn in Python?
- How to eliminate mean values from feature vector using scikit-learn library in Python?
- Learning Model Building in Scikit-learn: A Python Machine Learning Library
