This question already has answers here:
Image rotation by Matlab without using imrotate
(4 answers)
Closed 7 years ago.
I have a 3D matrix with the dimensions X:24, Y:24, and Z:61397. Z corresponds to the number of frames. when I plot each frame I get an image that is rotated 45 degree clockwise.
I've been trying to rotate the matrix so that the pictures can be straight.(It needs to be rotated 45 degree anticlockwise).
I've tried multiplication by the following rotation matrix based on previous answers for similar question:
% rotation matrix
theta = pi/4;
Rot = makehgtform('xrotate',theta);
Rot = Rot(1:3,1:3);
I got an error due to the difference in size. Do I need to extend the rotation matrix to 24by24? If yes, how?
If all you are doing is rotating an image by 45 degrees you can simply use imrotate.
imrotate(Stack, 45);
where Stack is your 3D matrix.
In case you are looking for a solution which doesn't rely on the image processing toolbox have a look here.
Related
I have nxn matrix in 2D space; I would like to rotate the matrix around the x-axis using matlab. Where the x-axis pass through the center of the matrix (pass through the point [n/2 n/2].
I found the Matlab function B = rot90(A) which rotate the matrix A by 90 degree. But I’m looking for a method that rotate matrix A by any given angle (e.g. 30, 45, 170 degree) around the x-axis.
You can as well try imrotate(). This function is from the Image Processing Toolbox, but since its main input is a matrix (either real or logical) it'll work also for non picture-related matrices (I've tried with a magic matrix).
The syntax is:
B=imrotate(A,theta);
where A is you matrix, B is the rotated version of A and theta is the rotation in degrees. The rotation is performed in counterclockwise direction around its center point; to rotate the matrix clockwise, specify a negative value for theta.
This question already has answers here:
I need to fit a best circle to the 3D data in matlab
(2 answers)
Closed 7 years ago.
I have my 3D data X,Y,Z (Matrices with size X = 200*1, Y = 200*1, Z = 200*1)
I want to fit the data to the best fit circle
You have 200 pts in 3d space. And a circle also in 3d space, the circle is defined by its centre (3variables), orientation (normal to the circus, so 2 more variables, since its length does not matter) and radius (one more variable), Given a circle and an abitrary point, the distance from the pt to the circle is given by one side of a triangle formed by taking a line from the point to the centre of the triangle then to the radius. This will be defined in terms of the 7 variables (centre, orientation, radius), now you have two hundred distances, sum them and this is a formula in terms of radius, orientation and position, now put this formula inside any of the matlab optimizers and you will find the optimal centre,orientation, radius. This is for sure a convex problem...
I would like to :
step 1) Rotate an image with 20 degrees using this code rotatedImage = imrotate(originalImage, 20);.
step 2) calculate degree rotation used in step 1 based only on the rotated image if it possible or based on rotated image and the original image.
there is any function in matlab could do the step 2 or a proposition to do that?
This example shows one way to perform step 2:
A = 'peppers.jpg';
img = im2double(imread(A));
img_r=imrotate(img,20,'nearest','crop'); % <-- this is the distorted image
% rotated 20 deg
xopt = fminsearch(#(x) imr(x,img_r,img), 10); % <-- start with 10 deg as guess
where imr is the function
function obj= imr(x,img1,img2);
img1_r = imrotate(img1,x,'nearest','crop');
obj = sum((img2(:)-img1_r(:)).^2);
The function wraps imrotate, generating an objective function to minimize so that it can be used by fminsearch.
This shows the original, distorted, and reversed image (with angle determined as above):
Note the limitations: the rotated images are cropped so that a point-by-point comparison is possible during computation of the objective function.
This is probably not the absolutely best way to do this, as I imagine that there are morphological algorithms designed to answer your specific question in a more general way. Still it worked.
You might want to check this. I had used Fourier-Mellin transform to retrieve rotation. Its accurate up to 1 degree. I think you will have to invest some time + don't forget to check some papers on Fourier-Mellin transform
I want to normalize the sift descriptors by rotating them so that the horizontal direction is aligned with the dominant gradient orientation of the patch.
I am using vl_feat library. Is there any way in vl_feat to normalize the sift descriptos?
or
what is the effective way of doing this using matlab?
I believe the ones in VLfeat are already oriented in the dominant gradient direction.
It shows them rotated if you look here: http://www.vlfeat.org/overview/sift.html
[f,d] = vl_sift(I) ;
f is a Nx4 matrix of keypoints. N being the keypoint indexand the other 4 being, x position, y position, scale, and orientation. d is a Nx128 matrix, where N is the keypoint index, and the 128 dimensions belong to the SIFT descriptor.
If all of your images are rotated upright, it is actually beneficial to not use rotational invariance. See this paper which assume a gravity vector: https://dspace.cvut.cz/bitstream/handle/10467/9548/2009-Efficient-representation-of-local-geometry-for-large-scale-object-retrieval.pdf?sequence=1
This question already has answers here:
Plotting 3-D Matrix *values* in MATLAB
(2 answers)
Closed 7 years ago.
Ive created a 3d matrix in MATLAB. The values of the matrix are the velocity at that point in a rectangular section. I would like a plot with colours showing the values at each position, is this possible?
Phrasing this another way, I have a matrix of size 100x100x200. Id like a graph that has 100x100x200 points and the colour of each of those points is related to its value.
This question is very similar to this question. You might want to check it out.
UPDATE:
Suppose you have a 3D matrix A:
A = rand(100,100,200);
You want to plot each entry of A mapped to a color at its 3D coordinates. First generate the coordinates:
[x,y,z] = meshgrid(1:100,1:100,1:200);
Now you are ready to use scatter3:
scatter3(x(:),y(:),z(:),5,A(:))
Here the : indexing vectorizes the coordinates column-wise.
Hope this helps.