Opencv - cvHoughLines2 - opencv

I am reading Learning openCV and I came across description of cvHoughLines2 in this book. But I can't understand one thing.
I read about Hough transform and I think I understand it, so the parameters rho and theta are bit puzzling to me. When we have equation rho=xcos(theta)+ycos(theta) when we decide on some set of discrete values of theta, values of rho should be automatically known.
In this book it is said that opencv creates rhoxtheta accumlator array.
Does opencv just discretize angle as multiplies of 360/theta? But how does the rho parameter fits? How are the values of rho discretized?

Your question isn't clear, it seems you are confused. Have a look at this page. Given a set of points (the x's and y's) belonging to a line you can describe the same line by just two parameters r and theta. These are two independent parameters we want to find that best describe the line that we have the points on.

in beginning you decide vector of theta lets say 10 numbers , you need to round the result to fall in pixel of matrix which row represent radius and columns the angle
so if some line is in same angle and radius it will add the accumulator a value.
[0 36 .. 360]
also radius vector [1 2 3 .. 10]
then you create image M*N all zeros lets say for example only
[ 0 0 0
0 0 0
0 0 0]
then you perform formula you write at some radius and angleyour matrix become
[ 1 0 0
0 0 0
0 0 0]
then
[ 1 0 0
0 0 1
0 0 0]
then
[ 2 0 0
0 0 1
0 1 0]
ans so on
then you can threshold and find only some lines or at some angles.

Related

What should be the Dilation output of a blank image if we gave a structuring elemnt with all 0 or combination of 0 and don't care

Suppose my image data is
0 0 0
0 0 0
0 0 0
and I am giving a structuring element
0/-1 0 0
-1/0 0 0
0/-1 0 0
What will be the output of the dilated image? The center pixel should be 1 by theory right?
So if we apply a structuring element with only 0 s and don't care in a blank image will we get a white image?
Or such shapeless structuring elements are valid?
When you dilate an image, for each pixel you keep the maximum value in its neighborhood, and the neighborhood is defined by the structuring element.
So because you image contains only 0, the output can only be 0, whatever the structuring element.

How Sobel Mask is derived?

Gx = [-1 0 1
-2 0 2
-1 0 1]
Gy = [-1 -2 -1
0 0 0
1 2 1]
I knew these are the combination of smoothing filter and gradient but how are they combine to get this output ?
The Sobel Kernel is a convolution of the derivation kernel [-1 0 1] with a smoothing kernel [1 2 1]'. The former is straightforward, the later is rather arbitrary - you can see it as some sort of discrete implementation of a 1D Gaussian of a certain sigma if you want.
I think edge detection (ie gradient) influence is obvious - if there is a vertical edge. sobel operator Gx will definitely give big values relative to places where there is no edge because you just subtract two different values (intensity on the one side of an edge differs much from intensity on another side). The same thought on horizontal edges.
About smoothing, if you see e.g. mask for gaussian function for simga=1.0:
which actually does smoothing, you can catch an idea: we actaully set a pixel to a value associated to values of its neighbor. It means we 'average' values respectively to the pixel we are considering. In our case, Gx and Gy, it perforsm slightly smoothing in comparision to gaussian, but still idea remains the same.

Gaussian bluring differentiable by X and Y

Help me get the 3 * 3 matrix of coefficients of the Gaussian filter, differentiable by X and Y.
Is it just
0 0 0
-1 0 1
0 0 0
or not?
You may use this 3x3 mask to compute the horizontal and vertical first derivatives:
Wolfram|Alpha also knows about that:
http://www.wolframalpha.com/input/?i=GaussianMatrix[1%2C{0%2C1}]
Transpose to get the mask corresponding to the vertical first derivative.

Pixel-wise summation and subtraction in EmguCV

I'm looking for an elegant way to perform pixel-wise summation and subtraction in EmguCV.
I'm trying to calculate the Haar-like features of an image.
For a one-dimensional situation, it's done by multiplying the vector [x x x x x x x x] by the following vector element-wise:
[ 1 -1 1 -1 1 -1 1 -1]
[ 1 1 -1 -1 1 1 -1 -1]
[ 1 1 1 1 -1 -1 -1 -1]
So I need to add or subtract the element pixels of an image.
Say,
Bgr sum = new Bgr();
sum = sum + img[0,0] - img[0,1] + img[0,2] - img[0,3];
Obviously this won't compile since there's no operator "+" in class Bgr. I've to make a new Bgr by specifying each of the B, G, R value, which is ugly.
Any idea on performing elegant pixel-wise operation?
Previous Thread
You could probably use img.GetSum() if you first flip the sign of the pixels you want to be subtracted. You might be able to do that by multiplying the image element-wise with a matrix consisting of 1 and -1 at the appropriate places.

Fourier transform help and mean filter

In image processing, if f(m,n) represent the image then MEAN filtering with a convolution mask h(m,n) will be represented by g(m,n)=f(m,n) * h(m,n). Now, here lies the confusion.
There is a question which asks that there is be a filter whose output at (x,y) is defined as the average of the four immediate neigbours of (x,y) but the pixel at (x,y) is not used. The question is: what is the kind / nature of the filter and what should be the MTF of this filter?
The mask/kernel for 3x3 mean filter is h(m,n) = 1/9 [1 1 1;1 1 1; 1 1 1] and output g(m,n) = 1/9 x [f(m-1,n-1)+f(m-1,n)+f(m-1,n+1)+f(m,n-1) + f(m,n) +f(m,n+1) + f(m+!,n-1) +f(m+1,n) +f(m+1,n+1) ] . The Center pixel at x,y is being considered !!
So, what is the correct way to construct for any kind of mean filter and will be h(m,n) (kernel) for the 3x3 mean filter and the 4 connected filter?
What is the fourier transform of h(m,n)?
How to decide if H(u,v), the fourier transform, is resulting into a high pass or low pass filter?
There is no single "mean filter" - it's just a class of filters where you take the mean of a number of points. You can have a mean filter which takes the average of 4 adjacent points:
0 1 0
1 0 1
0 1 0
or a 3x3 mean filter:
1 1 1
1 1 1
1 1 1
or a 5x5 mean filter:
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
or any kernel geometry you like.
In general though a mean filter is a (not very good) low pass filter. The advantage of a mean filter is low computational complexity (no coefficient multiplies), but unless your performance requirements are very high then there are much better low pass filters which should be considered.
The Fourier Transform of any given mean filter is fairly easy to calculate once you know the exact kernel geometry you want to use, and is left as an exercise for the reader.

Resources