Implementation on neighborhood average algorithm