I have large 2d matrices from dicom files that i wish to filter with a 3x3 mask. the image arrays are of varying size and are padded with one border of zeros for the edge handling of the mask. i need to iterate over every element in the array and multiply it by the mask. ive done it in SciLab but so far in python i have the padded image matrix and the 3x3 mask ready to go i just need to get the syntax right.(adsbygoogle = window.adsbygoogle || []).push({});

g is the image matrix usually about 600 by 800, i.e. not square

w is the 3x3 filter

the function is SciLab is as follows

i, j and m,n refers to the array elements of the image matrix and the filter but it doesnt work like that in python.Code (Text):for i=1:m;

for j=1:n;

g(i,j)= g(i,j)*w(1,1)+g(i+1,j)*w(2,1)+g(i+2,j)*w(3,1)...

+g(i,j+1)*w(1,2)+g(i+1,j+1)*w(2,2)+g(i+2,j+1)*w(3,2)...

+g(i,j+2)*w(1,3)+g(i+1,j+2)*w(2,3)+g(i+2,j+2)*w(3,3);

end

end

Im just having trouble with the syntax conversions.

Thanks

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Spatial Filtering 2d numpy array with a 3x3 mask

Have something to add?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**