Exemple #1
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for IMAGE_EDGE_TEST.
    //
    //  Discussion:
    //
    //    IMAGE_EDGE_TEST tests the IMAGE_EDGE library.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    22 July 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int          g_max = 0;
        int          i;
        const string input_filename = "coins.ascii.pgm";

        string[]     input_unit;
        int          m = 0;
        int          n = 0;
        const string output_filename = "coin_edges.ascii.pbm";

        Console.WriteLine("");
        Console.WriteLine("IMAGE_EDGE_TEST");
        Console.WriteLine("  Test the IMAGE_EDGE library.");
        Console.WriteLine("");
        Console.WriteLine("  Demonstrate the NEWS stencil for edge detection");
        Console.WriteLine("  in images.");

        Console.WriteLine("");
        Console.WriteLine("  The input file is \"" + input_filename + "\".");

        try
        {
            input_unit = File.ReadAllLines(input_filename);
        }
        catch
        {
            Console.WriteLine("");
            Console.WriteLine("IMAGE_EDGE_TEST - Fatal error!");
            Console.WriteLine("  Could not open the file \"" + input_filename + "\"");
            return;
        }

        int inputIndex = 0;

        PGMA.pgma_read_header(input_unit, ref inputIndex, ref m, ref n, ref g_max);

        Console.WriteLine("");
        Console.WriteLine("  Number of rows =          " + m + "");
        Console.WriteLine("  Number of columns =       " + n + "");
        Console.WriteLine("  Maximum pixel intensity = " + g_max + "");

        int[] g = new int[m * n];

        PGMA.pgma_read_data(input_unit, ref inputIndex, m, n, ref g);


        int[] g_histo = typeMethods.i4mat_histogram(m, n, g, 255);

        Console.WriteLine("");
        Console.WriteLine(" Gray     Count");
        Console.WriteLine("");
        for (i = 0; i <= 255; i++)
        {
            Console.WriteLine("  " + i.ToString().PadLeft(3)
                              + "  " + g_histo[i].ToString().PadLeft(8) + "");
        }

        int[] e = NEWS.news(m, n, g);
        //
        //  Write the edge information as a portable BIT map (0/1).
        //
        PBMA.pbma_write(output_filename, m, n, e);

        Console.WriteLine("");
        Console.WriteLine("  Wrote edge information to \"" + output_filename + "\".");

        //
        //  Terminate.
        //
        Console.WriteLine("");
        Console.WriteLine("IMAGE_EDGE_TEST");
        Console.WriteLine("  Normal end of execution.");
        Console.WriteLine("");
    }
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests GRAY_MEDIAN_NEWS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    22 July 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int          g_max          = 0;
        const string input_filename = "glassware_noisy.ascii.pgm";

        string[]     input_unit;
        int          m = 0;
        int          n = 0;
        const string output_filename = "glassware_median_news.ascii.pgm";

        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  GRAY_MEDIAN_NEWS uses a NEWS median filter ");
        Console.WriteLine("  on a noisy grayscale image.");

        Console.WriteLine("");
        Console.WriteLine("  The input file is \"" + input_filename + "\".");

        //
        //  Open the input file and read the data.
        //
        try
        {
            input_unit = File.ReadAllLines(input_filename);
        }
        catch (Exception)
        {
            Console.WriteLine("");
            Console.WriteLine("TEST01 - Fatal error!");
            Console.WriteLine("  Could not open the file \"" + input_filename + "\"");
            return;
        }

        int index = 0;

        PGMA.pgma_read_header(input_unit, ref index, ref m, ref n, ref g_max);

        Console.WriteLine("");
        Console.WriteLine("  Number of rows =          " + m + "");
        Console.WriteLine("  Number of columns =       " + n + "");
        Console.WriteLine("  Maximum pixel intensity = " + g_max + "");

        int[] g = new int[m * n];

        PGMA.pgma_read_data(input_unit, ref index, m, n, ref g);

        int[] g2 = NEWS.gray_median_news(m, n, g);
        //
        //  Write the denoised images.
        //
        PGMA.pgma_write(output_filename, m, n, g2);

        Console.WriteLine("");
        Console.WriteLine("  Wrote denoised image to \"" + output_filename + "\".");
    }