Hi,
A while back, I asked if there was any way I could convert an axis into an image matrix. I was pointed to export_fig, which while certainly is functional takes a while for each image you export. The program I am running converts 90 figures into matrices, so you can see how this time adds up. Additionally, I will need to use the same program for a much larger dataset soon, so I'd really like to increase the program efficiency if I can. Essentially, I have several shapes stored in a .mat file which must be converted into an image matrix of 1's (area of a shape) and 0's (area of nothing).
My current process is as follows:
- Create a current axis of the same dimensions as the final image.
- Draw a solid black image to the current axis.
- Load each shape to the workspace and draw on the current axis (on top of the black).
- Export the current figure with export_fig into an image matrix.
- Sum the resulting image matrix (so that you have a 2D matrix instead of a 3D/RGB matrix)
- Divide the image matrix by itself so that all 0's remain 0 but all non-zero values are converted to 1.
I wanted to reclarify my initial question and see if anyone else had additional ideas. I need a tool/method that:
- Draws several shapes on an axis which are stored from a .mat file.
- Creates a matrix of zeros of the same dimensions (e.g., a 1600 x 900 axis would become imgMatrix = zeros(900,1600))
- For every pixel with color, the corresponding location in the matrix becomes a 1 (e.g., if 1400,700 falls within a shape then imgMatrix(700,1400) = 1)
To sum, I start with nothing but several shapes stored in a .mat file. I need to end up with a matrix which contains those shapes "drawn" onto the matrix where 1's represent area covered by the shape and 0's represent area outside of the shapes.
Best Answer