SlideShare a Scribd company logo
OpenCV-basic
operations
Flipping, rotating, cropping,
resizing & extracting images
Flipping of images
 The flipping operation is done to flip the images in defined orientations.
 The cv2.flip() function is used to flip the images.
 There are two arguments required for this function to work.
 The first argument is the location of the read image.
 The second argument is the type of flipping, this is given by indices.
 0 means flipping around the x-axis (horizontal) axis.
 Any positive value means flipping around the y-axis (vertical) axis.
 Any negative number means flipping around both the axes.
cv2.flip(a,0)
cv2.flip(a,1)
cv2.flip(a,-1)
Rotating images
 The operation of rotation is done by the function called as cv2.rotate().
 There are two arguments required for this function to work.
 The first argument is the variable containing the read image.
 The second argument is the mode.
 There are indices for the modes of rotating an image.
 0- rotating 90 degree clockwise
 1- rotating 180 degree clockwise
 2- rotating 270 degree clockwise
Rotate 90 clockwise
Rotate 180 clockwise
Rotate 270 clockwise
Resizing of images
 The operation of resizing allows us to change the shape and dimensions of an
image.
 This can be done only with the read image or it can be done with the
processed image also.
 The function used for this is the cv2.resize().
 There are two arguments required here.
 The first one is the read image.
 The second one is the desired dimensions.
 It can be given in (height, width) format.
Enlarged image
Diminished image
Cropping of images
 The cropping operation is done to get a particular portion of an image.
 This can be done by altering the height and width of the image.
 The dimensions are to be given in square brackets.
 There are three dimensions in a colour image namely the height, width and
colour channel.
 The , separates the dimensions and the : is used to indicate all values.
 So [:,:,:] refers to the original image.
 In order to crop the image we have to add numbers in between the :s.
Horizontal cropping
 This can be achieved by altering the height of the image. Taking any ranges of
values can result in this type of cropping.
Vertical cropping
 This can be achieved by altering the numbers in the width of the image.
Combined cropping
 This type of cropping is what we do normally in our mobile phones.
 This can be achieved by altering both the height and width of image.
 This image contains the face of the dog cropped from the entire image.
Extracting images
 The process of extraction refers to the extraction of the colour channels from
the given colour image. In other words, every colour image is obtained from
the b, g & r equivalents.
 It is important to note that in OpenCV the indexing for colour channels are
different when compared to others.
 The order here is BGR meaning that blue has index 0, green has index 1 and
red has index 2.
 So the extraction must be done in this particular order.
 Also this process of extraction is applicable for colour images only.
 An error will pop-up if grayscale images are used referring to the
incompatible dimensions.
Blue
 Blue is the first colour channel present in OpenCV.
 First we separate the image into R,G and B using the cv2.split(img) function.
 In order to get the blue image we have keep the values of green and red
channels as zero.
 This is done using numpy where we create an array of specified shape
containing zeroes.
 Then we merge the arrays with that of the split image.
 This is point in which the indexing plays a major role.
 So for blue it is cv2.merge([b,array,array])
Output
Green
 Green is the second colour channel present in OpenCV.
 First we separate the image into R,G and B using the cv2.split(img) function.
 In order to get the green image we have keep the values of blue and red
channels as zero.
 This is done using numpy where we create an array of specified shape
containing zeroes.
 Then we merge the arrays with that of the split image.
 This is point in which the indexing plays a major role.
 So for green it is cv2.merge([array,g,array])
Output
Red
 Red is the last colour channel present in OpenCV.
 First we separate the image into R,G and B using the cv2.split(img) function.
 In order to get the red image we have keep the values of blue and green
channels as zero.
 This is done using numpy where we create an array of specified shape
containing zeroes.
 Then we merge the arrays with that of the split image.
 This is point in which the indexing plays a major role.
 So for red it is cv2.merge([array, array,r])
Output
OpenCV presentation series- part 3

More Related Content

PPTX
OpenCV presentation series- part 2
PPTX
OpenCV presentation series- part 4
PPTX
OpenCV presentation series- part 5
PDF
Local binary pattern
PPTX
5. gray level transformation
PPTX
Introduction to Image Processing with MATLAB
PDF
//STEIM Workshop: A Vernacular of File Formats
PDF
Basics of Image Processing using MATLAB
OpenCV presentation series- part 2
OpenCV presentation series- part 4
OpenCV presentation series- part 5
Local binary pattern
5. gray level transformation
Introduction to Image Processing with MATLAB
//STEIM Workshop: A Vernacular of File Formats
Basics of Image Processing using MATLAB

What's hot (20)

PPTX
Digital image processing
PPTX
Particle filter and cam shift approach for motion detection
PPTX
Image representation
PPTX
Point processing
PPT
Muzammil Abdulrahman PPT On Gabor Wavelet Transform (GWT) Based Facial Expres...
PPTX
Matlab and Image Processing Workshop-SKERG
PPTX
Introductory Digital Image Processing using Matlab, IIT Roorkee
PPTX
Jpeg compression
PPTX
Ec section
PPT
Image enhancement
PDF
Image analysis using python
PPTX
A rank based ensemble classifier for image classification
PPT
Image enhancement
PDF
Image enhancement techniques a review
PPTX
PDF
Digital image processing using matlab: basic transformations, filters and ope...
PPTX
Log Transformation in Image Processing with Example
PPTX
Mathematical operations in image processing
PDF
Contrast enhancement in digital images
PDF
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
Digital image processing
Particle filter and cam shift approach for motion detection
Image representation
Point processing
Muzammil Abdulrahman PPT On Gabor Wavelet Transform (GWT) Based Facial Expres...
Matlab and Image Processing Workshop-SKERG
Introductory Digital Image Processing using Matlab, IIT Roorkee
Jpeg compression
Ec section
Image enhancement
Image analysis using python
A rank based ensemble classifier for image classification
Image enhancement
Image enhancement techniques a review
Digital image processing using matlab: basic transformations, filters and ope...
Log Transformation in Image Processing with Example
Mathematical operations in image processing
Contrast enhancement in digital images
Hybrid Technique for Copy-Move Forgery Detection Using L*A*B* Color Space
Ad

Similar to OpenCV presentation series- part 3 (20)

PDF
Writeup advanced lane_lines_project
PDF
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
PPTX
Image Enhancement - Point Processing
PDF
Practical Digital Image Processing 2
PDF
Lec_2_Digital Image Fundamentals.pdf
PPTX
IMAGE ENHANCEMENT IN THE SPATIAL DOMAIN.pptx
PPTX
Image_processing_unit2_SPPU_Syllabus.pptx
PPTX
Computer vision labs for improving in the subject
PPTX
Digital Image Processing
PPTX
Module 2.pptxwwwwwwwwwwwwwwwwwwwwwwwwwww
PDF
PPTX
Image processing second unit Notes
PPTX
LAPLACE TRANSFORM SUITABILITY FOR IMAGE PROCESSING
PPTX
Dip digital image 3
PPTX
Unit 2. Image Enhancement in Spatial Domain.pptx
PPT
Digital Image through Scanner, Digital Camera. Concept of Gray Levels.
PPTX
Image Processing - Unit II - Image Enhancement discussed
PPTX
Digital Image Processing Unit -2 Notes complete
PPTX
PYTHON-OOOOOOOOOOPPPPPPEEEEEEEEN-CV.pptx
PPT
Image Enhancement in the Spatial Domain U2.ppt
Writeup advanced lane_lines_project
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
Image Enhancement - Point Processing
Practical Digital Image Processing 2
Lec_2_Digital Image Fundamentals.pdf
IMAGE ENHANCEMENT IN THE SPATIAL DOMAIN.pptx
Image_processing_unit2_SPPU_Syllabus.pptx
Computer vision labs for improving in the subject
Digital Image Processing
Module 2.pptxwwwwwwwwwwwwwwwwwwwwwwwwwww
Image processing second unit Notes
LAPLACE TRANSFORM SUITABILITY FOR IMAGE PROCESSING
Dip digital image 3
Unit 2. Image Enhancement in Spatial Domain.pptx
Digital Image through Scanner, Digital Camera. Concept of Gray Levels.
Image Processing - Unit II - Image Enhancement discussed
Digital Image Processing Unit -2 Notes complete
PYTHON-OOOOOOOOOOPPPPPPEEEEEEEEN-CV.pptx
Image Enhancement in the Spatial Domain U2.ppt
Ad

More from Sairam Adithya (8)

PPTX
COUNTERS(Synchronous & Asynchronous)
PPTX
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
PPTX
Medical waste segregation using deep learning
PPTX
OpenCV presentation series- part 1
PPTX
A Brief Introduction to Diabetes Mellitus
PPTX
Detection of medical instruments project- PART 2
PPTX
Detection of medical instruments project- PART 1
PPTX
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX
COUNTERS(Synchronous & Asynchronous)
SEQUENTIAL LOGIC CIRCUITS (FLIP FLOPS AND LATCHES)
Medical waste segregation using deep learning
OpenCV presentation series- part 1
A Brief Introduction to Diabetes Mellitus
Detection of medical instruments project- PART 2
Detection of medical instruments project- PART 1
TASK-OPTIMIZED DEEP NEURAL NETWORK TO REPLICATE THE HUMAN AUDITORY CORTEX

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Institutional Correction lecture only . . .
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Classroom Observation Tools for Teachers
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Basic Mud Logging Guide for educational purpose
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Anesthesia in Laparoscopic Surgery in India
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPH.pptx obstetrics and gynecology in nursing
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Institutional Correction lecture only . . .
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
GDM (1) (1).pptx small presentation for students
Classroom Observation Tools for Teachers

OpenCV presentation series- part 3

  • 2. Flipping of images  The flipping operation is done to flip the images in defined orientations.  The cv2.flip() function is used to flip the images.  There are two arguments required for this function to work.  The first argument is the location of the read image.  The second argument is the type of flipping, this is given by indices.  0 means flipping around the x-axis (horizontal) axis.  Any positive value means flipping around the y-axis (vertical) axis.  Any negative number means flipping around both the axes.
  • 6. Rotating images  The operation of rotation is done by the function called as cv2.rotate().  There are two arguments required for this function to work.  The first argument is the variable containing the read image.  The second argument is the mode.  There are indices for the modes of rotating an image.  0- rotating 90 degree clockwise  1- rotating 180 degree clockwise  2- rotating 270 degree clockwise
  • 10. Resizing of images  The operation of resizing allows us to change the shape and dimensions of an image.  This can be done only with the read image or it can be done with the processed image also.  The function used for this is the cv2.resize().  There are two arguments required here.  The first one is the read image.  The second one is the desired dimensions.  It can be given in (height, width) format.
  • 13. Cropping of images  The cropping operation is done to get a particular portion of an image.  This can be done by altering the height and width of the image.  The dimensions are to be given in square brackets.  There are three dimensions in a colour image namely the height, width and colour channel.  The , separates the dimensions and the : is used to indicate all values.  So [:,:,:] refers to the original image.  In order to crop the image we have to add numbers in between the :s.
  • 14. Horizontal cropping  This can be achieved by altering the height of the image. Taking any ranges of values can result in this type of cropping.
  • 15. Vertical cropping  This can be achieved by altering the numbers in the width of the image.
  • 16. Combined cropping  This type of cropping is what we do normally in our mobile phones.  This can be achieved by altering both the height and width of image.  This image contains the face of the dog cropped from the entire image.
  • 17. Extracting images  The process of extraction refers to the extraction of the colour channels from the given colour image. In other words, every colour image is obtained from the b, g & r equivalents.  It is important to note that in OpenCV the indexing for colour channels are different when compared to others.  The order here is BGR meaning that blue has index 0, green has index 1 and red has index 2.  So the extraction must be done in this particular order.  Also this process of extraction is applicable for colour images only.  An error will pop-up if grayscale images are used referring to the incompatible dimensions.
  • 18. Blue  Blue is the first colour channel present in OpenCV.  First we separate the image into R,G and B using the cv2.split(img) function.  In order to get the blue image we have keep the values of green and red channels as zero.  This is done using numpy where we create an array of specified shape containing zeroes.  Then we merge the arrays with that of the split image.  This is point in which the indexing plays a major role.  So for blue it is cv2.merge([b,array,array])
  • 20. Green  Green is the second colour channel present in OpenCV.  First we separate the image into R,G and B using the cv2.split(img) function.  In order to get the green image we have keep the values of blue and red channels as zero.  This is done using numpy where we create an array of specified shape containing zeroes.  Then we merge the arrays with that of the split image.  This is point in which the indexing plays a major role.  So for green it is cv2.merge([array,g,array])
  • 22. Red  Red is the last colour channel present in OpenCV.  First we separate the image into R,G and B using the cv2.split(img) function.  In order to get the red image we have keep the values of blue and green channels as zero.  This is done using numpy where we create an array of specified shape containing zeroes.  Then we merge the arrays with that of the split image.  This is point in which the indexing plays a major role.  So for red it is cv2.merge([array, array,r])