public static Bitmap TileWiseHoughTransform(Bitmap sourceImage) { sourceImage = ImageTools.ApplyInvert(sourceImage); sourceImage.Save(@"C:\SensorNetworks\Output\Sonograms\TestSourceImage.png"); int numberOfDirections = 16; bool saveTranformImage = true; int tileWidth = 33, tileHeight = 33; double thresholdIntensity = 2.0; //this filter converts standard pixel format to indexed as used by the hough transform var filter = Grayscale.CommonAlgorithms.BT709; int rowCount = sourceImage.Height; int colCount = sourceImage.Width; int xDirectionTileCount = colCount / tileWidth; int yDirectionTileCount = rowCount / tileHeight; Bitmap returnBmp = new Bitmap(sourceImage); Graphics g = Graphics.FromImage(returnBmp); for (int r = 0; r < yDirectionTileCount; r++) { for (int c = 0; c < xDirectionTileCount; c++) { int x = c * tileWidth; int y = r * tileHeight; Rectangle cropArea = new Rectangle(x, y, tileWidth, tileHeight); Bitmap tile = sourceImage.Clone(cropArea, sourceImage.PixelFormat); tile.Save(@"C:\SensorNetworks\Output\Sonograms\TestTile.png"); ImageTools.ApplyInvert(tile); // create and apply filter to convert to indexed color format. double[,] rtMatrix = DoHoughTransform(filter.Apply(tile), numberOfDirections, saveTranformImage); Bitmap tile2 = AddRTmatrix2Image(rtMatrix, thresholdIntensity, tile); //Bitmap tile2 = HoughTransform.ConvertRTmatrix2Image(rtMatrix, thresholdIntensity, tileWidth); g.DrawImage(tile2, x, y); tile2.Save(@"C:\SensorNetworks\Output\Sonograms\TestTile2.png"); } } return(returnBmp); } // TileWiseHoughTransform(Bitmap sourceImage)