/// <summary> /// Construct new ImageStack using an initialized buffer /// </summary> /// <param name="imageData">Pointer to the buffer data</param> /// <param name="width">The width of the image in pixels</param> /// <param name="stride">The stride of the image in bytes</param> /// <param name="height">The height of the image in pixels</param> /// <param name="nZ">The number of zPlanes in the stack</param> /// <param name="nT">The number of timepoints in the stack</param> /// <param name="sliceOrder">The slize ordering of the image</param> public ImageStack32F(float* imageData, int width, int stride, int height, int nZ, int nT, SliceOrders sliceOrder) { //check stride - we don't accept strides that aren't divisible by 4 (size of float) if (stride % 4 != 0) throw new ArgumentException("Stride of 32-bit image has to be divisible by 4"); InitializeShallow((byte*)imageData, width, stride, height, nZ, nT, sliceOrder, 4); }
/// <summary> /// Initialize image buffer according to another image /// and copy image data. /// </summary> /// <param name="imsource">The source image to copy</param> protected void InitializeAsCopy(ImageStack imsource) { DisposeGuard(); _pixelSize = imsource._pixelSize; SliceOrder = imsource.SliceOrder; ImageWidth = imsource.ImageWidth; ImageHeight = imsource.ImageHeight; ZPlanes = imsource.ZPlanes; TimePoints = imsource.TimePoints; Stride = imsource.Stride; //request image buffer RequestImageData((IntPtr)(Stride * ImageHeight * ZPlanes * TimePoints)); //copy actual data CopyImageMemory(imsource, this); }
/// <summary> /// Makes a shallow copy effectively re-interpreting a memory chunk as a stack /// </summary> /// <param name="imageData">Pointer to the image data</param> /// <param name="width">The intended width of the image stack</param> /// <param name="stride">The intended stride of the image stack</param> /// <param name="height">The intended height of the image stack</param> /// <param name="nZ">The intended number of zPlanes</param> /// <param name="nT">The intended number of Timepoints</param> /// <param name="sliceOrder">The intended slice ordering</param> /// <param name="pixelSize">The intended pixel size in bytes</param> protected void InitializeShallow(byte *imageData, int width, long stride, int height, int nZ, int nT, SliceOrders sliceOrder, byte pixelSize) { if (imageData == null) { throw new ArgumentNullException(nameof(imageData)); } DisposeGuard(); //free old image data if necessary FreeImageData(); _pixelSize = pixelSize; SliceOrder = sliceOrder; ImageWidth = width; ImageHeight = height; ZPlanes = nZ; TimePoints = nT; Stride = stride; _imageData = imageData; IsShallow = true; ImageNB = Stride * ImageHeight * ZPlanes * TimePoints; }
/// <summary> /// Construct new ImageStack using an initialized buffer /// </summary> /// <param name="imageData">Pointer to the buffer data</param> /// <param name="width">The width of the image in pixels</param> /// <param name="stride">The stride of the image in bytes</param> /// <param name="height">The height of the image in pixels</param> /// <param name="nZ">The number of zPlanes in the stack</param> /// <param name="nT">The number of timepoints in the stack</param> /// <param name="sliceOrder">The slize ordering of the image</param> public ImageStack16(ushort *imageData, int width, int stride, int height, int nZ, int nT, SliceOrders sliceOrder) { //check stride - we don't accept strides that aren't divisible by 2 (size of ushort) if (stride % 2 != 0) { throw new ArgumentException("Stride of 16-bit image has to be divisible by 2"); } InitializeShallow((byte *)imageData, width, stride, height, nZ, nT, sliceOrder, 2); }
/// <summary> /// Construct new ImageStack using an initialized buffer /// </summary> /// <param name="imageData">Pointer to the buffer data</param> /// <param name="width">The width of the image in pixels</param> /// <param name="stride">The stride of the image in bytes</param> /// <param name="height">The height of the image in pixels</param> /// <param name="nZ">The number of zPlanes in the stack</param> /// <param name="nT">The number of timepoints in the stack</param> /// <param name="sliceOrder">The slize ordering of the image</param> public ImageStack16(ushort* imageData, int width, int stride, int height, int nZ, int nT, SliceOrders sliceOrder) { //check stride - we don't accept strides that aren't divisible by 2 (size of ushort) if (stride % 2 != 0) throw new ArgumentException("Stride of 16-bit image has to be divisible by 2"); InitializeShallow((byte*)imageData, width, stride, height, nZ, nT, sliceOrder, 2); }
/// <summary> /// Makes a shallow copy effectively re-interpreting a memory chunk as a stack /// </summary> /// <param name="imageData">Pointer to the image data</param> /// <param name="width">The intended width of the image stack</param> /// <param name="stride">The intended stride of the image stack</param> /// <param name="height">The intended height of the image stack</param> /// <param name="nZ">The intended number of zPlanes</param> /// <param name="nT">The intended number of Timepoints</param> /// <param name="sliceOrder">The intended slice ordering</param> /// <param name="pixelSize">The intended pixel size in bytes</param> protected void InitializeShallow(byte* imageData, int width,long stride, int height, int nZ, int nT, SliceOrders sliceOrder, byte pixelSize) { if (imageData == null) throw new ArgumentNullException(nameof(imageData)); DisposeGuard(); //free old image data if necessary FreeImageData(); _pixelSize = pixelSize; SliceOrder = sliceOrder; ImageWidth = width; ImageHeight = height; ZPlanes = nZ; TimePoints = nT; Stride = stride; _imageData = imageData; IsShallow = true; ImageNB = Stride * ImageHeight * ZPlanes * TimePoints; }
/// <summary> /// Construct new ImageStack using an initialized buffer /// </summary> /// <param name="imageData">Pointer to the buffer data</param> /// <param name="width">The width of the image in pixels</param> /// <param name="stride">The stride of the image in bytes</param> /// <param name="height">The height of the image in pixels</param> /// <param name="nZ">The number of zPlanes in the stack</param> /// <param name="nT">The number of timepoints in the stack</param> /// <param name="sliceOrder">The slize ordering of the image</param> public ImageStack8(byte* imageData, int width,int stride, int height, int nZ, int nT, SliceOrders sliceOrder) { InitializeShallow(imageData, width, stride, height, nZ, nT, sliceOrder, 1); }
/// <summary> /// Construct new ImageStack using an initialized buffer /// </summary> /// <param name="imageData">Pointer to the buffer data</param> /// <param name="width">The width of the image in pixels</param> /// <param name="stride">The stride of the image in bytes</param> /// <param name="height">The height of the image in pixels</param> /// <param name="nZ">The number of zPlanes in the stack</param> /// <param name="nT">The number of timepoints in the stack</param> /// <param name="sliceOrder">The slize ordering of the image</param> public ImageStack8(byte *imageData, int width, int stride, int height, int nZ, int nT, SliceOrders sliceOrder) { InitializeShallow(imageData, width, stride, height, nZ, nT, sliceOrder, 1); }
/// <summary> /// Construct new ImageStack using an initialized buffer /// </summary> /// <param name="imageData">Pointer to the buffer data</param> /// <param name="width">The width of the image in pixels</param> /// <param name="stride">The stride of the image in bytes</param> /// <param name="height">The height of the image in pixels</param> /// <param name="nZ">The number of zPlanes in the stack</param> /// <param name="nT">The number of timepoints in the stack</param> /// <param name="sliceOrder">The slize ordering of the image</param> public ImageStack32F(float *imageData, int width, int stride, int height, int nZ, int nT, SliceOrders sliceOrder) { //check stride - we don't accept strides that aren't divisible by 4 (size of float) if (stride % 4 != 0) { throw new ArgumentException("Stride of 32-bit image has to be divisible by 4"); } InitializeShallow((byte *)imageData, width, stride, height, nZ, nT, sliceOrder, 4); }