If the image F is convoluted with the filter M what is the value of the shaded pixel? - filter

If the image F is convoluted with the filter M what is the value of the shaded pixel? can someone teach me how to calculate this please. with the steps

Related

Indexing image according to polar coordinates?

Ok, this might be a little dumb to ask but I'm really having a hard time understanding the image coordinates in Matlab.
So, in a mathematical equation, f(x,y) f is the image function where x and y are the coordinates of the image. For example, in matlab code, we can:
img = imread('autumn.tif');
img(1,4); %f(x,y)
where img(1,4) is equivalent to the function f(x,y). Now, in Matlab, there is an option to convert the cartesian coordinate (x,y) to polar coordinate (rho,theta) with cart2pol() function.
Now, here's where I don't understand. Is it possible to apply f(rho,theta) which is the polar coordinates instead of the cartesian coordinate in Matlab?
I tried doing something like:
img(2.14,1.5)
But I get the error message saying about array indexing is only supported with integers or logical values.
Could anyone clear up my understanding on this? Because I'm required to apply f(rho,theta) instead of the conventional f(x,y).
An image in Matlab is basically just an 2D array (if you consider just a greyscale image). Therefore you also need integer indices, just as for all other arrays, to access the pixels of the image.
% i,j integers, not doubles, floates, etc.
pixel = img(i,j);
The polar coordinates from yor last question (theta, rho) can therefore not be used to access the image array. That is also the exact reason for the error message. At least you'd need to round them or find some other way to use them as indices (e.g. convert them back to cartesian coords. would be best, due to matrix indexing)
Regarding your application: As far as I have found out, these polar coordinates are used as parameters for the Zernike polynomials. So why would you use them to access the image?

Matlab - Image Formation - Matrix

I am doing a very interesting Computer Vision project which talks about how to "create manually" images with Matlab.
The teacher gave me three matrices: the illuminant matrix (called E), the camera sensitivity matrix (called R) and finally, the surface reflectance matrix (called S).
The matrix dimensions are as follows:
S: 31x512x512 (reflectance samples x x-dimension x y-dimension)
R: 31x3
E: 31x1
The teacher gave me also the following relationship:
P=transpose(C)*R=transpose(S)*diagonal(E)*R
Where C is the color matrix.
Where P is the sensor response matrix.
The goal is to display the image formed by all the previous matrices. Therefore, we have to compute the P matrix.
The class of all the matrices is double.
This is what I have done:
Diag_D=diag(D);% Diagonal matrix of D
S_reshaped= reshape(S,31,[512*512]);% Reshape the surface reflectance matrix
S_permute=permute(S_reshaped,[2 1]);% The output matrix is a 262144x31 matrix
Color_Signal_D65_buffer=S_permute*Diag_DD;
Color_Signal_D65=reshape(Color_Signal_D65_buffer,[512 512 31]);% This is the final color matrix
Image_D65_buffer= (reshape(Color_Signal_D65,[512*512],31))*R;% Apply the given formula
Image_D65= reshape(Image_D65_buffer,[512 512 3]);% image formation
Image_D65_norm=sqrt(sum(Image_D65.^2,3));% Compute the Image_D65 norm
Image_D65_Normalized=bsxfun(#rdivide, Image_D65, Image_D65_norm);% Divide each element of the matrix by the norm in order to normalize the matrix
figure
imshow(Image_D65_Normalized)% Display the image
However,it did not work at all. The output is an image but the colors are completely wrong (there is too much blue on the image).
I think it could be a matrix reshaping problem but I have tried all the possible combinations but nothing to do.
Thank you so much for your help
I've finaly found the error. It was a problem in the normalization process. I was using the wrong formula.

Computing the homography matrix

I have a poster in the world image. I have to replace the poster with my own image.
Let the poster in world image have points A, B , C , D. My own image coordinates are a , b , c , d.
The idea is to compute a homography matrix such that a = HA, b = HB, c = HC, d = HD. After that I apply H^-1 to my image and transform them to the poster in in world image. I saw a couple of books , lectures like this.
Why is not that I can compute a homography H' such that A = H'a , B = H'b and so on. Why find H and then its inverse and not directly H'. Is there some problem with it?
Actually there isn't any difference between finding H and inverting it, or directly finding H^-1. Usually it is better to avoid inversion to speed up the algorithm and reduce accumulation of numerical errors.
I can't think of any 'real' reasons to use the inversion the way you described. Maybe authors did it for sake of clarity, or some notation conventions.
Also, usually when you warp an image using a homography - it is inverted under the hood. So instead of calculating the 'new' coordinates for points in the original image and writing source colors there - you iterate over pixels in the destination image and see where should you take the color values from in the source image. This way you can avoid writing to same pixel several times (if you are downscaling an image) or producing a sparse image (when upscaling).
If you post the exact sources where you have seen this unnecessary conversion - we can give you more helpful comments.

detect if a pixel in RGB image belong to a line between two other pixels (MATLAB)

I have a problem in my matlab project
I have a RGB color image, and I have two specified pixel (x1,y1) and (x2,y2)
I want to check each pixel in the image and determine if pixel is belong to the line between (x1,y1) and (x2,y2)
I tried to use these functions
m = (y2-y1)/(x2-x1);
b= y1 - m*x1;
if (y==m*x+b) then TRUE
but it almost fails
anybody has another way to solve it ? please
Thanks
bear in mind that pixels have area and aren't just points. depending on how you define your coordinates, you are checking something like "does the centre of my pixel lie exactly on the line between the centres of these other pixels"
i'm guessing that you may want to leave some leeway, ie set some tolerance and then check
if abs(m*x+b -y) < tolerance
instead of straight equality
You are, though you may not know it, trying to implement Bresenham's Algorithm or a similar algorithm.

Is there any algorithm for determining 3d position in such case? (images below)

So first of all I have such image (and ofcourse I have all points coordinates in 2d so I can regenerate lines and check where they cross each other)
(source: narod.ru)
But hey, I have another Image of same lines (I know thay are same) and new coords of my points like on this image
(source: narod.ru)
So... now Having points (coords) on first image, How can I determin plane rotation and Z depth on second image (asuming first one's center was in point (0,0,0) with no rotation)?
What you're trying to find is called a projection matrix. Determining precise inverse projection usually requires that you have firmly established coordinates in both source and destination vectors, which the images above aren't going to give you. You can approximate using pixel positions, however.
This thread will give you a basic walkthrough of the techniques you need to use.
Let me say this up front: this problem is hard. There is a reason Dan Story's linked question has not been answered. Let provide an explanation for people who want to take a stab at it. I hope I'm wrong about how hard it is, though.
I will assume that the 2D screen coordinates and projection/perspective matrix is known to you. You need to know at least this much (if you don't know the projection matrix, essentially you are using a different camera to look at the world). Let's call each pair of 2D screen coordinates (a_i, b_i), and I will assume the projection matrix is of the form
P = [ px 0 0 0 ]
[ 0 py 0 0 ]
[ 0 0 pz pw]
[ 0 0 s 0 ], s = +/-1
Almost any reasonable projection has this form. Working through the rendering pipeline, you find that
a_i = px x_i / (s z_i)
b_i = py y_i / (s z_i)
where (x_i, y_i, z_i) are the original 3D coordinates of the point.
Now, let's assume you know your shape in a set of canonical coordinates (whatever you want), so that the vertices is (x0_i, y0_i, z0_i). We can arrange these as columns of a matrix C. The actual coordinates of the shape are a rigid transformation of these coordinates. Let's similarly organize the actual coordinates as columns of a matrix V. Then these are related by
V = R C + v 1^T (*)
where 1^T is a row vector of ones with the right length, R is an orthogonal rotation matrix of the rigid transformation, and v is the offset vector of the transformation.
Now, you have an expression for each column of V from above: the first column is { s a_1 z_1 / px, s b_1 z_1 / py, z_1 } and so on.
You must solve the set of equations (*) for the set of scalars z_i, and the rigid transformation defined R and v.
Difficulties
The equation is nonlinear in the unknowns, involving quotients of R and z_i
We have assumed up to now that you know which 2D coordinates correspond to which vertices of the original shape (if your shape is a square, this is slightly less of a problem).
We assume there is even a solution at all; if there are errors in the 2D data, then it's hard to say how well equation (*) will be satisfied; the transformation will be nonrigid or nonlinear.
It's called (digital) photogrammetry. Start Googling.
If you are really interested in this kind of problems (which are common in computer vision, tracking objects with cameras etc.), the following book contains a detailed treatment:
Ma, Soatto, Kosecka, Sastry, An Invitation to 3-D Vision, Springer 2004.
Beware: this is an advanced engineering text, and uses many techniques which are mathematical in nature. Skim through the sample chapters featured on the book's web page to get an idea.

Resources