The first and easiest change is to get rid of any for loops. for example if you want to multiply each element of [3,2,4] by its corresponding number in [5;2;4] you can say [3,2,4] .* [5;2;4] instead of using a for loop.
Also make sure to put a ; at the end of each line of code so that it does not need to print things to the screen, this can also greatly speed your code up.
Also what function are you using to read the image in with? imread() is usually the quickest.