(double[][] grayValues)
| 53 | // converts a double matrix of values into a normalized picture |
| 54 | // values are normalized by the maximum grayscale value (ignoring border pixels) |
| 55 | public static Picture doubleToPicture(double[][] grayValues) { |
| 56 | |
| 57 | // each 1D array in the matrix represents a single column, so number |
| 58 | // of 1D arrays is the width, and length of each array is the height |
| 59 | int width = grayValues.length; |
| 60 | int height = grayValues[0].length; |
| 61 | |
| 62 | Picture picture = new Picture(width, height); |
| 63 | |
| 64 | // maximum grayscale value (ignoring border pixels) |
| 65 | double maxVal = 0; |
| 66 | for (int col = 1; col < width-1; col++) { |
| 67 | for (int row = 1; row < height-1; row++) { |
| 68 | if (grayValues[col][row] > maxVal) |
| 69 | maxVal = grayValues[col][row]; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (maxVal == 0) |
| 74 | return picture; // return black picture |
| 75 | |
| 76 | for (int col = 0; col < width; col++) { |
| 77 | for (int row = 0; row < height; row++) { |
| 78 | float normalizedGrayValue = (float) grayValues[col][row] / (float) maxVal; |
| 79 | if (normalizedGrayValue >= 1.0f) normalizedGrayValue = 1.0f; |
| 80 | picture.set(col, row, new Color(normalizedGrayValue, normalizedGrayValue, normalizedGrayValue)); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return picture; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | // This method is useful for debugging seams. It overlays red |
no outgoing calls
no test coverage detected