예제 #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.");
    }
예제 #2
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 + "\".");
    }
예제 #3
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);
    }
예제 #4
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.");
    }