Try to convert your gray image of 1024x1024 pixels to an other image that contain 1024x1024x3 (like an RGB image) but in your case the matrix are the same gray image
Let you new image is Im and the old gray image is im_gray
Im(:,:,1) = im_gray
Im(:,:,2) = im_gray
Im(:,:,3) = im_gray
With that i think the system will work on it like an RGB image .. but in reality its still your old gray image
For obtaining gray images you need PCA/LDA as a dimension reduction technique, see e.g., https://www.datacamp.com/community/tutorials/principal-component-analysis-in-python