Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Computer VisionImage geometry and implementation
Juan Irving Vasquez
Consejo Nacional de Ciencia y Tecnologıa
5 de febrero de 2020
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 1 / 29
Image geometry
The pinhole model
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 2 / 29
Image geometry
There are two parts of the image formation:
Geometry. Determines where in the image plane a point of the realworld will be shown.Intensity of light. Determines the amount of brightness that a point inthe image will have.
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 3 / 29
Image geometry (inverted)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 4 / 29
Image geometry
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 5 / 29
Image geometry
Let us write,f
z=
r ′
r
x ′
x=
y ′
y=
r ′
r
Prove that (activity),
x ′ =f
zx
y ′ =f
zy
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 6 / 29
What is an image?
A function.f (x , y) : R2 → R (1)
But computers are not so capable, then
I (i , j) : [a, b]× [c , d ]→ [min,max ] (2)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 7 / 29
What is an image?
A function.f (x , y) : R2 → R (1)
But computers are not so capable, then
I (i , j) : [a, b]× [c , d ]→ [min,max ] (2)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 7 / 29
Samplig and quantization
A discrete image
I (i , j) : [a, b]× [c , d ]→ [min,max ]
Samplig. The amount of pixels in the image.e.g. 640× 480 pixels
Quantization. The possibles values for each pixel.e.g. binary, 8 bits, or float (HDRI)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 8 / 29
Implementation
Figura: Gray scale imageJ. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 9 / 29
Color images
A vector valued function or ”stacked”
f (x , y) =
r(x , y)g(x , y)b(x , y)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 10 / 29
Implementation
Figura: Color imageJ. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 11 / 29
OpenCV
OpenCV
The Open Source Computer Vision Library is an open source computervision and machine learning software library.
Provides a common infrastructure for computer vision application
Accelerates the use of machine perception in the commercial products
BSD-licensed product
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 12 / 29
Implementation
Create an image (matrix).
Mat a= Mat ( S i z e ( 5 , 5 ) , CV 32F ) ;
Data types
CV 8UC1CV 8UC3CV 8UC4CV 32FC1CV 32FC3CV 32FC4
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 13 / 29
Data types
(Check by yourself)
Mat
Vec
Scalar
Point
Size
Rect
RotatedRect
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 14 / 29
Lets go to code!!
Repository:
OpenCV Exampleshttps://github.com/irvingvasquez/vision_programas.git
Primer programa: leer y mostrar una imagen.
01_operaciones_basicas.ipynb
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 15 / 29
Basic operations
Addition, C = A + Bci ,j = ai ,j + bi ,j (3)
Substraction, C = A− B
ci ,j = ai ,j − bi ,j (4)
Multiplication, C = AB. If A is an m × n matrix and B is an n × pmatrix,
ci ,j =n∑
k=1
ai ,kbk,j (5)
Element-wise multiplication
ci ,j = ai ,jbi ,j (6)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 16 / 29
Suma
Programa 03
Mat ImGray= imread ( ” . . / l e n a . j p g ” , 0 ) ;Mat ImGray2 = imread ( ” . . / monkey . j p g ” , 0 ) ;
Mat sum = Mat ( ImGray . s i z e ( ) , t y p e ) ;sum = ImGray + ImGray2 ;
imshow (”Suma” , sum ) ;
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 17 / 29
Addition
Figura: Addition. Is this ok?
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 18 / 29
Suma (Weighted)
Programa 04
Mat ImGray= imread ( ” . . / l e n a . j p g ” , 0 ) ;Mat ImGray2 = imread ( ” . . / monkey . j p g ” , 0 ) ;
Mat sum = Mat ( ImGray . s i z e ( ) , t y p e ) ;
f l o a t a l p h a = 0 . 5 ;sum = a l p h a ∗ ImGray + (1− a l p h a ) ∗ ImGray2 ;
imshow (” wighted sum ” , sum ) ;
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 19 / 29
Suma (Weighted)
Figura:J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 20 / 29
Region of Interest
A ROI allow us to work with certain parts of an image.
Figura: Regions of interest.
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 21 / 29
Crop an image
// Read imagesMat ImGray= imread ( ” . . / l e n a . j p g ” , 0 ) ;Mat ImCropped ;
// x , yRect window ( 0 , 0 , ImGray . c o l s , 0 . 5∗ ImGray . rows ) ;
ImCropped = ImGray ( window ) ;
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 22 / 29
Histograma
Muestra la frecuencia con la que aparece cada valor.
Una funcionf (i)
que cuenta cuantos pixeles tienen igual intensidad o en el intervalo i .
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 23 / 29
Histogram
Figura: Red channel’s histogram
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 24 / 29
Histogramas
Histograma normalizado
g(i) = f (i)/m
Histograma acumulado
g(i) =i∑
j=1
f (i)
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 25 / 29
Histogram Modification
Histogram equalization.
Defines a mapping of gray levels p into gray levels q such that thedistribution of gray levels q is uniform.
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 26 / 29
Equalizacion de histograma
Mapping
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 27 / 29
Equalizacion de histograma
Mapping
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 28 / 29
Miniproject 1
Read this paper:BENDIG, Juliane, et al. Combining UAV-based plant height from crop surface
models, visible, and near infrared vegetation indices for biomass monitoring in
barley. International Journal of Applied Earth Observation and Geoinformation,
2015, vol. 39, p. 79-87.
Download this imagehttps://jivg.org/2016/10/05/mapa-del-campo-escom/
Compute the following idices:
GRVIMGRVI or RGBVI
Display your results
J. Irving Vasquez (jivg.org) Computer Vision 5 de febrero de 2020 29 / 29