Hi, I am importing an image - gray scale, size (1440,1776,1). I wrote a simple code for performing a running average with a square filter of size 2*f+1, with f as a variable. I am not performing running average over the boundaries i.e., neglecting boundary pixels.
Leaving aside the time to import image or display image in Matlab or Julia, I see that Matlab takes about 15 seconds and Julia (35 seconds). And there is only one section of recursive code which takes up this much time. The code is: S is sums over image pixels which are in Matrix A. I declare all in the beginning. Their sizes are declared. For example, A=1.0*data(img); #This extracts the image array from img image imported through Image. It is in Uint8 but multiplying by 1.0 converts it to Float64. S=zeros(Float64,imsz); The initial values of S have been calculated in an earlier section of the code and that is pretty fast. The main slower are the following lines. The entire code takes 35 seconds to run and this one takes most of that time (~34.9seconds). p1=f+1; #for m=(f+1):(imsz[1]-f) #imsz(1)=1440, imsz(2)=1776. # for n=(f+1):(imsz[2]-f-1) for n=(f+1):(imsz[2]-f-1) for m=(f+1):(imsz[1]-f) S[m,n+1]=S[m,n]+sum(sum(A[m-f:m+f,n+p1],2))-sum(sum(A[m-f:m+f,n-f],2)); end end I tried both ways i.e., using sum and also actually summing A in a separate for loop. If I do that it takes about 60 seconds. So 'sum' is faster than looping and adding to A. I also tried first column wise and then row wise looping as you will see in the commented section. It takes the same time - does not matter which way I do the loop. Matlab code: takes about 14 seconds. p1=f+1; for m=(f+1):(imsz(1)-f) for n=(f+1):(imsz(2)-f-1) S(m,n+1)=S(m,n)+(sum(A(m-f:m+f,n+p1),2))-(sum(A(m-f:m+f,n-f),2)); end end Any suggestions? Unfortunately my codes are on two different machines. Doubt if that make a difference? 2.3GHz,4Gb RAM-Matlab 3.4GHz,8Gb RAM-Julia