| 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
MultiImageView sliceContainer = MultiImageViewFactory.Create();
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());
}
}
}
IOLink.DataType
Stores information about a data type.
Definition DataType.cs:24
IOLink.ImageTypeId
Enum for the image type (see ImageType)
Definition ImageTypeId.cs:20
IOLink.ImageViewFactory
This factory is aimed at creating dataset views.
Definition ImageViewFactory.cs:21
IOLink.ImageViewFactory.Stack
static ImageView Stack(MultiImageView view, ImageDimension newDimension)
Creates an ImageView from a multiImageView by agglomerating frames into a new given dimension.
Definition ImageViewFactory.cs:578
IOLink.ImageViewFactory.Allocate
static ImageView Allocate(VectorXu64 shape, DataType type, ImageProperties properties, MetadataNode metadata)
Creates a memory image with the given shape and type.
Definition ImageViewFactory.cs:86
IOLink.ImageView
Interface representing an N dimensional image.
Definition ImageView.cs:30
IOLink.ImageView.Properties
ReadonlyImageProperties Properties
The ImageProperties associated with this ImageView instance.
Definition ImageView.cs:84
IOLink.ImageView.ToString
string ToString()
Return a string representation.
Definition ImageView.cs:226
IOLink.ImageView.WriteRegion
unsafe void WriteRegion(RegionXu64 region, byte[] src)
Write a input buffer into a given region of the image.
Definition ImageView.cs:387
IOLink.MultiImageViewFactory
This factory is aimed at creating stack of ImageViews.
Definition MultiImageViewFactory.cs:14
IOLink.MultiImageViewFactory.Create
static MultiImageView Create()
Creates an empty MultiImageView.
Definition MultiImageViewFactory.cs:62
IOLink.MultiImageView
Interface representing a multi-image view, i.e. a stack of ImageView.
Definition MultiImageView.cs:19
IOLink.MultiImageView.AddFrame
virtual void AddFrame(ImageView newFrame)
Add a new frame at the end of the set.
Definition MultiImageView.cs:123
IOLink.RegionXu64
A Region using dynamic vectors.
Definition RegionXu64.cs:14
IOLink.RegionXu64.CreateFullRegion
static RegionXu64 CreateFullRegion(VectorXu64 regionSize)
Utility factory that create the region of origin [0, 0, 0] and given size.
Definition RegionXu64.cs:173
IOLink.VectorXu64
A dynamically sized arithmetic vector.
Definition VectorXu64.cs:14
Examples
Definition CreateDataFrame.cs:6
IOLink
Definition AccessCapabilities.cs:11
IOLink.ImageInterpretation
ImageInterpretation
Interpretation of an Image.
Definition ImageInterpretation.cs:15
IOLink.ImageDimension
ImageDimension
Enum used in ImageType to represent each dimension of an Image.
Definition ImageDimension.cs:15
IOLink.DataTypeId
DataTypeId
A collection of built-in data types.
Definition DataTypeId.cs:15