I have a stack of 2D images. lets say below are the dimensions of this volume.
Depth(Number of images) - 100
Width(Pixels in X axis) - 200
Height(Pixels in Y-axis) - 200
I want to rotate this volume and create Bitmaps out of this. I am using C#
to implement this.
Here is what i did:
List<short[]> volumebuffer = new List<short[]>(noImages);
for (int img = 0; imge<noImages; img++)
{
short[] tmpArray = new short[ImgTotalHeight * ImgTotalWidth];
int index = 0;
for (int aHeight = 0; aHeight<ImgTotalHeight; aHeight++)
{
for (int aWidth = 0; aWidth<ImgTotalWidth; aWidth++)
{
tmpArray[index++] = image[aWidth + aHeight * ImgTotalWidth];
}
}
#append this tmpArray to a List<>
vomumebuffer.Add(tmpArray);
}
In the above code the volumebuffer will contain all the pixel values of all the images. I am converting each short array of each image to byte array and creating the bitmaps out of it.
Now i want to rotate this volume and create bitmaps out of it. I want create only 90 degree orientations.
I tried to read the pixel values in different axis. Like for reading pixel values in Width-> Depth -> Height order etc..
But this will need many for loops for each orientation.
Is there any better way to achieve orientation of the volume?
Please help me on how i can rotate this volume at 90 degrees in different orientations.
Thanks in advance.
you should add methods to index the volume by x,y,z coordinates. Rotation in 90-degrees steps would then simply be switching places of the indices, keeping one dimension fixed. For example
bitmap[u, v] = volume[0, v, u]
or
bitmap[u, v] = volume[v, 0, u]
or
bitmap[u, v] = volume[xSize - v, u, 0]
there should be 24 valid combinations in total
you can replace 0 with whatever valid value you want, and you need to ensure the u/y coordinates are limited to corresponding volume-dimension.
Edit:
Example using multidimensional arrays in order to make indexing clearer. You would need to exchange this with corresponding code, and convert the result to a bitmap.
var volume = new ushort[1, 2, 3];
var bitmap = new ushort[volume.GetLength(2), volume.GetLength(1)];
for (int v = 0; v < bitmap.GetLength(1); v++)
{
for (int u = 0; u < bitmap.GetLength(0); u++)
{
bitmap[u, v] = volume[0, v, u];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.