public ImageMatBlackWhite ToImageBlackWhite(int threshold) { var bools = new bool[Width * Height]; for (int i = 0; i < data.Length; i++) { bools[i] = data[i].ToPixelGray() > threshold ? true : false; } ImageMatBlackWhite result = new ImageMatBlackWhite(bools, Width, Height, false); return(result); }
public HoughTransform(ImageMatBlackWhite pic, int scale) { this.image = pic; this.scale = scale; /*(x,y) => Hough-Space (θ,d) * θ:the angle between x-axis and the line which passing through (x,y) * d : the distance from origin to the line which passing through (x,y) * * * so, mathematically, * d = xcosθ + ysinθ * by The auxiliary Angle formula(辅助角公式), * max(d) = sqrt(x²+y²) * so d:[-sqrt(x²+y²),sqrt(x²+y²)] */ double maxr = Math.Sqrt((pic.Width * pic.Width + pic.Height * pic.Height)); //we need to create a array two times big because d:[-sqrt(x²+y²),sqrt(x²+y²)] maxd = (int)Math.Ceiling(maxr) + 1; hough_space = new HoughPixel[maxd * 2, scale + 1]; for (int i = 0; i < maxd * 2; i++) { for (int j = 0; j < scale + 1; j++) { hough_space[i, j].minx = int.MaxValue; hough_space[i, j].miny = int.MaxValue; hough_space[i, j].maxx = int.MinValue; hough_space[i, j].maxy = int.MinValue; } } /* * maxd*2 because d:[-sqrt(x²+y²),sqrt(x²+y²)] => d:[-maxd,maxd] * scale+1 because 0<=i<=scale */ //θ=π/scale*x,so save the tmpθ to accelerate calcaltion / ttheta = Math.PI / scale; }