Image Mat Util Code
Image Mat Util Code
'image_mat_util.py' file:
```python
def file2mat(path, row_labels = ('x', 'y', 'u')):
"""input: a filepath to an image in .png format
output: the pair (points, matrix) of matrices representing the image."""
return image2mat(image.file2image(path), row_labels)
This code defines two functions, `file2mat` and `image2mat`, that take an image
file path or an image in list-of-lists format, respectively, and return a pair of
matrices representing the image: one for the points and one for the colors.
The `image2mat` function first determines the height and width of the input image,
then creates two dictionaries, `ptsD` and `colorsD`, to store the metadata about
the points and colors in the image. It then iterates over the pixels in the image,
storing the x, y, and u (always 1) coordinates in the `ptsF` dictionary, and the
red, green, and blue values in the `colorsF` dictionary.
Finally, the function returns a pair of `mat.Mat` objects, one for the points and
one for the colors, which can be used to display the image.