public void Should_Throw_InitializationException_When_No_Image_Was_Added() { // Arrange var pyramidBuilder = new PyramidBuilder(); Action act = () => pyramidBuilder.Build(2); // Act & Assert act.ShouldThrow <InitializationException>(); }
public void Should_Throw_ArgumentOutOfRangeException_When_Levels_Amount_Less_Then_1() { // Arrange byte levelsAmount = 0; var pyramidBuilder = new PyramidBuilder(); Action act = () => pyramidBuilder.Build(levelsAmount); // Act & Assert act.ShouldThrow <ArgumentOutOfRangeException>(); }
public void Should_Not_Throw_When_Can_Be_Divided_Levels_Amount_Times(int width, int height, byte levelsAmount) { // Arrange var image = CreateImage(width, height); var markup = CreateImage(width / 2, height / 2); var pyramidBuilder = new PyramidBuilder(); pyramidBuilder.Init(image, markup); Action act = () => pyramidBuilder.Build(levelsAmount); // Act & Assert act.ShouldNotThrow(); }
public void Should_Throw_WrongImageSizeException_When_Image_Downscaled_To_1px_On_Any_Side(int width, int height, byte levelsAmount) { // Arrange var image = CreateImage(width, height); var markup = CreateImage(width / 2, height); var pyramidBuilder = new PyramidBuilder(); pyramidBuilder.Init(image, markup); Action act = () => pyramidBuilder.Build(levelsAmount); // Act & Assert act.ShouldThrow <WrongImageSizeException>(); }
public void Should_Build_Pyramid_Of_Required_Level_High(int width, int height, byte levelsAmount) { // Arrange var image = CreateImage(width, height); var markup = CreateImage(width / 2, height / 2); var pyramidBuilder = new PyramidBuilder(); pyramidBuilder.Init(image, markup); // Act var pyramid = pyramidBuilder.Build(levelsAmount); // Assert pyramid.LevelsAmount.ShouldBe <byte>(levelsAmount); }
public void Should_Throw_AreaRemovedException_When_Markup_Covers_Whole_Image() { // Arrange int width = 128; int height = 128; byte levelsAmount = 3; var image = CreateImage(width, height); var markup = CreateImage(width, height); var pyramidBuilder = new PyramidBuilder(); pyramidBuilder.Init(image, markup); Action act = () => pyramidBuilder.Build(levelsAmount); // Act & Assert act.ShouldThrow <AreaRemovedException>(); }
public void Should_Throw_NoAreaToInpaintException_When_Markup_In_Image_Area_Empty() { // Arrange int width = 128; int height = 128; byte levelsAmount = 3; var image = CreateImage(width, height); var markup = Create3pixBiggerMarkupNotEmptyOutsideOfTheImage(width, height); var pyramidBuilder = new PyramidBuilder(); pyramidBuilder.Init(image, markup); Action act = () => pyramidBuilder.Build(levelsAmount); // Act & Assert act.ShouldThrow <NoAreaToInpaintException>(); }
public void Should_Use_Last_Set_Image(int width1, int height1, int width2, int height2, byte levelsAmount) { // Arrange var image1 = CreateImage(width1, height1); var image2 = CreateImage(width2, height2); var markup1 = CreateImage(width1 / 2, height1 / 2); var markup2 = CreateImage(width2 / 2, height2 / 2); var pyramidBuilder = new PyramidBuilder(); pyramidBuilder.Init(image1, markup1); pyramidBuilder.Init(image2, markup2); // Act var pyramid = pyramidBuilder.Build(levelsAmount); // Assert pyramid.LevelsAmount.ShouldBe <byte>(levelsAmount); }
public void Should_Use_Last_Set_Markup() { // Arrange int width = 128; int height = 128; byte levelsAmount = 3; var image = CreateImage(width, height); var markup1 = Create3pixBiggerMarkupNotEmptyOutsideOfTheImage(width, height); var pyramidBuilder = new PyramidBuilder(); var markup2 = CreateImage(width / 2, height / 2); // Act pyramidBuilder.Init(image, markup1); pyramidBuilder.Init(image, markup2); var pyramid = pyramidBuilder.Build(levelsAmount); // Assert pyramid.LevelsAmount.ShouldBe(levelsAmount); }
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; }
public override void BuildGeometry() { PyramidBuilder.Build(gameObject, this); }