IOLink C# 1.11.0
Loading...
Searching...
No Matches
VolumeFromStack.cs

Create a volume from a series of 2D-images given in user-memory. Many 2D images are in user-memory and represent a volume if stacked together. This code shows how to create ImageView from these 2D images, and then create a Volume from these ImageViews.

using IOLink;
using System;
using System.Data;
namespace Examples
{
public class VolumeFromStack
{
static Byte[] slice_0
= new Byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
static Byte[] slice_1
= new Byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
static Byte[] slice_2
= new Byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
static Byte[] slice_3
= new Byte[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
static Byte[] slice_4
= new Byte[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 };
static Byte[] slice_5
= new Byte[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
static Byte[] slice_6
= new Byte[] { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
static Byte[] slice_7
= new Byte[] { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
static Byte[] slice_8
= new Byte[] { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
static Byte[] slice_9
= new Byte[] { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 };
static Byte[][] slicesData = new Byte[][] {
slice_0, slice_1, slice_2, slice_3, slice_4, slice_5, slice_6, slice_7, slice_8, slice_9
};
// create a ImageView for the slice whose data, shape and
// datatype are given in parameters.
private static ImageView CreateSliceFromRawData(Byte[] data,
VectorXu64 sliceShape,
DataType dtype)
{
RegionXu64 fullRegion = RegionXu64.CreateFullRegion(sliceShape);
// create an image view in memory
ImageView slice = ImageViewFactory.Allocate(sliceShape, dtype);
// write the data into the image view
slice.WriteRegion(fullRegion, data);
// update properties of the slice
slice.HasAlpha = false;
slice.AxesInterpretation = ImageTypeId.IMAGE;
slice.ImageInterpretation = ImageInterpretation.GRAYSCALE;
return slice;
}
// create the volume from slices
private static ImageView CreateVolumeFromSlices(Byte[][] slices)
{
// create a MultiImageView from all ImageViews
VectorXu64 shapeSlice = new VectorXu64(10, 10);
DataType dtype = DataTypeId.UINT8;
// iterate over all slices
for (int i = 0; i < slices.Length; ++i)
{
// create an ImageView from the slice data
ImageView slice = CreateSliceFromRawData(slices[i], shapeSlice, dtype);
// add the slice to the MultiImageView
sliceContainer.AddFrame(slice);
}
// create the volume by indicating the new dimension
// as SLICE
return ImageViewFactory.Stack(sliceContainer, ImageDimension.SLICE);
}
public static void Main(string[] args)
{
ImageView volume = CreateVolumeFromSlices(slicesData);
Console.WriteLine(volume.ToString());
Console.WriteLine(volume.Properties.ToString());
}
}
}
Definition CreateDataFrame.cs:6