static void Main(string[] args) { GrayscaleFloatImage input_image = ImageIO.FileToGrayscaleFloatImage(args[0]); input_image = ExtendedRD(input_image, 4); //input_image = temp_func(input_image, 2); ImageIO.ImageToFile(input_image, args[2]); }
static GrayscaleFloatImage ExtendedRD(GrayscaleFloatImage img, int steps, int start = 1) { int[,] ridges_amount = new int[img.Width, img.Height]; double sigma = Math.Pow(Math.Sqrt(2), start - 1); GrayscaleFloatImage[] image_array = new GrayscaleFloatImage[steps]; GrayscaleFloatImage[] new_image_array = new GrayscaleFloatImage[steps]; int rad = 0; for (int i = 0; i < steps; ++i, sigma *= Math.Sqrt(2)) { var t = matrix_der2(img, (float)sigma); var matr = _solve_matr(t); image_array[i] = RD(matr); new_image_array[i] = nonmax(image_array[i].ToColorFloatImage(), (float)sigma); ImageIO.ImageToFile(new_image_array[i], "a_" + i.ToString() + ".bmp"); new_image_array[i] = img_expansion(new_image_array[i].ToColorFloatImage(), "odd", rad).ToGrayscaleFloatImage(); } int MAGIC_NUMBER = 3; for (int i = 0; i < steps; ++i) { for (int y = 0; y < img.Height; ++y) { for (int x = 0; x < img.Width; ++x) { if (image_array[i][x, y] > 0) { ridges_amount[x, y]++; } } } } GrayscaleFloatImage out_img = new GrayscaleFloatImage(img.Width, img.Height); for (int y = 0; y < img.Height; ++y) { for (int x = 0; x < img.Width; ++x) { if (ridges_amount[x, y] >= MAGIC_NUMBER) { for (int i = steps - MAGIC_NUMBER - 1; i >= 0; --i) { bool f = true; for (int j = 0; j < MAGIC_NUMBER; ++j) { bool an_f = false; for (int a = -rad; a <= rad; ++a) { for (int b = -rad; b <= rad; ++b) { if (new_image_array[i][x + rad + a, y + rad + b] > 0 && !an_f) { if (out_img[x, y] == 0) { out_img[x, y] = new_image_array[i + j][x + rad + a, y + rad + b]; } an_f = true; } } } if (!an_f) { f = false; out_img[x, y] = 0; } } if (f) { //out_img[x, y] /= MAGIC_NUMBER; break; } } } } } return(out_img); }