0
$\begingroup$

For increasing the image size from 8X8 to 32X32, I tried to do zero padding. The simplest concept of zero padding in Java for me seems to be the code as shown below in Java such that I can shift each point by 4 points while rescaling.

for (int i = 0; i < imageWidth; i += 4) 
        for (int j = 0; j < imageHeight; j += 4) 
            pspectrum[i][j] = powerspectrum[(i + 1)/4][(j + 1)/4];

Now, what I am mainly concerned is that is there any more accurate method and how this helps with my calculation.

$\endgroup$
  • $\begingroup$ What you're doing there is way more than zero padding. Ollie's answer is better: zero-fill the new array, and then put the previous array in the appropriate corner of the new one. $\endgroup$ – Peter K. Sep 25 '15 at 12:18
2
$\begingroup$

I suppose the array names are not descriptive of the contents and you have simply repurposed them. To zero-pad from 8x8 to 32x32:

for (int i = 0; i < 32; i++) 
    for (int j = 0; j < 32; j++) 
        pspectrum[i][j] = 0;
for (int i = 0; i < 8; i++) 
    for (int j = 0; j < 8; j++) 
        pspectrum[i][j] = powerspectrum[i][j];

The purpose of this is that the discrete Fourier transform (DFT) of a larger image has a higher frequency resolution, so you can resolve for example the dominant frequency more accurately. It is the same as really well done interpolation in the frequency domain.

$\endgroup$
  • $\begingroup$ I think this way the whole image information will be concentrated at one corner of the image, mainly the corner referring to (0,0) for the image and two edges of the image will be highly zero-padded and two will remain the same. If the original image is at the image centre then it may be surely helpful. $\endgroup$ – Psi Lambda Delta Sep 25 '15 at 17:56
  • $\begingroup$ DFT is a periodic transform: the input is periodic and the array contains one period. The edges you think won't be padded will be padded by zeros on the opposite side of the 32x32 image. Translation in the spatial domain equals a phase shift in the frequency domain, which won't affect the magnitudes of the frequency bins. So you don't need to translate the 8x8 image in any particular way if you are only going to look at the bin magnitudes. $\endgroup$ – Olli Niemitalo Sep 26 '15 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.