# Code Discrete Fourier Transform Image

**URL:** <https://forum.opencv.org/t/code-discrete-fourier-transform-image/9805>\
**Category:** C++\
**Tags:** programming\
**Created:** [August 10, 2022, 2:37pm UTC](https://forum.opencv.org/t/code-discrete-fourier-transform-image/9805 "2022-08-10T14:37:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ismail1](https://avatars.discourse-cdn.com/v4/letter/i/d6d6ee/32.png) [@Ismail1](https://forum.opencv.org/u/Ismail1)\
**Post date:** [August 10, 2022, 2:37pm UTC](https://forum.opencv.org/t/code-discrete-fourier-transform-image/9805/1 "2022-08-10T14:37:55Z")

</div>

Hello everybody, I have found the code for Discrete Fourier Transform of an image here : [OpenCV: Discrete Fourier Transform](https://docs.opencv.org/4.x/d8/d01/tutorial_discrete_fourier_transform.html)  
However I don’t get how they croped the spectrum when it has an odd number of columns or rows that is : magI.cols & -2 and/or magI.rows & -2 inside the Rect…  
I found that the & is a bitand operator that is it compares each bits of what is before the & to the bits of what is after the & and if both are 1 it keeps it at 1. Else it puts the bit to 0.  
My Question is why do we compare the bits of magI.cols and magI.rows to those of -2 and not simply 2 ? Does anyone can explain ?

Thank you for reading

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 10, 2022, 3:43pm UTC](https://forum.opencv.org/t/code-discrete-fourier-transform-image/9805/2 "2022-08-10T15:43:39Z")

</div>

```python
>>> bin(np.uint8(-2))
'0b11111110'
>>> a = np.arange(-5, +6)
>>> np.column_stack([a, a & -2])
array([[-5, -6],
       [-4, -4],
       [-3, -4],
       [-2, -2],
       [-1, -2],
       [0, 0],
       [1, 0],
       [2, 2],
       [3, 2],
       [4, 4],
       [5, 4]])

```

that’s unrelated to OpenCV. that’s just how computers work, how integer arithmetic works.

---

<div class="post-metadata">

**Author:** ![Ismail1](https://avatars.discourse-cdn.com/v4/letter/i/d6d6ee/32.png) [@Ismail1](https://forum.opencv.org/u/Ismail1)\
**Post date:** [August 10, 2022, 4:31pm UTC](https://forum.opencv.org/t/code-discrete-fourier-transform-image/9805/3 "2022-08-10T16:31:58Z")

</div>

Thank you crackwitz. I now understand how it works, it returns the closest lower even value.  
bin(np.uint8(-2))=bin(np.uint8(254))…
