public static Picture doubleToPicture(double[][] grayValues)
    {

        //each 1D array in the matrix represents a single column, so number
        //of 1D arrays is the width, and length of each array is the height
        int width = grayValues.length;
        int height = grayValues[0].length;

        Picture p = new Picture(width, height);

        double maxVal = 0;
        for (int i = 0; i < width; i++)
            for (int j = 0; j < height; j++)
                if (grayValues[i][j] > maxVal)
                    maxVal = grayValues[i][j];

        if (maxVal == 0)
            return p; //return black picture

        for (int i = 0; i < width; i++)
            for (int j = 0; j < height; j++)
            {
                float normalizedGrayValue = (float) grayValues[i][j] / (float) maxVal;
                p.set(i, j, new Color(normalizedGrayValue, normalizedGrayValue, normalizedGrayValue));
            }

        return p;
    }