Ejemplo n.º 1
0
        public void DrawTest()
        {
            // arrange
            string specification = @"
⬇10
E10R80E10
78×E10RE78RE10
E10R80E10
⬇10
";

            this.ExpectedImage = TestImage.Create(100, 100, Color.Black, specification);

            var @event = new SpectralEvent()
            {
                EventEndSeconds    = 9,
                EventStartSeconds  = 1,
                HighFrequencyHertz = 900,
                LowFrequencyHertz  = 100,
            };
            var options = new EventRenderingOptions(new UnitConverters(0, 10, 1000, 100, 100));

            // act

            this.ActualImage.Mutate(x => @event.Draw(x, options));

            // assert
            this.AssertImagesEqual();
        }
Ejemplo n.º 2
0
        public void TestFromSourceToDestination(string resourcePath)
        {
            // Load source image
            using Bitmap sourceBitmap = TestImage.FromResource(resourcePath) as Bitmap;

            Assert.IsNotNull(sourceBitmap);

            // Create blank bitmap
            using Bitmap copyBitmap = new(sourceBitmap.Width, sourceBitmap.Height, sourceBitmap.PixelFormat);

            // Crop region of image
            ImageCopy.FromSourceToDestination(sourceBitmap, copyBitmap);

            // Check size
            Assert.AreEqual(sourceBitmap.Width, copyBitmap.Width);
            Assert.AreEqual(sourceBitmap.Height, copyBitmap.Height);

            // Get bytes for each image
            byte[] sourceBytes = ImageBytes.FromImage(sourceBitmap);
            byte[] copiedBytes = ImageBytes.FromImage(copyBitmap);

            // Compare to ensure correct copy matches
            int limit = System.Math.Min(sourceBytes.Length, copiedBytes.Length);

            for (int i = 0; i < limit; i++)
            {
                Assert.AreEqual(sourceBytes[i], copiedBytes[i]);
            }
        }
Ejemplo n.º 3
0
 private void CheckNotNull(TestImage img)
 {
     if (img == null)
     {
         throw new NullReferenceException("Null testImage");
     }
 }
Ejemplo n.º 4
0
        public void TestCombineAllSame()
        {
            string resourcePath = "Freedom35.ImageProcessing.Tests.Resources.clock.bmp";

            // Load source image
            using Image sourceImage = TestImage.FromResource(resourcePath);
            Assert.IsNotNull(sourceImage);

            using Image sourceImageCopy = TestImage.FromResource(resourcePath);
            Assert.IsNotNull(sourceImageCopy);

            Image[] imagesToCombine = new Image[]
            {
                sourceImage,
                sourceImageCopy
            };

            // Combine
            Bitmap combinedImage = ImageCombine.All(imagesToCombine);

            // Convert for byte comparison
            Bitmap sourceBitmap = ImageFormatting.ToBitmap(sourceImage);

            // Compare images
            Assert.IsTrue(TestImage.Compare(sourceBitmap, combinedImage));
        }
Ejemplo n.º 5
0
        public void TestByRegion(string resourcePath)
        {
            // Load source image
            using Image sourceImage = TestImage.FromResource(resourcePath);

            Assert.IsNotNull(sourceImage);

            Rectangle region = new(0, 0, sourceImage.Width / 2, sourceImage.Height / 2);

            // Crop region of image
            using Image croppedImage = ImageCrop.ByRegion(sourceImage, region);

            Assert.IsNotNull(croppedImage);

            // Check size
            Assert.AreEqual(region.Width, croppedImage.Width);
            Assert.AreEqual(region.Height, croppedImage.Height);

            // Get bytes for each image
            byte[] sourceBytes  = ImageBytes.FromImage(sourceImage);
            byte[] croppedBytes = ImageBytes.FromImage(sourceImage);

            // Compare to ensure correct region cropped
            int limit = croppedImage.Width * croppedImage.Height;

            for (int i = 0; i < limit; i++)
            {
                Assert.AreEqual(sourceBytes[i], croppedBytes[i]);
            }
        }
Ejemplo n.º 6
0
        public void TestAsBytes(string sourceResourcePath)
        {
            // Load source image
            using Image sourceImage = TestImage.FromResource(sourceResourcePath);

            Assert.IsNotNull(sourceImage);

            const byte Threshold = 0x7F;

            // Get bytes for image
            byte[] imageBytes = ImageBinary.AsBytes(sourceImage, Threshold);

            // Check we have some bytes
            Assert.IsNotNull(imageBytes);

            // Check all converted to binary (0 or 1)
            Assert.IsTrue(imageBytes.All(b => b < 0x02));

            // Check correct number of bytes after conversion
            // (Same per source image)
            Assert.AreEqual(118287, imageBytes.Length);

            // Count 1's and 0's
            int countZero = imageBytes.Count(b => b == 0x00);
            int countOne  = imageBytes.Count(b => b == 0x01);

            // May be slight variances due to compression
            // but should be similar.
            Assert.IsTrue(countZero > 52000 && countZero < 52100);
            Assert.IsTrue(countOne > 66200 && countOne < 66300);
        }
        /// <summary>
        /// Handler for the ManipulationDelta event. It may or may not be a pinch. If it is not a
        /// pinch, the ViewportControl will take care of it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            if (e.PinchManipulation != null)
            {
                e.Handled = true;

                if (!_pinching)
                {
                    _pinching = true;
                    Point center = e.PinchManipulation.Original.Center;
                    _relativeMidpoint = new Point(center.X / TestImage.ActualWidth, center.Y / TestImage.ActualHeight);

                    var xform = TestImage.TransformToVisual(viewport);
                    _screenMidpoint = xform.Transform(center);
                }

                _scale = _originalScale * e.PinchManipulation.CumulativeScale;

                CoerceScale(false);
                ResizeImage(false);
            }
            else if (_pinching)
            {
                _pinching      = false;
                _originalScale = _scale = _coercedScale;
            }
        }
Ejemplo n.º 8
0
 private void CheckHasBeenAdded(TestImage img)
 {
     if (!img.Id.HasValue)
     {
         throw new Exception($"Img not in db");
     }
 }
 public void Validate()
 {
     if (!Directory.Exists(TargetDir))
     {
         Directory.CreateDirectory(TargetDir);
     }
     TestImage.Save(Path.Combine(TargetDir, Name), ImageFileType.Png);
 }
 public void Fail()
 {
     if (!Directory.Exists(ReferenceImageManager.FailedImageCacheDir))
     {
         Directory.CreateDirectory(ReferenceImageManager.FailedImageCacheDir);
     }
     TestImage.Save(Path.Combine(ReferenceImageManager.FailedImageCacheDir, Name), ImageFileType.Png);
 }
Ejemplo n.º 11
0
        public EventSeeSingleImage(TestImage img)
        {
            var vm = new EventSeeSingleImageViewModel(img);

            vm.Navigation       = Navigation;
            this.BindingContext = vm;
            InitializeComponent();
        }
        private void CompareTestImgs(TestImage t1, TestImage t2)
        {
            t1.Should().BeEquivalentTo(t2, opt => opt.Excluding(i => i.Img));
            var mat = t1.Img;

            mat.Rows.Should().Be(t2.Img.Rows);
            mat.Cols.Should().Be(t2.Img.Cols);
        }
Ejemplo n.º 13
0
        private void TesterGUI_FormClosing(object sender, FormClosingEventArgs e)
        {
            isTesting = false;

            if (TestImage != null)
            {
                TestImage.Dispose();
            }
        }
Ejemplo n.º 14
0
        public static TestImage CreateTestImage(string id, string fileName)
        {
            TestImage myTestImage = new TestImage();

            myTestImage.HiveId    = id;
            myTestImage.ImageName = fileName;

            return(myTestImage);
        }
Ejemplo n.º 15
0
        private int getCRCHashCodeforFile(TestImage crtHiveImage, string filePath)
        {
            String     hash               = String.Empty;
            FileStream imageFile          = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            int        imageFileHashValue = imageFile.GetHashCode();

            imageFile.Close();

            return(imageFileHashValue);
        }
Ejemplo n.º 16
0
        public void TestBytesGetMaxValue()
        {
            const string ResourcePath = "Freedom35.ImageProcessing.Tests.Resources.clock.bmp";

            using Image image = TestImage.FromResource(ResourcePath);

            byte max = ImageBytes.GetMaxValue(image);

            Assert.AreEqual(0xff, max);
        }
Ejemplo n.º 17
0
        public void TestPicturePostfix()
        {
            uut = new PicturePostfix();
            TestImage ti = new TestImage
            {
                PinId = "testId"
            };

            Assert.That(uut.Generate(ti), Is.EqualTo("testId"));
        }
Ejemplo n.º 18
0
        public void TestCombineAllWithNegative()
        {
            string resourcePath = "Freedom35.ImageProcessing.Tests.Resources.clock.bmp";

            // Load source image
            using Image sourceImage = TestImage.FromResource(resourcePath);
            Assert.IsNotNull(sourceImage);

            using Image negativeCopy = ImageColor.ToNegative(sourceImage);
            Assert.IsNotNull(negativeCopy);

            Image[] imagesToCombine = new Image[]
            {
                sourceImage,
                negativeCopy
            };

            Bitmap combinedImage = ImageCombine.All(imagesToCombine);

            // Get bytes for images
            byte[] combinedBytes = ImageBytes.FromImage(combinedImage);

            // Just check first row of bytes has been combined
            for (int i = 0; i < combinedImage.Width; i++)
            {
                Assert.AreEqual(byte.MaxValue, combinedBytes[i]);
            }

            int pixelDepth = 3;
            int stride     = 1056;
            int width      = 1053;
            int height     = combinedImage.Height;

            int limit = combinedBytes.Length - 4;

            // Compare combined bytes excluding stride padding
            for (int y = 0; y < height; y++)
            {
                int offset = y * stride;

                for (int x = 0; x < width; x += pixelDepth)
                {
                    int i = offset + x;

                    if (i < limit)
                    {
                        Assert.AreEqual(byte.MaxValue, combinedBytes[i]);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public void TestBytesGetMinMaxValue()
        {
            const string ResourcePath = "Freedom35.ImageProcessing.Tests.Resources.clock.bmp";

            using Image image = TestImage.FromResource(ResourcePath);

            Tuple <byte, byte> minMax = ImageBytes.GetMinMaxValue(image);

            Assert.AreEqual(0x00, minMax.Item1);
            Assert.AreEqual(0xff, minMax.Item2);
        }
Ejemplo n.º 20
0
        public void FlexLayoutMeasuresImagesUnconstrained()
        {
            var root       = new Grid();
            var flexLayout = new FlexLayout() as IFlexLayout;
            var image      = new TestImage();

            root.Add(flexLayout);
            flexLayout.Add(image as IView);

            var manager = new FlexLayoutManager(flexLayout);

            _ = manager.Measure(1000, 1000);

            Assert.True(image.Passed, "Image should be measured unconstrained even if the FlexLayout is constrained.");
        }
Ejemplo n.º 21
0
        public void Remove(TestImage img)
        {
            CheckNotNull(img);
            CheckHasBeenAdded(img);

            var sql = $@"DELETE FROM {TestImageTable} WHERE Id=@Id;";

            using var connection = CreateConnection();
            var result = connection.Execute(sql, img);

            if (result != 1)
            {
                throw new Exception($"Could not remove testImage {img.Id}");
            }
        }
Ejemplo n.º 22
0
        public ActionResult LoadImage(string id, HttpPostedFileBase theFile)
        {
            //POST (load) an image from hard disk
            //method is called when button LoadAnImagefromDisk is pressed
            // OR POST (load) the image received from Android
            if (Request.Files.Count > 0)
            {
                try
                {
                    HttpPostedFileBase postedImage = Request.Files[0];  // Request.Files["File"];
                    if (postedImage != null && postedImage.ContentLength > 0)
                    {
                        string        deployPath      = Server.MapPath(LOCAL_PATH);
                        string        destinationPath = deployPath + "\\" + id;
                        DirectoryInfo di   = Directory.CreateDirectory(destinationPath);
                        string        path = Path.Combine(destinationPath, Path.GetFileName(postedImage.FileName));

                        postedImage.SaveAs(path);

                        TestImage modelToSendToView = _monitorDBContex.TestImages.FirstOrDefault(im => im.HiveId == id);
                        if (modelToSendToView == null)
                        {
                            modelToSendToView = _monitorDBContex.TestImages.Create();
                            _monitorDBContex.TestImages.Add(modelToSendToView);
                        }

                        modelToSendToView.HiveId    = id;
                        modelToSendToView.ImageName = postedImage.FileName;
                        modelToSendToView.FileCRC   = getCRCHashCodeforFile(modelToSendToView, path);
                        _monitorDBContex.SaveChanges();

                        ViewBag.localPath  = LOCAL_PATH + "/" + id;
                        ViewBag.FileStatus = "File upload - OK"; // this message is sent back to Android
                        return(View("LoadImage", modelToSendToView));
                    }
                }
                catch (Exception e)
                {
                    string err = e.ToString();

                    ViewBag.FileStatus = "Error while file uploading.";
                }
            }


            ViewBag.FileStatus = "File uploaded failed.";
            return(View());
        }
        public void TestApplyThresholdValue(string sourceResourcePath)
        {
            // Load source image
            using Image sourceImage = TestImage.FromResource(sourceResourcePath);

            Assert.IsNotNull(sourceImage);

            // Apply threshold
            using Image thresholdImage = ImageThreshold.Apply(sourceImage, 0x40);
            Assert.IsNotNull(thresholdImage);

            byte[] withoutAlphaBytes = RemoveAlphaLayerBytes(ImageBytes.FromImage(thresholdImage), sourceImage.PixelFormat);

            // Check bytes thresholded
            Assert.IsTrue(withoutAlphaBytes.Take(sourceImage.Width).All(b => b == byte.MinValue || b == byte.MaxValue));
        }
Ejemplo n.º 24
0
        public async Task TestLoadInformationFromImage(TestImage image)
        {
            var file = new Mock <IFile>();

            file.Setup(x => x.OpenRead()).Returns(image.GetStream);

            var loader = new FileInformationLoader(new SHA256FileHasher(), _logger, Options.Create(new InfrastructureOptions()));
            var result = await loader.Load(file.Object);

            Assert.Equal(image.Hash, result.Hash);
            Assert.NotNull(result.PhotoProperties);

            Assert.Equal(image.Width, result.PhotoProperties.Width);
            Assert.Equal(image.Height, result.PhotoProperties.Height);
            Assert.Equal(image.CreatedOn, result.FileCreatedOn);
        }
Ejemplo n.º 25
0
        public void TestCombineAllMixedColor()
        {
            using Image colorImage = TestImage.FromResource("Freedom35.ImageProcessing.Tests.Resources.clock.bmp");
            Assert.IsNotNull(colorImage);

            using Image bwImage = TestImage.FromResource("Freedom35.ImageProcessing.Tests.Resources.clock-bw.bmp");
            Assert.IsNotNull(bwImage);

            Image[] imagesToCombine = new Image[]
            {
                colorImage,
                bwImage
            };

            Assert.ThrowsException <ArgumentException>(() => ImageCombine.All(imagesToCombine));
        }
Ejemplo n.º 26
0
        public void TestBytesGetAvgValue()
        {
            const string ResourcePath = "Freedom35.ImageProcessing.Tests.Resources.clock.bmp";

            using Image image = TestImage.FromResource(ResourcePath);

            byte avg = ImageBytes.GetAverageValue(image);

            // Average for image
            Assert.AreEqual(0x8d, avg);

            avg = ImageBytes.GetAverageValue(image, 0x22, 0x24);

            // Average in range
            Assert.AreEqual(0x23, avg);
        }
Ejemplo n.º 27
0
        public void TestImageResizeAsNewByRatio(string resourcePath)
        {
            // Load source image
            using Image sourceImage = TestImage.FromResource(resourcePath);

            Assert.IsNotNull(sourceImage);

            Bitmap bitmap = sourceImage as Bitmap;

            Assert.IsNotNull(bitmap);

            using Image resizedImage = ImageResize.ResizeAsNew(bitmap, 2.0);

            Assert.IsNotNull(resizedImage);
            Assert.AreEqual(bitmap.Width * 2, resizedImage.Width);
            Assert.AreEqual(bitmap.Height * 2, resizedImage.Height);
        }
        public void TestApplyMinMax(string sourceResourcePath)
        {
            // Load source image
            using Image sourceImage = TestImage.FromResource(sourceResourcePath);

            Assert.IsNotNull(sourceImage);

            // Apply min/max value
            using Image minMaxImage = ImageThreshold.ApplyMinMax(sourceImage, 0x25, 0xc3);

            Assert.IsNotNull(minMaxImage);

            byte[] withoutAlphaBytes = RemoveAlphaLayerBytes(ImageBytes.FromImage(minMaxImage), sourceImage.PixelFormat);

            // Check all within range
            Assert.IsTrue(withoutAlphaBytes.All(b => b >= 0x25 && b <= 0xc3));
        }
        public void TestApplyMin(string sourceResourcePath)
        {
            // Load source image
            using Image sourceImage = TestImage.FromResource(sourceResourcePath);

            Assert.IsNotNull(sourceImage);

            // Apply min value
            using Image minImage = ImageThreshold.ApplyMin(sourceImage, 0x20);

            Assert.IsNotNull(minImage);

            byte[] withoutAlphaBytes = RemoveAlphaLayerBytes(ImageBytes.FromImage(minImage), sourceImage.PixelFormat);

            // Check all greater than value
            Assert.IsTrue(withoutAlphaBytes.All(b => b >= 0x20));
        }
        private void TestFinalImage()
        {
            if (frameTimer == null)
            {
                frameTimer          = new DispatcherTimer();
                frameTimer.Tick    += (o, e) => TimerTick();
                frameTimer.Interval = TimeSpan.FromMilliseconds(1000 / 40);
            }

            if (!frameTimer.IsEnabled)
            {
                var width  = Device.ImageWidth;
                var height = Device.ImageHeight;
                testImage      = new TestImage(width, height, Device.ImageSize);
                testImageFrame = 0;
            }

            frameTimer.IsEnabled = !frameTimer.IsEnabled;
        }