Extract arbitrarily rotated plane of data from 3D array as 2D array

后端 未结 2 1564
鱼传尺愫
鱼传尺愫 2020-12-03 22:51

I have a 3D matrix of data in matlab, but I want to extract an arbitrarily rotated slice of data from that matrix and store it as a 2D matrix, which I can access. Similar to

相关标签:
2条回答
  • 2020-12-03 23:14

    You can take a look at the code here. I think the function is similar to what you are trying to solve.

    The function extracts an arbitrary plane from a volume given the size of the plane, the center point of the plane, and the plane normal, i.e. [A,B,C]. It also outputs the volumetric index and coordinate of each pixel on the plane.

    0 讨论(0)
  • Aha! May have just solved it myself.

    To produce the plane equation I rotate a normal vector of (0,0,1) using rotation matrices and then find D. If I also rotate the following vectors:

    (1,0,0) //step in the x direction of our 2D array
    

    and

    (0,1,0) //step in the y direction of our 2D array
    

    I'll have the gradients that denote how much my coordinates in x,y,z have to change before I step to the next column in my array, or to the next row.

    I'll mock this up ASAP and mark it as the answer if it works

    EDIT: Ok slight alteration, when I'm rotating my vectors I should also rotate the point in 3D space that represents the xyz coordinates of x=0,y=0,z=0 (although I'm rotating around the centre of the structure, so it's actually -sizex/2,-sizey/2,-sizez/2, where size is the size of the data, and then I simply add size/2 to each coordinate after the rotations to translate it back to where it should be).

    Now that I have the gradient change in 3D as I increase the x coordinate of my 2D array and the gradient change as I increase the y coordinate, I can simply loop through all possible x and y coordinates (the resulting array will be 50x50 for a 50x50x50 array, I'm not sure what it will be for irregular sizes, which I'll need to work out eventually) in my 2D array and calculate the resulting 3D coordinates on my plane in the data. My rotated corner value serves as the starting point. Hooray!

    Just got to work out a good test for this encompassing all angles and then I'll approve this as an answer

    0 讨论(0)
提交回复
热议问题