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

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.

Stock Price Prediction Project using LSTM and RNN
Learn how to predict stock prices using RNN and LSTM models. Understand deep learning concepts and apply them to real-world financial data for accurate forecasting.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Langchain Project for Customer Support App in Python
In this LLM Project, you will learn how to enhance customer support interactions through Large Language Models (LLMs), enabling intelligent, context-aware responses. This Langchain project aims to seamlessly integrate LLM technology with databases, PDF knowledge bases, and audio processing agents to create a comprehensive customer support application.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Recommender System Machine Learning Project for Beginners-4
Collaborative Filtering Recommender System Project - Comparison of different model based and memory based methods to build recommendation system using collaborative filtering.

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Build a Credit Default Risk Prediction Model with LightGBM
In this Machine Learning Project, you will build a classification model for default prediction with LightGBM.