I've been having a go at speeding up the following code snippet, but I've got no idea where to start.
I have a function denoise(i, j) that takes a matrix index  i, j as an input and returns an element p. The function denoise is able to reference the matrix to which the index refers.
The intention is to input an image matrix M, and return a target image T where T(i,j) = denoise(i,j) for all i,j in M
My code at the moment is very slow because it uses for loops. What's the best place to start to speed it up?
target = zeros(rows_in_M, cols_in_M)
for i=1:rows_in_M
    for j=1:cols_in_M
        target(i, j) = denoise(i,j)
    end
end
 
    