Hi, and welcome!
Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.
Here, to test my own answer I'm flying blind without representative data and the libraries being used for the functions like rgb_2gray
. And the friction of reverse engineering the problem deters many who might answer.
It doesn't have to be *all the data, just representative, say 4x40 or whatever is big enough to yield a 64*64 image (whether or not it's the whole image. I'm thinking that a purrr:map will be quicker and easier than a loop.