Exemplo n.º 1
0
        public void UpscaleConstructor_Correct()
        {
            Random rnd  = new Random();
            var    ims8 = new ImageStack8(43, 43, 41, 41, ImageStack.SliceOrders.ZBeforeT);
            //quickly fill image with random values
            int *buffer = (int *)ims8.ImageData;
            long iter   = ims8.ImageNB / 4;

            for (long i = 0; i < iter; i++)
            {
                buffer[i] = rnd.Next();
            }
            var ims16 = new ImageStack16(ims8, true);

            Assert.AreEqual(ims8.SliceOrder, ims16.SliceOrder);
            for (int z = 0; z < ims8.ZPlanes; z++)
            {
                for (int t = 0; t < ims8.TimePoints; t++)
                {
                    for (int y = 0; y < ims8.ImageHeight; y++)
                    {
                        for (int x = 0; x < ims8.ImageWidth; x++)
                        {
                            float value = *ims8[x, y, z, t];
                            value = (value / 255) * ushort.MaxValue;
                            Assert.AreEqual((ushort)Math.Floor(value), *ims16[x, y, z, t]);
                        }
                    }
                }
            }
            ims8.Dispose();
            ims16.Dispose();
        }
Exemplo n.º 2
0
        public void From8bit_Constructor_Correct()
        {
            Random rnd  = new Random();
            var    ims8 = new ImageStack8(43, 43, 41, 41, ImageStack.SliceOrders.ZBeforeT);
            //quickly fill image with random values
            int *buffer = (int *)ims8.ImageData;
            long iter   = ims8.ImageNB / 4;

            for (long i = 0; i < iter; i++)
            {
                buffer[i] = rnd.Next();
            }
            var ims32 = new ImageStack32F(ims8, 2500);

            Assert.AreEqual(ims8.SliceOrder, ims32.SliceOrder);
            for (int z = 0; z < ims8.ZPlanes; z++)
            {
                for (int t = 0; t < ims8.TimePoints; t++)
                {
                    for (int y = 0; y < ims8.ImageHeight; y++)
                    {
                        for (int x = 0; x < ims8.ImageWidth; x++)
                        {
                            Assert.AreEqual(*ims8[x, y, z, t], *ims32[x, y, z, t] / 2500 * 255, *ims8[x, y, z, t] / 1000.0);
                        }
                    }
                }
            }
            ims8.Dispose();
            ims32.Dispose();
        }
Exemplo n.º 3
0
        public void RangeCheck_OnPixelAccess()
        {
            var ims = new ImageStack8(5, 5, 5, 5, ImageStack.SliceOrders.ZBeforeT);
            var p   = ims[5, 0, 0, 0];

            ims.Dispose();
        }
Exemplo n.º 4
0
        public void PixelPointerNull_AfterDispose()
        {
            var ims = new ImageStack8(5, 5, 5, 5, ImageStack.SliceOrders.ZBeforeT);

            ims.Dispose();
            Assert.IsTrue(ims[4, 0, 0, 0] == null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Compares every pixel in an image to a given value
        /// </summary>
        /// <param name="value">The value each pixel should have</param>
        /// <param name="image">The image to compare</param>
        private void CompareValImage(byte value, ImageStack8 image)
        {
            byte *imStart = image.ImageData;

            //only compare outside of stride padding
            for (long i = 0; i < image.ImageNB; i++)
            {
                if (i % image.Stride < image.ImageWidth)
                {
                    Assert.AreEqual(value, imStart[i], "Found non-matching pixel at position {0}", i);
                }
            }
        }
Exemplo n.º 6
0
        public void Construction_WithValidArguments_DimCorrect()
        {
            int w   = 20;
            int h   = 30;
            int z   = 40;
            int t   = 50;
            var ims = new ImageStack8(w, h, z, t, ImageStack.SliceOrders.TBeforeZ);

            Assert.AreEqual(ims.ImageWidth, w, "Image width not correct.");
            Assert.AreEqual(ims.ImageHeight, h, "Image height not correct.");
            Assert.AreEqual(ims.ZPlanes, z, "Image z plane number not correct.");
            Assert.AreEqual(ims.TimePoints, t, "Number of timepoints not correct.");
            ims.Dispose();
        }
Exemplo n.º 7
0
        public void CopyConstructor_Correct()
        {
            var ims = CreateDefaultStack();

            ims.SetAll(33);
            var copy = new ImageStack8(ims);

            Assert.IsFalse(ims.ImageData == copy.ImageData, "Source and its copy point to the same buffer");
            byte *sourceStart = ims.ImageData;
            byte *copyStart   = copy.ImageData;

            for (long i = 0; i < ims.ImageNB; i++)
            {
                Assert.AreEqual(sourceStart[i], copyStart[i], "Found non-matching pixel");
            }
            ims.Dispose();
            copy.Dispose();
        }
Exemplo n.º 8
0
        public void Downscale_Construction_Correct()
        {
            var          rnd    = new Random();
            ImageStack16 source = new ImageStack16(50, 50, 50, 50, ImageStack.SliceOrders.TBeforeZ);
            //quickly fill image with random values
            int *buffer = (int *)source.ImageData;
            long iter   = source.ImageNB / 4;

            for (long i = 0; i < iter; i++)
            {
                buffer[i] = rnd.Next();
            }
            ushort      rangeMin = 10;
            ushort      rangeMax = 1000;
            ImageStack8 ims8     = new ImageStack8(source, rangeMin, rangeMax);

            Assert.AreEqual(source.SliceOrder, ims8.SliceOrder);
            for (int z = 0; z < source.ZPlanes; z++)
            {
                for (int t = 0; t < source.TimePoints; t++)
                {
                    for (int y = 0; y < source.ImageHeight; y++)
                    {
                        for (int x = 0; x < source.ImageWidth; x++)
                        {
                            float pixel = *source[x, y, z, t];
                            pixel = pixel - rangeMin;
                            pixel = pixel / (rangeMax - rangeMin) * byte.MaxValue;
                            pixel = pixel < 0 ? 0 : pixel;
                            pixel = pixel > byte.MaxValue ? byte.MaxValue : pixel;
                            Assert.AreEqual((byte)pixel, *ims8[x, y, z, t]);
                        }
                    }
                }
            }
            source.Dispose();
            ims8.Dispose();
        }
Exemplo n.º 9
0
        public void Construction_WithInvalidHeight()
        {
            var ims = new ImageStack8(20, 0, 40, 50, ImageStack.SliceOrders.TBeforeZ);

            ims.Dispose();
        }