i did it with a matrix multiplication (see attached code) but it seems much slower than the previous version with four loops.

```
for ip = (row_ext+1):(rc(1)+row_ext) %rows
for np = (col_ext+1):(rc(2)+col_ext)%columns
PF(ip,np)=sum(sum(kern.*P( (ip-row_ext):(ip+row_ext) , (np-col_ext):(np+col_ext)),1),2)/sum(sum(kern,1),2);
end
end
```