This code demonstrates how to adapt a float ImageView into a 16-bit unsigned integer ImageView. Data are converted on the fly, and the resulting image has values between 0 and 65535. Both images are displayed to show their content.
using Newtonsoft.Json.Linq;
using System;
using System.Runtime.Intrinsics;
{
public class GradientFloatToInt
{
{
float[] lineBuffer = new float[shape[0]];
float stepLine = ((float)inputRange[1] - (float)inputRange[0]) / shape[1];
Console.WriteLine("Writing data slice by slice, line by line");
float valueInit = (float)inputRange[0];
float valueToSet = valueInit;
for (ulong j = 0; j < shape[1]; ++j)
{
Array.Fill(lineBuffer, valueToSet);
valueToSet = valueInit + j * stepLine;
}
Console.WriteLine("Writing completed");
return image;
}
private static void displayImageContent<T>(
ImageView image)
{
Console.WriteLine("Image content: ");
for (ulong j = 0; j < shape[1]; ++j)
{
for (ulong i = 0; i < shape[0]; ++i)
{
Console.Write(buffer[i + j * shape[0]]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Main(string[] args)
{
ImageView floatImage = GenerateGradientWithGivenRange(inputRange);
GradientFloatToInt.displayImageContent<float>(floatImage);
floatImage,
new Vector2d((
double)inputRange[0], (
double)inputRange[1]),
GradientFloatToInt.displayImageContent<UInt16>(IntImage);
Console.WriteLine("SUCCESS");
}
}
}
Stores information about a data type.
Definition DataType.cs:24
This factory is aimed at creating dataset views.
Definition ImageViewFactory.cs:21
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
static ImageView AdaptDynamicRange(ImageView view, DataType type, Vector2d inputRange, Vector2d outputRange)
Creates an ImageView from another view with given type by mapping dynamic range.
Definition ImageViewFactory.cs:465
Interface representing an N dimensional image.
Definition ImageView.cs:30
VectorXu64 Shape
The ImageView shape, the size of each of its dimensions.
Definition ImageView.cs:71
unsafe void ReadRegion(RegionXu64 region, byte[] dst)
Read a region of the image into a buffer.
Definition ImageView.cs:270
unsafe void WriteRegion(RegionXu64 region, byte[] src)
Write a input buffer into a given region of the image.
Definition ImageView.cs:387
A Region using dynamic vectors.
Definition RegionXu64.cs:14
uint ElementCount
The number of elements in this region.
Definition RegionXu64.cs:139
static RegionXu64 CreateFullRegion(VectorXu64 regionSize)
Utility factory that create the region of origin [0, 0, 0] and given size.
Definition RegionXu64.cs:173
An arithmetic vector.
Definition Vector2d.cs:29
An arithmetic vector.
Definition Vector2f.cs:29
A dynamically sized arithmetic vector.
Definition VectorXu64.cs:14
Definition CreateDataFrame.cs:6
Definition AccessCapabilities.cs:11
DataTypeId
A collection of built-in data types.
Definition DataTypeId.cs:15