Beispiel #1
0
        public void Should_Throw_ArgumentOutOfRangeException_When_PatchSize_Less_Than_2(byte patchSize)
        {
            // Arrange
            var     detector = new PyramidLevelsDetector();
            ZsImage image    = CreateImage(100, 100);
            ZsImage markup   = CreateImage(50, 100);

            Action act = () => detector.CalculateLevelsAmount(image, markup, patchSize);

            // Act & Assert
            act.ShouldThrow <ArgumentOutOfRangeException>();
        }
Beispiel #2
0
        public void Should_Throw_AreaRemovedException_When_Markup_Covers_Image(int iw, int ih, int mw, int mh)
        {
            // Arrange
            var     detector  = new PyramidLevelsDetector();
            ZsImage image     = CreateImage(iw, ih);
            ZsImage markup    = CreateImage(mw, mh);
            byte    patchSize = 7;

            Action act = () => detector.CalculateLevelsAmount(image, markup, patchSize);

            // Act & Assert
            act.ShouldThrow <AreaRemovedException>();
        }
Beispiel #3
0
        public void Should_Throw_ArgumentNullException_When_RemoveMarkup_IsNull()
        {
            // Arrange
            var     detector  = new PyramidLevelsDetector();
            ZsImage image     = CreateImage(100, 100);
            ZsImage markup    = null;
            byte    patchSize = 7;

            Action act = () => detector.CalculateLevelsAmount(image, markup, patchSize);

            // Act & Assert
            act.ShouldThrow <ArgumentNullException>();
        }
Beispiel #4
0
        public void Should_Return_1_When_Markup_IsEmpty_Inside_Image_Area()
        {
            // Arrange
            var     detector  = new PyramidLevelsDetector();
            ZsImage image     = CreateImage(100, 100);
            ZsImage markup    = Create3pixBiggerMarkupNotEmptyOutsideOfTheImage(100, 100);
            byte    patchSize = 7;

            // Act
            var levelsAmount = detector.CalculateLevelsAmount(image, markup, patchSize);

            // Assert
            levelsAmount.ShouldBe((byte)1);
        }
Beispiel #5
0
        public void Should_Return_1_When_Markup_IsEmpty()
        {
            // Arrange
            var     detector  = new PyramidLevelsDetector();
            ZsImage image     = CreateImage(100, 100);
            ZsImage markup    = CreateImage(100, 100, 0.0);
            byte    patchSize = 7;

            // Act
            var levelsAmount = detector.CalculateLevelsAmount(image, markup, patchSize);

            // Assert
            levelsAmount.ShouldBe((byte)1);
        }
Beispiel #6
0
        public static async Task<CloudPyramid> GeneratePyramids([ActivityTrigger] InpaintRequest inpaintRequest)
        {
            var levelDetector = new PyramidLevelsDetector();
            var pyramidBuilder = new PyramidBuilder();
            var settings = new InpaintSettings();

            var container = BlobHelper.OpenBlobContainer(inpaintRequest.Container);
            var imageBlob = container.GetBlockBlobReference(inpaintRequest.Image);
            var removeMaskBlob = container.GetBlockBlobReference(inpaintRequest.RemoveMask);

            var imageArgb = await BlobHelper.ConvertBlobToArgbImage(imageBlob);
            var removeMaskArgb = await BlobHelper.ConvertBlobToArgbImage(removeMaskBlob);

            var levelsAmount = levelDetector.CalculateLevelsAmount(imageArgb, removeMaskArgb, settings.PatchSize);
            pyramidBuilder.Init(imageArgb, removeMaskArgb);
            var pyramid = pyramidBuilder.Build(levelsAmount, settings.PatchSize);
            var cloudPyramid = new CloudPyramid
            {
                Levels = new CloudPyramidLevel[pyramid.LevelsAmount]
            };

            for (byte levelIndex = 0; levelIndex < pyramid.LevelsAmount; levelIndex++)
            {
                var image = pyramid.GetImage(levelIndex);
                var fileName = $"{levelIndex}.png";
                await BlobHelper.SaveImageLabToBlob(image, container, fileName);
                cloudPyramid.Levels[levelIndex].ImageName = fileName;

                var inpaintArea = pyramid.GetInpaintArea(levelIndex);
                var inpaintAreaState = inpaintArea.GetState();
                var inpaintAreaFileName = $"ia{levelIndex}.json";
                var inpaintAreaData = JsonConvert.SerializeObject(inpaintAreaState);
                BlobHelper.SaveJsonToBlob(inpaintAreaData, container, inpaintAreaFileName);
                cloudPyramid.Levels[levelIndex].InpaintArea = inpaintAreaFileName;

                cloudPyramid.Levels[levelIndex].Nnf = $"nnf{levelIndex}.json";

                var mapping = pyramid.GetMapping(levelIndex);
                var mappingFileName = $"map{levelIndex}.json";
                var mapState = mapping.GetState();
                var mappingData = JsonConvert.SerializeObject(mapState);
                BlobHelper.SaveJsonToBlob(mappingData, container, mappingFileName);
                cloudPyramid.Levels[levelIndex].Mapping = mappingFileName;

                var mappings = SplitMapping(mapping, inpaintRequest.Settings.MaxPointsAmountPerFunction, settings.PatchSize).ToArray();
                cloudPyramid.Levels[levelIndex].SplittedMappings = new string[mappings.Length];
                cloudPyramid.Levels[levelIndex].SplittedNnfs = new string[mappings.Length];
                for (var i = 0; i < mappings.Length; i++)
                {
                    var map = mappings[i];
                    mappingFileName = $"map{levelIndex}_p{i}.json";
                    mapState = map.GetState();
                    mappingData = JsonConvert.SerializeObject(mapState);
                    BlobHelper.SaveJsonToBlob(mappingData, container, mappingFileName);
                    cloudPyramid.Levels[levelIndex].SplittedMappings[i] = mappingFileName;
                    cloudPyramid.Levels[levelIndex].SplittedNnfs[i] = $"nnf{levelIndex}_p{i}.json";
                }
            }

            return cloudPyramid;
        }