/// <summary> /// Reads dimensions and data type of given image file. /// </summary> /// <param name="filename">Name of file to examine.</param> /// <param name="dimensions">Dimension of the image. Returns zero dimensions if the image file could not be read.</param> /// <param name="dataType">Data type of the image. Returns Unknown if the image could not be read.</param> public void GetImageInfo(string filename, out Vec3 dimensions, out ImageDataType dataType) { dimensions = new Vec3(); dataType = ImageDataType.Unknown; using (Pi2Image result = NewImage(ImageDataType.UInt32, 4)) { PiLib.RunAndCheck(Handle, $"fileinfo({filename}, {result.ImageName})"); dimensions.X = result.GetValue(0); dimensions.Y = result.GetValue(1); dimensions.Z = result.GetValue(2); dataType = (ImageDataType)result.GetValue(3); } }
/// <summary> /// Writes the given image to a .raw file. /// Appends dimensions and extension to the file name. /// </summary> /// <param name="img"></param> /// <param name="filename"></param> public void WriteRaw(Pi2Image img, string filename) { PiLib.RunAndCheck(Handle, $"writeraw({img.ImageName}, {filename})"); }
/// <summary> /// Copies pixels of the source image to the target image to the specified location. /// Does not change the size of the target image. /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <param name="position"></param> public void Copy(Pi2Image source, Pi2Image target, Vec3 position) { PiLib.RunAndCheck(Handle, $"copy({source.Name}, {target.Name}, {ToIntVec(position)})"); }
/// <summary> /// Rotates input image 90 degrees clockwise. /// </summary> /// <param name="inImg"></param> /// <param name="outImg"></param> public void Rot90CW(Pi2Image inImg, Pi2Image outImg) { PiLib.RunAndCheck(Handle, $"rot90cw({inImg.Name}, {outImg.Name})"); }
/// <summary> /// Generate additive Gaussian noise. /// </summary> /// <param name="img">Target image where noise will be added.</param> /// <param name="mean">Mean of the noise.</param> /// <param name="stddev">Standard deviation of the noise.</param> public void Noise(Pi2Image img, float mean = 0.0f, float stddev = 50.0f) { PiLib.RunAndCheck(Handle, $"noise({img.Name}, {mean.ToString(CultureInfo.InvariantCulture)}, {stddev.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Set value of pixel at specified location. /// </summary> /// <param name="img"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="value"></param> public void Set(Pi2Image img, int x, int y, int z, float value) { PiLib.RunAndCheck(Handle, String.Format(CultureInfo.InvariantCulture, "set({0}, [{1}, {2}, {3}], {4})", img.Name, x, y, z, value)); }
/// <summary> /// Divide image by a constant. /// </summary> /// <param name="img"></param> /// <param name="value"></param> public void Divide(Pi2Image img, float value) { PiLib.RunAndCheck(Handle, $"divide({img.Name}, {value.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Add two images and place the result to the first one. /// </summary> /// <param name="img"></param> /// <param name="img2"></param> public void Add(Pi2Image img, Pi2Image img2) { PiLib.RunAndCheck(Handle, $"add({img.Name}, {img2.Name})"); }
/// <summary> /// Clear all metadata items. /// </summary> /// <param name="img"></param> public void ClearMeta(Pi2Image img) { PiLib.RunAndCheck(Handle, $"clearmeta({img.Name})"); }
/// <summary> /// Set metadata item with given name to given value. /// </summary> /// <param name="img"></param> /// <param name="name"></param> /// <param name="value"></param> /// <param name="i"></param> /// <param name="j"></param> public void SetMeta(Pi2Image img, string name, string value, int i = 0, int j = 0) { PiLib.RunAndCheck(Handle, $"setmeta({img.Name}, {name}, {value}, {i}, {j})"); }
/// <summary> /// Makes sure that the size of the image equals the given dimensions. /// Reallocates the image in case of size difference. /// </summary> /// <param name="img"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="depth"></param> public void EnsureSize(Pi2Image img, int width = 1, int height = 1, int depth = 1) { PiLib.RunAndCheck(Handle, $"ensuresize({img.Name}, {width}, {height}, {depth})"); }
public void List() { PiLib.RunAndCheck(Handle, "list()"); }
/// <summary> /// Mean projection in some coordinate direction. /// </summary> /// <param name="source"></param> /// <param name="target">Output image. Data type must be float32.</param> /// <param name="dimension"></param> public void MeanProject(Pi2Image source, Pi2Image target, int dimension) { PiLib.RunAndCheck(Handle, $"meanproject({source.Name}, {target.Name}, {dimension})"); }
/// <summary> /// Multiply two images and place the result into the first image. /// </summary> /// <param name="img">The first image. The result will be placed to this image.</param> /// <param name="img2">The seconds image.</param> /// <param name="allowBroadcast">Set to true to allow size of parameter image differ from size of input image. If there is a need to access pixel outside of parameter image, the nearest value inside the image is taken instead.If set to false, dimensions of input and parameter images must be equal. If set to true, the parameter image is always loaded in its entirety in distributed processing mode.</param> public void Multiply(Pi2Image img, Pi2Image img2, bool allowBroadcast = false) { PiLib.RunAndCheck(Handle, $"multiply({img.ImageName}, {img2.ImageName}, {allowBroadcast.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Multiply image by a constant. /// </summary> /// <param name="img"></param> /// <param name="value"></param> public void Multiply(Pi2Image img, float value) { PiLib.RunAndCheck(Handle, $"multiply({img.ImageName}, {value.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Converts img to specified data type in-place. /// Does not scale pixel values. /// </summary> /// <param name="img"></param> /// <param name="dt"></param> public void Convert(Pi2Image img, ImageDataType dt) { PiLib.RunAndCheck(Handle, $"convert({img.Name}, {dt})"); }
/// <summary> /// Make pixels of img equal those of img2. /// </summary> /// <param name="img"></param> /// <param name="img2"></param> public void Set(Pi2Image img, Pi2Image img2) { PiLib.RunAndCheck(Handle, $"set({img.Name}, {img2.Name})"); }
/// <summary> /// Read metadata from a file previously written by the WriteMeta command. /// </summary> /// <param name="img"></param> /// <param name="filename"></param> public void ReadMeta(Pi2Image img, string filename) { PiLib.RunAndCheck(Handle, $"readmeta({img.Name}, {filename})"); }
/// <summary> /// Subtract an image from a constant. /// </summary> /// <param name="img"></param> /// <param name="value"></param> public void InvSubtract(Pi2Image img, float value) { PiLib.RunAndCheck(Handle, $"invsubtract({img.Name}, {value.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Read image file to given image. /// </summary> /// <param name="target"></param> /// <param name="filename"></param> public void Read(Pi2Image target, string filename) { PiLib.RunAndCheck(Handle, $"read({target.Name}, {filename})"); }
/// <summary> /// Divide img by img2 and place the result to img. /// </summary> /// <param name="img">The first image. The result will be placed to this image.</param> /// <param name="img2">The seconds image.</param> /// <param name="allowBroadcast">Set to true to allow size of parameter image differ from size of input image. If there is a need to access pixel outside of parameter image, the nearest value inside the image is taken instead.If set to false, dimensions of input and parameter images must be equal. If set to true, the parameter image is always loaded in its entirety in distributed processing mode.</param> public void Divide(Pi2Image img, Pi2Image img2, bool allowBroadcast = false) { PiLib.RunAndCheck(Handle, $"divide({img.Name}, {img2.Name}, {allowBroadcast.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Create a disk-mapped image from existing .raw file or create a new .raw file if corresponding file does not exist. /// If data type and dimensions are not specified, the image file name must contain dimensions of the image, i.e. it must be in format corresponding to image_name_123x456x789.raw. /// </summary> /// <param name="image">The mapped image is placed into this image object. NOTE: Changes made to the image are IMMEDIATELY reflected on disk.</param> /// <param name="filename">Name of image file to map.</param> /// <param name="dataType">Data type of the image. Specify empty value to infer data type from image dimensions</param> /// <param name="width">Width of the image. Omit width, height and depth to infer dimensions from file name.</param> /// <param name="height">Height of the image. Omit width, height and depth to infer dimensions from file name.</param> /// <param name="depth">Depth of the image. Omit width, height and depth to infer dimensions from file name.</param> public void MapRaw(Pi2Image image, string filename, ImageDataType dataType = ImageDataType.Unknown, int width = 0, int height = 0, int depth = 0) { PiLib.RunAndCheck(Handle, $"mapraw({image.Name}, {filename}, {dataType}, {width}, {height}, {depth})"); }
/// <summary> /// Generate a grayscale ramp. /// </summary> /// <param name="img">Target image. Existing pixel values will be lost.</param> /// <param name="dimension">Dimension where gray values increase.</param> public void Ramp(Pi2Image img, int dimension) { PiLib.RunAndCheck(Handle, $"ramp({img.Name}, {dimension})"); }
/// <summary> /// Writes the given image to a .tif file. /// No extension is appended to the file name. /// </summary> /// <param name="img"></param> /// <param name="filename"></param> public void WriteTif(Pi2Image img, string filename) { PiLib.RunAndCheck(Handle, $"writetif({img.Name}, {filename})"); }
/// <summary> /// Scales input image and stores result to output image. /// </summary> /// <param name="inImg">Input image.</param> /// <param name="outImg">Output image. If scale factor is zero, the input image is scaled to the size of the output image.</param> /// <param name="scaleFactor">Scaling factor. If nonzero, the output image size is calculated from scaling factor and input image size. If zero, the input image is scaled to the size of the output image.</param> public void Scale(Pi2Image inImg, Pi2Image outImg, float scaleFactor = 0) { // TODO: Vector scaling factor, interpolation mode, boundary condition. PiLib.RunAndCheck(Handle, $"scale({inImg.Name}, {outImg.Name}, {scaleFactor.ToString(CultureInfo.InvariantCulture)})"); }
/// <summary> /// Performs FBP preprocessing for given projections. /// </summary> /// <param name="projections">Flat-field corrected projection data. This image is not modified.</param> /// <param name="preprocessed">This image will store the preprocessed projection data.</param> /// <param name="settings"></param> public void FBPPreprocess(Pi2Image projections, Pi2Image preprocessed, string settings) { PiLib.RunAndCheck(Handle, $"fbppreprocess({projections.Name}, {preprocessed.Name}, {settings})"); }
/// <summary> /// Copies pixels of source image to target image. /// Converts data type if required. /// </summary> /// <param name="source"></param> /// <param name="target"></param> public void Copy(Pi2Image source, Pi2Image target) { PiLib.RunAndCheck(Handle, $"copy({source.Name}, {target.Name})"); }
/// <summary> /// Performs backprojection part of filtered backprojection reconstruction. /// </summary> /// <param name="preprocessed">Projections processed using FBPPreprocess command.</param> /// <param name="output">Reconstruction will be placed in this image.</param> /// <param name="settings"></param> public void FBP(Pi2Image preprocessed, Pi2Image output, string settings) { PiLib.RunAndCheck(Handle, $"fbp({preprocessed.Name}, {output.Name}, {settings})"); }
/// <summary> /// Crops the image into size of output. Set size of output before calling this command or pass size as an argument. /// NOTE: If the data type of target image is not correct, this function will change it! /// </summary> /// <param name="input">Input image.</param> /// <param name="output">Output image.</param> /// <param name="position">Position in input image where the top-left corner of the cropped image is placed.</param> /// <param name="size">Size of output image. Specify zeroes or nothing to crop to current size of output image.</param> public void Crop(Pi2Image input, Pi2Image output, Vec3 position, Vec3 size) { PiLib.RunAndCheck(Handle, $"crop({input.Name}, {output.Name}, {ToIntVec(position)}, {ToIntVec(size)})"); }
/// <summary> /// Create an wx1x1 image that contains values of filter for use in filtered backprojection. /// </summary> /// <param name="output">Output image.</param> /// <param name="size">Desired size or zero to use size of output image.</param> /// <param name="filterType">Type of filter. Supported values are Ideal ramp1, Ramp, Shepp-Logan, Cosine, Hamming, Hann, Blackman, Parzen.</param> /// <param name="cutoff">Filter cutoff frequency.</param> public void CreateFBPFilter(Pi2Image output, int size = 100, string filterType = "Ramp", float cutoff = 1.0f) { PiLib.RunAndCheck(Handle, $"createfbpfilter({output.Name}, {size}, {filterType}, {cutoff.ToString(CultureInfo.InvariantCulture)})"); }