Images  Camera models  Digital images  Colour images  Noise  Smoothing Images Based on A Practical Introduction to Computer Vision with OpenCV by.

Slides:



Advertisements
Similar presentations
Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
Advertisements

3-D Computer Vision CSc83020 / Ioannis Stamos  Revisit filtering (Gaussian and Median)  Introduction to edge detection 3-D Computater Vision CSc
Spatial Filtering (Chapter 3)
Image Processing Lecture 4
Chapter 3 Image Enhancement in the Spatial Domain.
Histograms 1D Histograms 3D Histograms Equalisation
Sliding Window Filters and Edge Detection Longin Jan Latecki Computer Graphics and Image Processing CIS 601 – Fall 2004.
EE4H, M.Sc Computer Vision Dr. Mike Spann
Image Processing IB Paper 8 – Part A Ognjen Arandjelović Ognjen Arandjelović
E.G.M. PetrakisFiltering1 Linear Systems Many image processing (filtering) operations are modeled as a linear system Linear System δ(x,y) h(x,y)
Digital Image Processing In The Name Of God Digital Image Processing Lecture3: Image enhancement M. Ghelich Oghli By: M. Ghelich Oghli
Color spaces CIE - RGB space. HSV - space. CIE - XYZ space.
COLORCOLOR A SET OF CODES GENERATED BY THE BRAİN How do you quantify? How do you use?
Color Image Processing
Light Light is fundamental for color vision Unless there is a source of light, there is nothing to see! What do we see? We do not see objects, but the.
School of Computing Science Simon Fraser University
Image Filtering CS485/685 Computer Vision Prof. George Bebis.
1 Color Segmentation: Color Spaces and Illumination Mohan Sridharan University of Birmingham
MSU CSE 803 Stockman Linear Operations Using Masks Masks are patterns used to define the weights used in averaging the neighbors of a pixel to compute.
Lecture 2: Image filtering
Images and colour Colour - colours - colour spaces - colour models Raster data - image representations - single and multi-band (multi-channel) images -
MSU CSE 803 Linear Operations Using Masks Masks are patterns used to define the weights used in averaging the neighbors of a pixel to compute some result.
1 CSCE441: Computer Graphics: Color Models Jinxiang Chai.
Most slides from Steve Seitz
Colour Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman
Introduction to Image Processing Grass Sky Tree ? ? Review.
Chapter 2. Image Analysis. Image Analysis Domains Frequency Domain Spatial Domain.
Presentation Image Filters
Machine Vision ENT 273 Image Filters Hema C.R. Lecture 5.
1 Color Processing Introduction Color models Color image processing.
Image Formation. Input - Digital Images Intensity Images – encoding of light intensity Range Images – encoding of shape and distance They are both a 2-D.
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
Computer Science 631 Lecture 7: Colorspace, local operations
Simple Image Processing Speaker : Lin Hsiu-Ting Date : 2005 / 04 / 27.
Binary Thresholding Threshold detection Variations
Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T Computer Vision Tahun: 2010.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Chapter 2: Color Basics. 2 What is light?  EM wave, radiation  Visible light has a spectrum wavelength from 400 – 780 nm.  Light can be composed.
AdeptSight Image Processing Tools Lee Haney January 21, 2010.
Image processing Fourth lecture Image Restoration Image Restoration: Image restoration methods are used to improve the appearance of an image.
Digital Image Processing Part 1 Introduction. The eye.
Digital Image Processing Lecture 10: Image Restoration March 28, 2005 Prof. Charlene Tsai.
Chapter 5: Neighborhood Processing
Linear filtering. Motivation: Noise reduction Given a camera and a still scene, how can you reduce noise? Take lots of images and average them! What’s.
Machine Vision ENT 273 Image Filters Hema C.R. Lecture 5.
Digital Image Processing Lecture 10: Image Restoration
CS6825: Color 2 Light and Color Light is electromagnetic radiation Light is electromagnetic radiation Visible light: nm. range Visible light:
Course 2 Image Filtering. Image filtering is often required prior any other vision processes to remove image noise, overcome image corruption and change.
DIGITAL IMAGE. Basic Image Concepts An image is a spatial representation of an object An image can be thought of as a function with resulting values of.
Intelligent Vision Systems ENT 496 Image Filtering and Enhancement Hema C.R. Lecture 4.
Visual Computing Computer Vision 2 INFO410 & INFO350 S2 2015
Non-linear Filters Non-linear filter (nelineární filtr) –spatial non-linear operator that produces the output image array g(x,y) from the input image array.
CSE 6367 Computer Vision Image Operations and Filtering “You cannot teach a man anything, you can only help him find it within himself.” ― Galileo GalileiGalileo.
Sliding Window Filters Longin Jan Latecki October 9, 2002.
Computer Graphics: Achromatic and Coloured Light.
CSE 185 Introduction to Computer Vision
Image Enhancement in the Spatial Domain.
Color Models Light property Color models.
Miguel Tavares Coimbra
Color Image Processing
Digital Image Processing Lecture 10: Image Restoration
Digital 2D Image Basic Masaki Hayashi
Image Processing - in short
Image Enhancement in the Spatial Domain
Digital Image Processing Week IV
Linear Operations Using Masks
Magnetic Resonance Imaging
Lecture 2: Image filtering
DIGITAL IMAGE PROCESSING Elective 3 (5th Sem.)
Presentation transcript:

Images  Camera models  Digital images  Colour images  Noise  Smoothing Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc. 2014Slide 1

Camera models Components: A photosensitive image plane A housing A lenses Mathematical model needed The simple pinhole camera model Distortions Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 2

Camera models – Simple Pinhole Model Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 3

Camera models – Simple Pinhole Model 3-D point 2-D image point Scaling factor Combination of focal length and image coordinate system Location of the optical centre Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 4

Digital Images Theoretically images are continuous 2D functions of reflected scene brightness. (i, j) or (column, row) or (x, y) To process on a computer we need a discrete representation Sample Quantise Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 5

Digital Images – Sampling Sample the continuous 2D function into discrete elements. Sensor 2D array Photosensitive elements Non photosensitive gaps Issues Elements have a fixed area Gaps Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 6

Digital Images – Sampling How many samples do we need ? Wasted space and computation time Enough for the objects of interest Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 7 Mat image, smaller_image; resize( image, smaller_image, Size( image1.cols/2, image.rows/2 ));

Digital Images – Quantisation Represent the individual image points as digital values. Typically 8 bits Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 8

Digital Images – Quantisation How many bits do we need ? Wasted space ? Losing the ability to distinguish objects Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 9 void ChangeQuantisationGrey( Mat &image, int num_bits ) { CV_Assert( (image.type() == CV_8UC1) && (num_bits >= 1) && (num_bits <= 8) ); uchar mask = 0xFF << (8-num_bits); for (int row=0; row < image.rows; row++) for (int col=0; col < image.cols; col++) image.at (row,col) = image.at (row,col) & mask; }

Colour Images Luminance only Simple representation Humans can understand Colour images ( luminance + chrominance ) Multiple channels (typically 3) Around 16.8 million colours More complex to process Facilitate certain operations Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 10

Colour Images – Processing Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 11 void InvertColour( Mat& input_image, Mat& output_image ) { CV_Assert( input_image.type() == CV_8UC3 );` output_image = input_image.clone(); for (int row=0; row < input_image.rows; row++) for (int col=0; col < input_image.cols; col++) for (int channel=0; channel < input_image.channels(); channel++) output_image.at (row,col)[channel] = 255 – input_image.at (row,col)[channel]; }

Colour Images – Efficient processing Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 12 int image_rows = image.rows; int image_columns = image.cols; for (int row=0; row < image_rows; row++) { uchar* value = image.ptr (row); uchar* result_value = result_image.ptr (row); for (int column=0; column < image_columns; column++) { *result_value++ = *value++ ^ 0xFF; }

Colour Images – RGB Images Red-Green-Blue images Most common Channels correspond roughly to Red (700nm) Green (546nm) Blue (436nm) Colours combined in display Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 13

Colour Images – RGB Images Converting to Greyscale Y = 0.299R G B Camera photosensitive elements Separate Red, Green & Blue elements Sometimes sensitive to all visible wavelengths Bayer pattern: Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 14

Colour Images – RGB Images Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 15 Mat bgr_image, grey_image; cvtColor(bgr_image, grey_image, CV_BGR2GRAY); vector bgr_images(3); split(bgr_image, bgr_images); Mat& blue_image = bgr_images[0];

Colour Images – CMY Images Cyan-Magenta-Yellow images Secondary colours Subtractive colour scheme C = 255 – R M = 255 – G Y = 255 – B Often used in printers Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 16 CMY is not directly supported in OpenCV.

Colour Images – YUV Images Used for analogue television signals PAL, NTSC 4 Y to 1 U to 1 V Conversion from RGB Y = 0.299R G B U = * (B-Y) V = * (R-Y) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 17

Colour Images – HLS Images Hue-Luminance-Saturation images Separates Luminance & Chrominance Values we humans can relate to… Hue 0 o..360 o Luminance 0..1 Saturation 0..1 Watch out for circular Hue… Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 18

Colour Images – HLS Images Conversion from RGB Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 19 cvtColor(bgr_image, hls_image, CV_BGR2HLS); // Hue ranges from 0 to 179.

Colour Images – Other colour spaces HSV YCrCb CIE XYZ CIE L*u*v* CIE L*a*b* Bayer Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 20

Colour Images – Skin detection (S >= 0.2) AND (0.5 < L/S <3.0) AND (H = 330 o ) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 21 uchar H = hls_image.at (row,col)[0]; uchar L = hls_image.at (row,col)[1]; uchar S = hls_image.at (row,col)[2]; double LS_ratio = ((double) L) / ((double) S); bool skin_pixel = (S >= 50) && (LS_ratio > 0.5) && (LS_ratio = 165));

Colour Images – Red eye detection (L >= 0.25) AND (S >= 0.4) AND (0.5 < L/S <1.5) AND (H = 324 o ) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 22 uchar H = hls_image.at (row,col)[0]; uchar L = hls_image.at (row,col)[1]; uchar S = hls_image.at (row,col)[2]; double LS_ratio = ((double) L) / ((double) S); bool skin_pixel = (L >= 64) && (S >= 100) && (LS_ratio > 0.5) && (LS_ratio < 1.5) && ((H = 162));

Noise Affects most images Degrades the image Can cause problems with processing Causes? Measuring noise: Correcting noise… Types Gaussian Salt and Pepper Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 23

Noise - Models Additive noise f(i,j) = g(i,j) + v(i,j) Multiplicative noise f(i,j) = g(i,j) + g(i,j).v(i,j) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 24

Noise – Salt and Pepper Noise Impulse noise Noise is maximum or minimum values Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 25

Noise – Salt and Pepper Noise Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 26 int noise_points = (int) (((double) image_rows* image.cols*image.channels())*noise_percentage/100.0); for (int count = 0; count < noise_points; count++) { int row = rand() % image.rows; int column = rand() % image.cols; int channel = rand() % image.channels(); uchar* pixel = image.ptr (row) + (column*image.channels()) + channel; *pixel = (rand()%2 == 1) ? 255 : 0; }

Noise – Gaussian Noise Good approximation to real noise Distribution is Gaussian (mean & s.d.) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 27

Noise – Gaussian Noise Generation Select value for σ Determine distribution -(i) 2 p(i) = 1.e 2σ 2 i = -(G-1),..,-1,0,1,…,G-1 σ  2  P cum (-(G-1)) = p(-(G-1)) P cum (i) = P cum (i-1) + p(i) For every pixel (x,y) f*(x,y) = g(x,y) + argmin i (abs( rand() - P cum [i] )) Set f(x,y) = 0 if f*(x,y) < 0 f(x,y) = G-1 if f*(x,y) > G-1 f(x,y) = f*(x,y) otherwise Truncation attenuates Gaussian nature of noise Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 28

Noise – Gaussian Noise Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 29 Mat noise_image(image.size(), CV_16SC3); randn(noise_image, Scalar::all(average), Scalar::all(standard_deviation)); Mat temp_image; image.convertTo(temp_image,CV_16SC3); addWeighted(temp_image, 1.0, noise_image, 1.0, 0.0, temp_image); temp_image.convertTo(image,image.type());

Smoothing Removing or reducing noise… Linear smoothing transformations Image Averaging Local Averaging Gaussian Smoothing Non-linear transformations Rotating Mask Median Filter Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 30

Smoothing – Image Averaging (linear) Average of n images f(i,j) = (1/ n). Σ (g k (i,j) + v k (i,j)) k = 1..,n Additive noise model v k (i,j) St. Dev. = σ /  n Assumptions? Static Statistical independence Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 31 addWeighted(image1,0.5,image2,0.5,0.0,average_image);

Smoothing – Image Averaging Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 32

Smoothing – Convolution Filtering / Convolution Linear transformation: f( i,j ) = Σ Σ h( i-m, j-n ).g( m,n ) (m,n)  Ο Convolution mask Non-linear transformation: Some logical operation based on a local region Smoothing Suppression of image noise Blurring sharp edges Large degradations? Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 33

Smoothing – Averaging Filters (linear) Available images? Local neighbourhood f( i,j ) = Σ Σ h( i-m, j-n ).g( m,n ) (m,n)  Ο Different masks… Local Average Gaussian Acceptable results? Size of noise Blurring of edges Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 34 blur(image,smoothed_image,Size(3,3)); GaussianBlur(image,smoothed_image,Size(5,5),1.5);

Smoothing – Examples Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 35

Smoothing – Rotating Mask (non-linear) Define a number of masks/regions Mask size & shape Alternatives: Use the average of one of the masks But which mask?? The most homogeneous Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 36

Smoothing – Rotating Mask (non-linear) Algorithm: For each image point (i,j) Calculate dispersions Assign output point average of mask with minimum dispersion Iterative application Convergence Effects of mask size Effects Noise suppression Image sharpening Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 37

Smoothing – Rotating Mask (non-linear) Dispersion σ 2 Lower computational complexity… Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 38

Smoothing – Median Filter (non-linear) Use the median value… Not affected by noise Doesn’t blur edges much Can be applied iteratively Damages thin lines and sharp corners Change region shape Computational expensive Standard – O(r 2 log r) Huang – O(r) Perreault (2007) – O(1) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide Median = 23 Average = 47 medianBlur(image, smoothed_image, 5);

Smoothing – Median Filter (Huang O(r)) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 40 Input image X (m * n), kernel radius k, Output image Y for row = 1 to m Initialise histogram H: X(-k, row-k).. X(k, row+k) for column = 1 to n Y(column, row) = Median of H Remove leftmost column from H: X(column-k, row-k).. X(column-k, row+k) Add new column to right of H: X(column+k+1, row-k).. X(column+k+1, row+k) Can determine median efficiently by maintaining and updating: - Median value - Number of points less than the median

Smoothing – Median Filter (Perreault O(1)) Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 41 Input image X (m * n), kernel radius k, Output image Y for row = 1 to m Initialise column histograms h 1..n and histogram H for column = 1 to n Y(column, row) = Median of H Remove X(column+k+1, row-k-1) from h column+k+1 Add X(column+k+1, row+k) from h column+k+1 Remove leftmost column from H: h column-k Add new column to right of H: h column+k+1

Smoothing – Examples Images Based on A Practical Introduction to Computer Vision with OpenCV by Kenneth Dawson-Howe © Wiley & Sons Inc Slide 42