Esempio n. 1
0
        /// <summary>
        /// extra_padding.pdf
        /// </summary>
        /// <param name="image"></param>
        /// <param name="imageCorners"></param>
        /// <param name="invalidColor"></param>
        /// <returns></returns>
        public static double GetExtraPaddingPercent(Bitmap image, ImageCorners imageCorners, Color invalidColor)
        {
            var diffPercentLeft = GetDiffPercentOnLeft(imageCorners, image, invalidColor);

            var diffPercentRight = GetDiffPercentOnRight(imageCorners, image, invalidColor);

            //return the max between the two
            return(diffPercentLeft > diffPercentRight? diffPercentLeft : diffPercentRight);
        }
Esempio n. 2
0
 public static ImageCorners GetActualImageCorners(ImageCorners clickImgCorners, Image image, IList <ClickPositionOnImage> clickInput)
 {
     return(new ImageCorners
     {
         Left = clickImgCorners.Left * image.Width / clickInput[0].AllowedWidth,
         Right = clickImgCorners.Right * image.Width / clickInput[0].AllowedWidth,
         Bottom = clickImgCorners.Bottom * image.Height / clickInput[0].AllowedHeight,
         Top = clickImgCorners.Top * image.Height / clickInput[0].AllowedHeight
     });
 }
Esempio n. 3
0
        private static ImageCorners GetImgCornersWithExtraPadding(ImageClickInputDetails clickInputs, Bitmap image, ImageAlterationParams imageAlterationParams)
        {
            //image corners with respect to the dimensions of click area
            var clickImgCorners = ImageCorners.GetImageCornersFromClickInputs(clickInputs, imageAlterationParams.MinImageHeightRatio, imageAlterationParams.BottomPaddingPercent);

            //image corners in actual image dimension
            var actualImgCorners = ImageCorners.GetActualImageCorners(clickImgCorners, image, clickInputs.ClickPositionListForImages);

            //image corners with extra padding on on each side of disc
            return(GetModifiedImgCornersForExtraWidth(actualImgCorners, imageAlterationParams.PercentExtraWidth));
        }
Esempio n. 4
0
 private static bool CheckForModelPixelInYDirection(ImageCorners imageCorners, double x, Bitmap image, Color invalidColor)
 {
     for (var y = imageCorners.Top; y <= imageCorners.Bottom; y++)
     {
         var pixel = image.GetPixel((int)x, (int)y);
         if (pixel.R != invalidColor.R || pixel.G != invalidColor.G || pixel.B != invalidColor.B)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
        private static ImageCorners GetModifiedImgCornersForExtraWidth(ImageCorners origCorners, double percentExtraWidth)
        {
            var extraOnEachSide = percentExtraWidth * origCorners.Width / 100.0;

            //return modified left and right based on extraOnEachSide
            return(new ImageCorners
            {
                Left = origCorners.Left - extraOnEachSide,
                Right = origCorners.Right + extraOnEachSide,
                Top = origCorners.Top,
                Bottom = origCorners.Bottom
            });
        }
Esempio n. 6
0
        private static double GetDiffPercentOnRight(ImageCorners imageCorners, Bitmap image, Color invalidColor)
        {
            double x;
            var    noOfModelPixelsAlongX = 0;

            for (x = imageCorners.Right + 1; x < image.Width; x++)
            {
                if (!CheckForModelPixelInYDirection(imageCorners, x, image, invalidColor))
                {
                    break;
                }
                noOfModelPixelsAlongX++;
            }
            return(noOfModelPixelsAlongX * 100.0 / imageCorners.Width);
        }
Esempio n. 7
0
        /// <summary>
        /// The width of the object can be more than the diameter of the base disc
        /// In such scenarios, we will need to keep some extra padding on each side of disc
        /// while cropping the image. This function calculates the amount by which we should pad.
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        public static double GetExtraPadding(CreateMeshContract contract)
        {
            var maxExtraPaddingPercent = 0.0;
            var bottomPaddingPercent   = contract.BottomPaddingPercent;

            //for each image
            foreach (var clickInput in contract.ClickInputs.ImageClickInputDetailsList)
            {
                var imageName = clickInput.ImageName;

                var bitmapImg = (Bitmap)Image.FromFile(string.Format(@"{0}\{1}", contract.ImageFolder, imageName));

                //resize to 100 (small size)
                const int newWidth  = 100;
                var       newHeight = newWidth * bitmapImg.Height / bitmapImg.Width;

                var imageAlterationParams = new ImageAlterationParams
                {
                    ResizeType           = ResizeType.ToSpecifiedSizes,
                    SpecificResizeHeight = newHeight,
                    SpecificResizeWidth  = newWidth
                };

                var resizedImage = ImageResizer.ResizeImage(bitmapImg, imageAlterationParams);

                //strip background
                BackgroundStripper.StripBackground(resizedImage, contract.BackgroundStrippingParams);

                //get actual borders for this image
                var origImageCorners   = ImageCorners.GetImageCornersFromClickInputs(clickInput, contract.MinImageHeightRatio, bottomPaddingPercent);
                var actualImageCorners = ImageCorners.GetActualImageCorners(origImageCorners, resizedImage, clickInput.ClickPositionListForImages);

                //calculate extra padding percent
                var padding = ExtraPadding.GetExtraPaddingPercent(resizedImage, actualImageCorners,
                                                                  contract.InvalidColor);

                //check if it is more than the maximum so far
                if (maxExtraPaddingPercent < padding)
                {
                    maxExtraPaddingPercent = padding;
                }
            }
            return(maxExtraPaddingPercent);
        }