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 }); }
/// <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 var max = diffPercentLeft > diffPercentRight? diffPercentLeft : diffPercentRight; return(max + 5); //take a little extra to be on the safe side }
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)); }
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); }
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 }); }
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); }