hello, i am trying to compare my versus matlab's implementaion of a convolution in the frequency domain. i have a mask that is not the same size of the image (in fact its much smaller). but i fft2 the mask with the dimensions of the image and then convolve with the fft2 of the image. my question i, what method is used for zero padding the mask to be the same size of the image? can someone tell me for example of what the resulting mask would look like if my original filter was: -1 0 1 -1 0 1 -1 0 1 and my image size was 128x128? i.e. calling fft2(mask,128,128) basically i am trying to figure out if the mask stays in the center, is shoved to the bottom left, or top left etc. also trying to understand if the mask gets chopped up and centered around the middle zero and shoved to the bottom left corner. thank you, happy holidays.
how does matlab zero pad on fft
Started by ●November 27, 2003
Reply by ●November 27, 20032003-11-27
gigabyte@mutimusic.com (CDB) wrote in message news:<be5fe9bf.0311270908.52a447e3@posting.google.com>...> hello, > > i am trying to compare my versus matlab's implementaion of a > convolution in the frequency domain. > > i have a mask that is not the same size of the image (in fact its much > smaller). but i fft2 the mask with the dimensions of the image and > then convolve with the fft2 of the image. > > my question i, what method is used for zero padding the mask to be the > same size of the image? > > can someone tell me for example of what the resulting mask would look > like if my original filter was: > > -1 0 1 > -1 0 1 > -1 0 1 > > and my image size was 128x128? i.e. calling fft2(mask,128,128) > > basically i am trying to figure out if the mask stays in the center, > is shoved to the bottom left, or top left etc. > > also trying to understand if the mask gets chopped up and centered > around the middle zero and shoved to the bottom left corner. > > thank you, happy holidays.If you do like this, S=real(ifft(fft(ones(3,3),6,6))) % Note no semicolon! you will see directly where matlab inserts the zeros. Rune
Reply by ●November 27, 20032003-11-27
"Rune Allnor" <allnor@tele.ntnu.no> wrote in message news:f56893ae.0311271442.5622995c@posting.google.com...> gigabyte@mutimusic.com (CDB) wrote in messagenews:<be5fe9bf.0311270908.52a447e3@posting.google.com>...> > hello, > > > > i am trying to compare my versus matlab's implementaion of a > > convolution in the frequency domain. > > > > i have a mask that is not the same size of the image (in fact its much > > smaller). but i fft2 the mask with the dimensions of the image and > > then convolve with the fft2 of the image. > > > > my question i, what method is used for zero padding the mask to be the > > same size of the image? > > > > can someone tell me for example of what the resulting mask would look > > like if my original filter was: > > > > -1 0 1 > > -1 0 1 > > -1 0 1 > > > > and my image size was 128x128? i.e. calling fft2(mask,128,128) > > > > basically i am trying to figure out if the mask stays in the center, > > is shoved to the bottom left, or top left etc. > > > > also trying to understand if the mask gets chopped up and centered > > around the middle zero and shoved to the bottom left corner. > > > > thank you, happy holidays. > > If you do like this, > > S=real(ifft(fft(ones(3,3),6,6))) % Note no semicolon! > > you will see directly where matlab inserts the zeros.I didn't think it would insert zeros at all! I thought the size of the transform was as specified and that "fft" really means "dft" unless the dimension is 2^n. Fred
Reply by ●November 28, 20032003-11-28
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message news:<1t6dnTHLdJlOGlui4p2dnA@centurytel.net>...> "Rune Allnor" <allnor@tele.ntnu.no> wrote in message > news:f56893ae.0311271442.5622995c@posting.google.com... > > gigabyte@mutimusic.com (CDB) wrote in message > news:<be5fe9bf.0311270908.52a447e3@posting.google.com>... > > > hello, > > > > > > i am trying to compare my versus matlab's implementaion of a > > > convolution in the frequency domain. > > > > > > i have a mask that is not the same size of the image (in fact its much > > > smaller). but i fft2 the mask with the dimensions of the image and > > > then convolve with the fft2 of the image. > > > > > > my question i, what method is used for zero padding the mask to be the > > > same size of the image? > > > > > > can someone tell me for example of what the resulting mask would look > > > like if my original filter was: > > > > > > -1 0 1 > > > -1 0 1 > > > -1 0 1 > > > > > > and my image size was 128x128? i.e. calling fft2(mask,128,128) > > > > > > basically i am trying to figure out if the mask stays in the center, > > > is shoved to the bottom left, or top left etc. > > > > > > also trying to understand if the mask gets chopped up and centered > > > around the middle zero and shoved to the bottom left corner. > > > > > > thank you, happy holidays. > > > > If you do like this, > > > > S=real(ifft(fft(ones(3,3),6,6))) % Note no semicolon! > > > > you will see directly where matlab inserts the zeros. > > I didn't think it would insert zeros at all! I thought the size of the > transform was as specified and that "fft" really means "dft" unless the > dimension is 2^n. > > FredThe matlab fft (which, BTW, should be fft2 in the 2D example above) does insert zeros if you ask it to. In the example above I made a 3x3 matrix with unit elements, and ask matlab to zero pad the data to a 6x6 matrix before computing the DFT. Rune