axis and shape in spyder variable explorer - spyder

I have a 3 dimensional ndarray and cannot understand the Axis and Shape in the variable explorer of Spyder.
Below variable is my 3 dimensional array and I would appreciate if someone can explan the axis and shapes for me:
t = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
t = np.reshape(t,(4,3,2))
for example when I set the Axis to 0, a 3*2 frame will show up. when I set it to 1, a 4*2 frame will show up and finally when I set the Axis to 2, a 4*3 frame will show up and I am having trouble visualizing them in a 3 dimensional form.
PS: I know it sounds completely unprofessional ...

Axis 0 would list values on y-z plane
Axis 1 gives x-z plane values
Axis 2 would list values on x-y plane
Index would be the dimension of the third axis whose value is not shown for a given axis.
a=np.ones(90)
a = np.ones(90)
a= a.reshape(9,5,2)
a[0]=2*a[0]
a[:,1,:]=3*a[:,1,:]
a[:,:,1]=7*a[:,:,1]
a.shape
Try this code and see the results with different values. If any index in slicing is -1, it means the value for that index is calculated based on the othee dimensions of the dataframe.

Related

Extending a straight line

There is a sloping LineSeries with two points showing a straight line. How can I calculate the Y value so the line continues infinitely in the same direction?
This line is like a guide-line that should follow along when values are added to another Series in the same chart. But must never change angle.
I'm using Delphi and Lazarus.
Suppose that the line passes through (x0,y0) and (x1,y1). The slope of the line k is given by:
k = (y1-y0) / (x1-x0)
So the line can be expressed as
y(x) = y0 + k(x-x0)
So you need to add points to the series whose x values are the minimum and maximum x values displayed on the chart. And whose y values are calculated as above.
This assumes that the line is not vertical, that is that x0 does not equal x1. If the line is vertical then the solution is trivial. Place points at the y values of the minimum and maximum values of the chart.

Display 3D matrix with its thickness information

I have a problem about plotting 3D matrix. Assume that I have one image with its size 384x384. In loop function, I will create about 10 images with same size and store them into a 3D matrix and plot the 3D matrix in loop. The thickness size is 0.69 between each size (distance between two slices). So I want to display its thickness by z coordinate. But it does not work well. The problem is that slice distance visualization is not correct. And it appears blue color. I want to adjust the visualization and remove the color. Could you help me to fix it by matlab code. Thank you so much
for slice = 1 : 10
Img = getImage(); % get one 2D image.
if slice == 1
image3D = Img;
else
image3D = cat(3, image3D, Img);
end
%Plot image
figure(1)
[x,y,z] = meshgrid(1:384,1:384,1:slice);
scatter3(x(:),y(:),z(:).*0.69,90,image3D(:),'filled')
end
The blue color can be fixed by changing the colormap. Right now you are setting the color of each plot point to the value in image3D with the default colormap of jet which shows lower values as blue. try adding colormap gray; after you plot or whichever colormap you desire.
I'm not sure what you mean by "The problem is that slice distance visualization is not correct". If each slice is of a thickness 0.69 than the image values are an integral of all the values within each voxel of thickness 0.69. So what you are displaying is a point at the centroid of each voxel that represents the integral of the values within that voxel. Your z scale seems correct as each voxel centroid will be spaced 0.69 apart, although it won't start at zero.
I think a more accurate z-scale would be to use (0:slice-1)+0.5*0.69 as your z vector. This would put the edge of the lowest slice at zero and center each point directly on the centroid of the voxel.
I still don't think this will give you the visualization you are looking for. 3D data is most easily viewed by looking at slices of it. you can check out matlab's slice which let's you make nice displays like this one:
slice view http://people.rit.edu/pnveme/pigf/ThreeDGraphics/thrd_threev_slice_1.gif

Image 3D rotation OpenCV

I need to perform a 3D rotation of a 2D image on x and y axis.
I read that i have to use the Homographic matrix on OpenCV , but i don't know how to set the matrix to perform a common rotation angle. For example 30 degree on x axis or 45° on y axis.
I read this post : Translating and Rotating an Image in 3D using OpenCV. I have tried different values of the f but it doesn't work.
I want to know which parameters of the matrix i have to change and how (formula).
Thank you!
Follow that same post, but replace your rotation matrix. Familiarize yourself with the Rorigues() function. You can send it a 1 x 3 array of the x, y, and z rotations. It will give you a a 3 x 3 rotation matrix. Plug this matrix in as the first 3 columns and 3 rows of R (leave the rest the same). If you don't want any translation, make sure you set the variable dist to 0 in the code on that page.

Rotate, Scale and Translate around image centre in OpenCV

I really hope this isn't a waste of anyone's time but I've run into a small problem. I am able to construct the transformation matrix using the following:
M =
s*cos(theta) -s*sin(theta) t_x
s*sin(theta) s*cos(theta) t_y
0 0 1
This works if I give the correct values for theta, s (scale) and tx/ty and then use this matrix as one of the arguments for cv::warpPerspective. The problem lies in that this matrix rotates about the (0,0) pixel whereas I would like it to rotate about the centre pixel (cols/2, rows/2). How can incoporate the centre point rotation into this matrix?
Two possibilities. The first is to use the function getRotationMatrix2D which takes the center of rotation as an argument, and gives you a 2x3 matrix. Add the third row and you're done.
A second possibility is to construct an additional matrix that translates the picture before and after the rotation:
T =
1 0 -cols/2
0 1 -rows/2
0 0 1
Multiply your rotation matrix M with this one to get the total transform -TMT (e.g. with function gemm) and apply this one with warpPerspective.

Put a line on zero value of y axis

Helo,
Is it possible to put a line on zero value of y axis ?
Because i have negatives values so i changed orthogonal value of my axis to the lowest one on my datasource.
Thanks
Make second x-axis and position it at zero. You can leave off the labels and tick marks to just get the axis line. See the axis demo in the Plot Gallery app for an example of how to add additional axes to a Core Plot graph.

Resources