A matrix is just the mathematical description for the idea backing the array that identifies your picture bits. If you can't store it in a "matrix" then you don't have enough memory on your computer.
If you don't have enough memory to support the image, you can divide the image into x parts and do the work in iterations. There are plenty of algorithms for performing the grayscale conversion on raster graphics, pick one w/ an efficiency that matches your needs. You can pickup a
pre-built for the graph.
Good coding involves knowing one's logical limits and expanding them as necessary.