Ejemplo n.º 1
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests PGMA_EXAMPLE, PGMA_WRITE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const string output_name = "pgma_io_test01.ascii.pgm";
        const int    xsize       = 300;
        const int    ysize       = 300;

        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  PGMA_EXAMPLE sets up ASCII PGM data.");
        Console.WriteLine("  PGMA_WRITE writes an ASCII PGM file.");
        Console.WriteLine("");
        Console.WriteLine("  Writing the file \"" + output_name + "\".");

        int[] g = new int[xsize * ysize];

        PGMA.pgma_example(xsize, ysize, ref g);

        Console.WriteLine("");
        Console.WriteLine("  PGMA_EXAMPLE has set up the data.");

        PGMA.pgma_write(output_name, xsize, ysize, g);

        Console.WriteLine("");
        Console.WriteLine("  PGMA_WRITE was successful.");

        //
        //  Now have PGMA_READ_TEST look at the file we think we created.
        //
        PGMA.pgma_read_test(output_name);

        Console.WriteLine("");
        Console.WriteLine("  PGMA_READ_TEST was able to read our file.");
    }
Ejemplo n.º 2
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("");
    }
Ejemplo n.º 3
0
    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 + "\".");
    }
Ejemplo n.º 4
0
    public static bool pgmb_to_pgma(string file_in_name, string file_out_name)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PGMB_TO_PGMA converts one PGMB file to PGMA format.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 May 2006
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, char *FILE_IN_NAME, the name of the input PGMB file.
    //
    //    Input, char *FILE_OUT_NAME, the name of the output PGMA file.
    //
    //    Output, bool HANDLE, is true if an error occurred.
    //
    {
        int[] g     = null;
        int   maxg  = 0;
        int   xsize = 0;
        int   ysize = 0;
        //
        //  Read the input file.
        //
        bool error = pgmb_read(file_in_name, ref xsize, ref ysize, ref maxg, ref g);

        switch (error)
        {
        case true:
            Console.WriteLine("");
            Console.WriteLine("PGMB_TO_PGMA: Fatal error!");
            Console.WriteLine("  PGMB_READ failed.");
            return(true);
        }
        //
        //  Check the data.
        //
        error = pgmb_check_data(xsize, ysize, maxg, g);

        switch (error)
        {
        case true:
            Console.WriteLine("");
            Console.WriteLine("PGMB_TO_PGMA: Fatal error!");
            Console.WriteLine("  PGMB_CHECK_DATA reports bad data from the file.");

            return(true);
        }
        //
        //  Convert the data.
        //
        // ucvec_to_i4vec ( xsize * ysize, g, g2 );
        //
        //  Write the output file.
        //
        try
        {
            PGMA.pgma_write(file_out_name, xsize, ysize, g);
        }
        catch (Exception)
        {
            Console.WriteLine("");
            Console.WriteLine("PGMB_TO_PGMA: Fatal error!");
            Console.WriteLine("  PGMA_WRITE failed.");
        }
        return(true);
    }
Ejemplo n.º 5
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests PGMA_READ_HEADER, PGMA_READ_DATA.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const string input_name = "pgma_io_test02.ascii.pgm";

        int[] g = new int[1];
        int   k;
        int   maxg  = 0;
        int   xsize = 0;
        int   ysize = 0;

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  PGMA_READ reads the header and data of an ASCII PGM file.");
        Console.WriteLine("");
        Console.WriteLine("  Reading the file \"" + input_name + "\".");
        //
        //  Create a data file to read.
        //
        PGMA.pgma_write_test(input_name);

        Console.WriteLine("");
        Console.WriteLine("  PGMA_WRITE_TEST created some test data.");
        //
        //  Now have PGMA_READ try to read it.
        //
        PGMA.pgma_read(input_name, ref xsize, ref ysize, ref maxg, ref g);

        Console.WriteLine("");
        Console.WriteLine("  PGMA_READ read the test data successfully.");

        Console.WriteLine("");
        Console.WriteLine("  Sample data:");
        Console.WriteLine("");
        for (k = 0; k <= 9; k++)
        {
            int i = ((9 - k) * 0 + k * (xsize - 1)) / 9;
            int j = ((9 - k) * 0 + k * (ysize - 1)) / 9;
            Console.WriteLine(i.ToString().PadLeft(4) + "  "
                              + j.ToString().PadLeft(4) + "  "
                              + g[i * ysize + j].ToString().PadLeft(6) + "");
        }
    }
Ejemplo n.º 6
0
    private static void test03()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests PGMA_WRITE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int NGRAY = 11;

        const string output_name = "pgma_io_test03.ascii.pgm";

        double[] gray =
        {
            0.000, 0.291, 0.434, 0.540, 0.629,
            0.706, 0.774, 0.837, 0.895, 0.949,
            1.000
        };
        int       i;
        const int xsize = 300;
        const int ysize = 300;

        Console.WriteLine("");
        Console.WriteLine("TEST03:");
        Console.WriteLine("  PGMA_WRITE writes an ASCII PGM file.");
        Console.WriteLine("");
        Console.WriteLine("  In this example, we make a sort of grayscale");
        Console.WriteLine("  checkerboard.");

        int[] g = new int[xsize * ysize];

        for (i = 0; i < xsize; i++)
        {
            int j;
            for (j = 0; j < ysize; j++)
            {
                int k = (i + j) * NGRAY / Math.Min(xsize, ysize);
                k %= NGRAY;
                g[i * ysize + j] = (int)(255.0E+00 * gray[k]);
            }
        }

        Console.WriteLine("  Writing the file \"" + output_name + "\".");

        PGMA.pgma_write(output_name, xsize, ysize, g);

        Console.WriteLine("");
        Console.WriteLine("  PGMA_WRITE was successful.");
    }