Volume reconstruction from 3D image gradient in Matlab - matlab

For 2D images- Gx and Gy gives the information on vertical and horizontal edge infromation respectively. Angle of the gradient direction vector can be calculated from inverse of tan(Gy/Gx) and edge direction will be perpendicular to the gradient direction vector.
I have 3D Z-stacked image datset so each pixel will be represented by (x,y,z) co-ordinate and with respective intensity value as well. I have used 3D image gradient link for initial reference.
(1) What if I want to derive whole volume/wireframe model just with the information of 3D image gradient magnitude and direction?
(2) Do I need X, Y and Z-stacked image data seperately in order to generate whole volume/wireframe model out of it?
In matlab, I can also develop whole volume just with 2D z-stacked masks using isosurface command. Here I am exploring other possibilities to generate wireframe volume/3D model.
Thanking you in anticipation.

Related

Matching RGB image with point cloud

I have an RGB image and a point cloud acquired by LIDAR.
In the RGB image I detect a feature, let's say a circle.
I want to use this circle as a ROI in my 3d point cloud.
How can I do that? I was thinking to produce a 3d point cloud from the RGB image through the camera parameters and then match the 2 with icp algorithm.
The problem's that on the moment I produce the point cloud from the 2D image, my coordinates system change, so I don't know anymore the position of my circle.
To perform 3d reconstruction I use triangulateMultiview function
I was thinking to produce a 3d point cloud from the RGB image through the camera parameters and then match the 2 with icp algorithm.
-> this would not work and not efficient.
Actually, there is a much better way. Assuming that you know the extrinsic between the camera and lidar, any circle(or ellipse) on the image can be extended into a 3d cone using the camera intrinsic and by selecting the points within the cone you can do the ROI operation.
Let's say you can define an ellipse on your image plane by detecting and finding the parameters of an ellipse equation. The ellipse equation can be extended into the quadric(cone) equation which representing the 3D cone. Now the only thing left is testing if your 3d point is within the cone by putting the cone equation.
This is a mathematically little bit complicated problem if you are not comfortable with camera model or quadric equation.

Find translation and rotation of a 3D image given a 2D projection

Given a non-planar 3D image and a 2D projection image, I need to determine the 3D translation and rotation of the 3D image that led to the 2D projection.
I have 3D coordinates of a 3D image and some of the corresponding 2D coordinates of the 2D image. I would like to find the translation and rotation of the 3D image that would best match the x and y coordinates of the 2D image. Also, the scale between the 3D image and 2D image is unknown. The 3D image is in mm, but the 2D image is in pixels.
Is there some matlab code or a set of formulas that shows how to get the translation and rotation of the 3D image to match the 2D projection?
Any help is much appreciated!
You have not specified what kind of projection is used.
In general case you have projection matrix T with unknown coefficients Tij, set of source coordinates S[], set of result projections P[] and set of equations for every S-P pair:
S * T = P
Try to solve this equation system for matrix coefficients.
Example math for 2D case

I need to fit a best circle to the 3D data in matlab

Basically, I have a many irregular circle on the ground in the form of x,y,z coordinates (of 200*3 matrix). but I want to fix a best circle in to the data of x,y,z coordinates (of 200*3 matrix).
Any help will be greatly appreciated.
I would try using the RANSAC algorithm which finds the parameters of your model (in your case a circle) given noisy data. The algorithm is quite easy to understand and robust against outliers.
The wikipedia article has a Matlab example for fitting a line but it shouldn't be too hard to adapt it to fit a circle.
These slides give a good introduction to the RANSAC algorithm (starting from page 42). They even show examples for fitting a circle.
Though this answer is late, I hope this helps others
To fit a circle to 3d points
Find the centroid of the 3d points (nx3 matrix)
Subtract the centroid from the 3D points.
Using RANSAC, fit a plane to the 3D points. You can refer here for the function to fit plane using RANSAC
Apply SVD to the 3d points (nx3 matrix) and get the v matrix
Generate the axes along the RANSAC plane using the axes from SVD. For example, if the plane norm is along the z-direction, then cross product between the 1st column of v matrix and the plane norm will generate the vector along the y-direction, then the cross product between the generated y-vector and plane norm will generate a vector along the x-direction. Using the generated vectors, form a Rotation matrix [x_vector y_vector z_vector]
Multiply the Rotation matrix with the centroid subtracted 3d points so that the points will be parallel to the XY plane.
Project the points to XY plane by simply removing the Z-axes from the 3d points
fit a circle using Least squares circle fit
Rotate the center of the circle using the inverse of the rotation matrix obtained from step 5
Translate back the center to the original location using the centroid
The circle in 3D will have the center, the radius will be the same as the 2D circle we obtained from step 8, the circle plane will be the RANSAC plane we obtained from step 3

plotting 3D edge in matlab

I have a 3D matrix of a MRI image and used matlab edge function and it gave me a 3D matrix as follow which some of the points are 1 (means edges).
I want to show this surface in matlab but I don't know that how I should do this. I know that I should use surf.
As #bdecaf said, you can use find to determine the height of the points, or in other words, in which of the 100 layers does the point lie. You can do that as follows:
z1=zeros(30,100);
temp=find(b);
[row,col,layer]=ind2sub(size(b),temp);
for i=1:size(x,1)
z1(row(i),col(i))=layer(i);
end
You can get an image as follows:

Build 3D surface from one 2D top-down image surface

I am wondering if there is a way to build a random 3D surface from only one (top-down) 2D image of this surface. The fact is that the 3D surface needs the z-coordinates (the heights and the depths) and the 2D (top-down) image gives only the x and y coordinates.
I believe that the main problem is that we can't get the real ranges of the dimensions (x,y,z) of the surface from one 2D (top-down) image but we can get some kind of normalized scaling which is not the real one (it's just similar).
For example:
If we have an image with a surface (2D) and we want 3D of this surface (x,y,z) we can have easily the x and the y coordinates from the image. We can't have the real range of the amplitude (z coordinate) in each point of the surface but only the gray-tones scaling. Is there any ideas on how could we take the real sizes of the amplitudes of a surface from one 2D (top-down) image?
Left is a sample of 2D top-down image and Right is a surface which created by the 2D
http://www.sendspace.com/file/9wzx0u
p.s.
I can't post an image because of my reputation, so I uploaded one on sedspace.com.
Read in the image:
A = imread(filename)
Plot the surface plot using the magnitude of the value read in for each x and y from the file:
surf(A)