Docsity

Computer Vision 1 Summary, Appunti di Elaborazione digitale delle immagini

Toggle sidebar
bg1
Contents
1 Computer vision: inverse problem 4
2 Cameras: pinhole camera 5
2.1 Projection properties . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Coordinate system . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Perspective projection . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Single-view geometry (One camera) . . . . . . . . . . . . . . . 8
2.4.1 Extrinsic.......................... 8
2.4.2 Intrinsic .......................... 9
2.5 Ortographic Projection . . . . . . . . . . . . . . . . . . . . . . 10
2.6 Camera calibration: Projection matrix from correspondences . 11
2.6.1 Homogeneous least squares/SVD . . . . . . . . . . . . 12
2.6.2 RQ-Decomposition . . . . . . . . . . . . . . . . . . . . 13
2.7 Real camera: thin lens formula . . . . . . . . . . . . . . . . . 14
2.7.1 Artifacts.......................... 15
2.8 CCDvsCMOS .......................... 16
2.9 Color................................ 17
3 Image processing/Filter 18
3.1 Linearfilter ............................ 19
3.1.1 Averagefilter ....................... 20
3.1.2 Gaussianfilter....................... 20
3.2 Non-linearfilter.......................... 21
3.3 Binaryimages........................... 21
3.4 ImagePyramids.......................... 22
3.5 Edgedetection .......................... 23
3.5.1 Non-maximum suppression . . . . . . . . . . . . . . . . 24
3.5.2 Hysteresis ......................... 24
3.5.3 Canny Edge Detector . . . . . . . . . . . . . . . . . . . 24
3.5.4 Second derivate: Laplacian . . . . . . . . . . . . . . . . 25
3.5.5 Laplacian Pyramid . . . . . . . . . . . . . . . . . . . . 25
3.6 ................................... 26
3.7 ................................... 26
3.8 ................................... 26
3.9 ................................... 26
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d

Anteprima parziale del testo

Scarica Computer Vision 1 Summary e più Appunti in PDF di Elaborazione digitale delle immagini solo su Docsity!

Contents

1 Computer vision: inverse problem

Computer vision is developing computational models and algorithms to in- terpret digital images and understand the visual world we live in. Computer vision is being used today in a wide variety of real-world applications, which include: Optical character recognition (OCR), Medical imaging, Self driving vehicles, Face detection. Why is computer vision potentially interesting? For a number of rea- sons. One is because it’s a challenging problem that’s far from being solved. Another reason can be because it combines many different disciplines: math- ematics, statistics, cognition, engineering (signal processing) and then, of course, computer science. In a computer vision setup, we need a formal model, that describes our problem so that we can, at some point, write down an algorithm. When I talk about algorithm, then I don’t just mean algorithm, what I really mean is mathematical model and algorithm. Because an algorithm alone is not sufficient, because if for example we a new problem comes around, then we can’t use our algorithm. If we have an understanding and a mathematical model, then we can adapt that mathematical model, derive a new algorithm based on it, and then solve a new problem. What we’re going to do is both computational and mathematical, so that means we will write down a for- mula, and we will also talk about an algorithm to implement this formula.

Inverse problem: we usually go from a model of the world to a picture, while in computer vision we try to do the opposite, from images to the world. And there are many possible interpretations of that image data and we need basically to find the right one. We need to first understand something about the geometry and the physics of the world and then write down a mathe- matical model of it. We will also need to write a mathematical model of prior knowledge and a computation model and algorithm to then turn this mathematical model into something useful, to infer the state of the world.

2 Cameras: pinhole camera

We start with images in computer vision, and we know that they come from cameras.The term camera actually comes from the phrase ”camera obscura”, meaning dark room, from Mozi, more than 1000 years ago. Then, Da Vinci described Camera obscura as: when images of illuminated objects penetrate through a small hole in a very dark room, you will see, on the opposite wall, these objects in their proper form and color, reduced in size, in a reverse position (upside-down).

If we take a picture of a tree, for example, and put a camera in front of it. What we need to do is basically make sure that we don’t have informa- tion from two different places, hit the sensor in the same location. The way to fix this is to use a pinhole (or aperture), basically a barrier so that only light in one specific direction passes through the barrier. To be exact, the pinhole has a finite size that means that the lights going through a small so called pencil of rays. The bigger the hole is, the fuzzier the image will get.

Why is the pinhole camera good? It turns out that it’s a good model for pretty much any common sensor that we have: even human eye is approx- imately a pinhole camera, but also other imaging sensors, such as X ray machines, can be, in some sense, described by a pinhole camera.

2.2 Coordinate system

Assume that we basically have an object or a point P in the world we have the origin of the coordinate system (O) and which we define to coincide with the pinhole, what we call O which is also stands for optical center. A point P in the world gets projected to a point P’ on the image plane, and the image plane has some distance f’ (from optical center) that we call focal length. When know also that the Z axis points towards the image plane. Then we can say that the ratio of x to x’ is the same, as the ratio of z to f’. From that we can get the projected points x’ and y’ as:

x′^ = f ′^ ·

x z

y′^ = f ′^ ·

y z

The problem is that if we’re transforming a 3d point to the 2d projection, using these formulas, then this is not a linear transformation, because where are dividing by the depth z. We can simply fix it by adding one addition coordinates to get so called homogeneous coordinates. Then I can go from homogeneous coordinates to non homogeneous coordinates by dividing through the last entry of the homogeneous vector (W = 1).

2.3 Perspective projection

I need to multiply my x and y coordinates with the focal length, and divide by z. So I take my homogeneous 3d vector, which is a four dimensional repre- sentation (with a constant added in the last dimension of this representation) and multiplied with this three by four matrix, I get a homogeneous 2d vector out of it. And if I just do row times column, I get f’ times x, f’ times y, and z. And then to convert this homogeneous 2d vector into a non homogeneous 2d vector, I need to divide by the last coordinates, which is Z, getting what I want basically

2.4 Single-view geometry (One camera)

We know that objects live in world coordinates, and these world coor- dinates have an origin. Then we have a camera and it also has its own coordinate system, the camera coordinate system. I need to turns basi- cally 3d into 2d, in our picture. ( and assuming that it was a pinhole camera, what we need to know is its optical center, and then I need to know the focal length of that camera). Then, in the world, we typically measure in some unit of distance, say mil- limeters and the camera coordinates are also in millimeters. But our image is not in millimeters, it’s in pixels. That means there is a third set of coor- dinates, the image coordinates. So we start with a world coordinate system, which has its origin say P W and then I’m transforming that to camera coordinates with the respective P C^. This transformation is called the extrinsic camera transformation. The next thing is the intrinsic camera transformation, where I go from camera coordinate system to image coordinate systems. So we go from 3d to 2d, and then go from millimeters to pixels.

2.4.1 Extrinsic

I don’t want to model the absolute world coordinates, but the world coor- dinates relative to the camera Center, which I’m going to call c tilde. Then I just subtract c tilde from every 3d point Xw , and then I need to apply the camera rotation R, a three by three rotation matrix (andare sopra, f’-f’- 1). Once I apply that, then I get my coordinates in camera coordinates, in non-homogeneous coordinates:

x˜C^ = R(˜xW^ − C˜)

Now, since this is not very convenient, because I need to first subtract a cam- era center and then multiply with a rotation matrix, I can also instead define everything in homogeneous coordinates by basically appending a constant one to the non homogeneous coordinate vector Xw , and multiplying now with a four by four rotation matrix, which in the top left has my rotation matrix R, in the bottom right it has a constant one, in the top right it has -Rc, that I can write also as T(stand for translation: a translation is simply basically adding a vector to another vector or subtracting it from that), and then 0.

2.5 Ortographic Projection

I could simply project from 3d to 2d by forgetting the third dimension and simply setting the projection of x and y to the original x and y: this is called orthographic projection. It’s particularly useful if something is far away, because I’m really basically only looking at a very small bundle of rays, which are almost parallel and then it’s a reasonable assumption. They’re also called parallel projection and, as I mentioned, the distance from the center of the projection to the image plane is infinite. The projection matrix for this it’s a three by four matrix and what we need to do is basically preserve the X coordinates, so the first row of the matrix is just 1 0 0 0. Because if we then multiply row by column, we get 1*x + 0 * rest, which is x. In the second row, we need 0 1 0 0, for the same reason as before but for y. And the last row needs to be 0001 so that I preserve the homogeneous one. And then, at the end, doing row times column I get just (x,y) out of it. What that means is that if my prospective projection is too complicated, I can assume an orthographic projection and I can I simply need to choose a different camera intrinsic matrix. The downside of that is that we can’t really recover depth from this.

2.6 Camera calibration: Projection matrix from cor-

respondences

We have 3d points big Xi and 2d image correspondences little xi and we want to recover the unknown projection matrix P from these correspondences. First of all, the rays from the origin to the image point and the ray from the origin to the feature in the 3d worlds, they need to be collinear, they need to point in the same direction. In other words, x and PX are parallel, which means that one of them is simply a scaled version of the other, with some unknown scaling factor lambda. In other words, lambda times the image coordinates xi, yi, and 1 because we have a homogeneous 2d vector, is equal to my projection matrix P times 3d points big Xi. xi and P times Xi should be parallel, which means that their cross product should be zero. We can rewrite in a form that we can easily extract P from it, because it what we don’t know, so we write a matrix of the things that we know, and a vector of the things that we don’t know, and the we need to solve this linear equation system. We have 12 parameters (3x4 projection matrix) that I want to figure out, but we only have 11 degrees of freedom, because the scale is arbitrary.

One 2D/3D correspondence gives us only two linearly independent equa- tions, because the third one is linear dependent on the first two. So that means I need six correspondences for a minimal solution.

Now, we can solve that using the homogeneus least square.

2.6.2 RQ-Decomposition

Once we’ve recovered the values of the camera matrix, we still have to figure out the intrinsic and extrinsic parameters. When we use the SVD on A transpose A, we get P, a vector and we need to basically reshape into a matrix. Then, first split the projection matrix into a 3x3 matrix and a 3x vector. What we know is that the 3x3 matrix M arises from the intrinsic calibration matrix times the rotation matrix, while m is the last column vector of this matrix, so is - KRc, where c is the unknown camera offset.

P = [M |m] = [KR| − KR˜c]

Next, decompose M into K (calibration) and R (rotation), using RQ-decomposition. ((We know that R is a rotation matrix, so it’s symmetric, and it has deter- mined one.)) Finally, we can find c as the nullspace of P using SVD. With this algorithm, we have a projection matrix P, which maps any point in the 3D world co- ordinates to image coordinates. So we can find out where the projection of a 3D point in the world lies on the image. Then, we can aks: given a point in the images, find out where this point is in the world. The problem is we cannot do this from one image, at least not without additional knowledge, because the depth is lost.

2.7 Real camera: thin lens formula

We know from pinhole camera that the bigger the hole is, the more light will come through. If we make the pinhole smaller, the picture will be less blurry, but, if we make the pinhole even smaller, the image gets blurrier again, at some point. This is the so called diffraction effects: if the pinhole gets too small, the lights due to its wave characteristics gets spread out again. So the optimum is somewhere in the middle. To fix that, we don’t want to use a pinhole camera, we want to put a lens in front of the camera. What the lens does is it basically ”focuses” the light rays to arrive at a certain point. There is a specific distance at which objects are ”in focus” and all other points basically project to a so called circle of confusion, in the image. This can be well approximated by the so called thin lens formula. I look at the distance between the lens and the object, which is D. I look at the distance between the lens and the image plane, which is D’. I also look at the focal length of the lens, which is f (the distance between the lens and the focal point). Any point satisfying the thin lens equation is in focus: 1 D′^

D

f

Anything that’s closer, so smaller than D’, will not be in focus, and anything that’s further away, being bigger than D is also not the focus.

The range of image being more or less sharp is the so called Depth of Field. The depth of field is basically the interval in terms of depth in which the image is reasonably sharp. The depth of field not only depends on the lens and its properties, but really also on the resolution of the camera. If our aperture is big, meaning the opening in front of the lens is big, we get a small depth of field. If we have a small aperture then things get more similar to a pinhole and that means there’s more stuff in focus.

The field of view (Zoom) is the arc tangents of D over two times f, where D is basically the sensor size and f is the focal length of the lens. Basically, smaller field of view means we need a larger focal length and viceversa.

2.8 CCD vs CMOS

Basically, there used to be two types of common sensors, so called CCD sen- sors (Charge Coupled devices) and CMOS sensors (Complementary metal oxide semiconductor). The sensor basically converts photons into measur- able quantity, into an array of numbers. And, at the same time, it also converts the spatially continuous signal into a spatially sampled representa- tion. So we take the continuous signal, we apply a sampling operator and we get the sampled image.

CCD sensor transports the charge across the chip and reads it at one corner of the array. An analog-to-digital converter (ADC) then turns each pixel’s value into a digital value by measuring the amount of charge at each photo- site and converting that measurement to binary form.

The CMOS sensor is works differently: uses several transistors at each pixel to amplify and move the charge using more traditional wires. The CMOS signal is digitized right away, so it needs no separate ADC.

2.9 Color

Each pixel basically have three different light sources (Red,Green,Blue). To turn a black and white sensor into a color sensor we can put a color filter in front of it, using a so called Bayer grid. Each pixel has a small color filter in front of it, capturing either blue or red or green. They’re placed in a checkerboard order: one pixel blue, one pixel not blue, one pixel blue, one pixel not blue, and and the rows are alternating and same is true for red, except that it’s different pixels, and for green will be captured twice! The reason for that is that our human eye is more sensitive to the green than red and blue. That means, a 20 megapixel camera, in reality, only captures 5 million blue values, 5 million red values and 10 million green values, and image that comes out still has 20 million RGB values. So what we basically do is interpolate the missing pixels, basically average the neighboring red channels, so average the neighboring blue pixels, to get the missing values. Interpolation can lead to poor quality, to so called moire effect: if we re- duce the spatial resolution of what we’re capturing, then you don’t have this moire effect. Most digital cameras, nowadays, have an artificial blur filter called optical low-pass filter, that overcome this problem.

Low light is another problem for real camera, because we get noise. One thing that we can use it’s the ISO value. If we have an high ISO setting on your sensor, what it does is basically get less light, with the downside of having more noise. Other issues are, basically, if you have a sensor with millions of pixels, qual- ity of lens have to be high, that would make it extremely costly. Basically, the lenses are not really good enough to take advantage of this. So more megapixels are great, because you might have more resolution, but then you also have more noise, and you need to have better lenses. Need a trade off. We may want also compression, but then we lose image quality, we can counter that with raw images. blooming: if we have a pixel, and we have light hitting that pixel, we will not only create image information in that pixel, but it might also spill a lit- tle bit into the neighboring pixel. And that then means that we get spatial effects that we don’t actually want.

3.1 Linear filter

Linear filters are have some nice mathematical/computational properties. The particular properties that linear filters fulfill are homogeneity: when you multiply the inputs with a scalar a and then apply the filter, this must be the same as apply the filter and then multiply with the scalar a. The next important concept is additivity: if we take the sum of two images and then apply the filter, this is the same as apply the filter at each image and then sum them. We have also superposition, which is basically a combination of two T [a · X + b · Y ] = a · T [X] + b · T [Y ]

If I take a vector and I multiply it with a matrix, it fulfills these conditions. It turns out that convolutions are just a special case of the matrix-vector product. Basically, convolution replace each pixel by a linear combination of its neighbors (and itself): we take the image f and we basically move a kernel over it, a filter over it, h. That filter basically combines information from various neighboring pixels, so For each sub window, basically take a product with the coefficients, pixel by pixel, and then sum up the contributions. In convolution, I’m going to multiply the bottom left pixels in the image with a top right pixel of the filter, so always flipped in horizontal and vertical direc- tion. There’s also an operation without that flipping, it’s called correlation. We can think filter as basically shifting this three by three window over the image f, so we take basically a three by three sub window, and I iterate over all sub windows in a way that I actually process all overlapping supplements. In the conventional definition of a convolution, my output image is smaller and how much smaller it gets depends on the size of the filter kernel. Important properties of the convolution are: Linear (if we apply a convo- lution h to the sum of f0 and f1, then that’s the same thing as convolving f0 with h and f1 with h separately), Associative, Commutative and Shift invariance.

3.1.1 Average filter

So first idea would be to basically average of noise. We just have a three by three filter, it could also be bigger, and we simply set all of the filter coefficients to the same value, for example 1. Then I multiply that with 1/9, if we have 3x3 filter, to make sure that all the filter coefficients sum up to one. If all weights are equal, it is called box filter. This filter so basically removes anything that has a high frequency but remove also detail and that’s why we typically don’t use a box filter.

3.1.2 Gaussian filter

A gaussian filter is the simplest noise removal filter. It basically just uses the well known curve of Gauss, which is basically a probability density function. We simply set the filter coefficients proportional to the probability density under the bell curve, so we weight the pixel that are ”closer” more than the pixel that are distant. And that’s the gold standar for image quality.

Some filters are called separable, which means that I can basically write the filter as the convolution of one filter with another filter. I first apply, for example, a filter along the rows, and then I filter along the columns in the second step. That’s not possible for all filters. The box filter is one example and also the 2D-Gaussian is basically just the product of a Gaussian on the X with the Gaussian on the y direction.

Padding: I want to make sure that my output has the same size as the input. One way to achieve this is to basically extend the input by enough pixels so that the output has the same size as the input. One strategies can be to add zeros around it, because then I’m not inventing any information, but that has some problems: the output will get darker on the edges of the input. Another solution can be for example clamp the values, which means that we assume that the last value on the border simply continues, for a few more pixels to the outside. I can also do other things like wrapping around, so I assume that my image wraps around in both horizontal and vertical direction. We can say that no one of these solutions are perfect.