How to find the shape size and data type of an image using OpenCV

This recipe helps you find the shape size and data type of an image using OpenCV

Recipe Objective: How to find the shape, size, and data type of an image using OpenCV?

In this recipe, let us see how to find the shape, size, and data type of an image

Access YOLO OCR Character Recognition Project with Source Code

Step 1: Import the libraries and read the images

Let us first import the OpenCV library and read an image. The image that we are using here is as follows.

Project Pro Logo
import cv2
image = cv2.imread('project.jpg')

Step 2: Finding the shape of the image

We can easily find the shape of the image using the .shape function as given below

print("The shape of the image is",image.shape)

Output:

The shape of the image is (110, 335, 3)

Here, 110, 335, and 3 are the height, width, and the number of channels, respectively

Step 3: Finding the size of an image

The size of an image can be found using the .size function

print("The size of the image is",image.size)

Output:

The size of the image is 110550

110550 represents that there are 110550 pixels in that image

Step 4: Finding the data type of an image

The data type of each pixel value can be easily found using the .dtype function

print("The data type of the image is",image.dtype)

Output:

The data type of the image is uint8

Here, uint8 represents that each pixel value is an Unsigned Integer of 8 bits. This data type contains all the whole numbers lying between 0 to 255

Download Materials

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

AWS MLOps Project to Deploy Multiple Linear Regression Model
Build and Deploy a Multiple Linear Regression Model in Python on AWS

End-to-End ML Model Monitoring using Airflow and Docker
In this MLOps Project, you will learn to build an end to end pipeline to monitor any changes in the predictive power of model or degradation of data.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Build an End-to-End AWS SageMaker Classification Model
MLOps on AWS SageMaker -Learn to Build an End-to-End Classification Model on SageMaker to predict a patient’s cause of death.

Mastering A/B Testing: A Practical Guide for Production
In this A/B Testing for Machine Learning Project, you will gain hands-on experience in conducting A/B tests, analyzing statistical significance, and understanding the challenges of building a solution for A/B testing in a production environment.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.