I am trying to implement what is stated in a research paper. It describes how to extract Fourier features from images. I tried to follow the steps while coding but repeatedly faced errors related to datatypes and dimensions of the input array. So I ask that how to input complex values to the function
I have followed the following instructions from the research paper
Fourier Descriptors: Fourier descriptors provide a way to encode an image boundary by mapping every pixel position ( x , y ) into a complex number ( x + i y ).
- Record the coordinate values of each pixel sequentially (moving clockwise along the shape)
- Construct a complex-valued vector using coordinate values recorded in step 1 i.e., ( x , y ) → ( x + i y ) .
- Take DFT of the complex-valued vector
My problem comes at step 3
This is my implementation
def get_dft(image):
coordinates = cv.findNonZero(image)
# the code below removes an unnecessary dimension
coordinates = coordinates.reshape(coordinates.shape[0], 2)
y = coordinates[:, 1] * 1j # convert to complex numbers
# the code below removes an unnecessary dimension
y = y.reshape(coordinates.shape[0], 1)
x = coordinates[:, 0].reshape(coordinates.shape[0], 1)
# the statement below will convert from two separate arrays
# to a single array with each element
# of the form [a + jb]
t = x + y
# below is where the error occurs
dft = cv.dft(t, flags=cv.DFT_COMPLEX_INPUT)
This is the error I get
TypeError: Expected cv::UMat for argument 'src'
when I convert as
a = numpy.ndarray(t)
I get
ValueError: sequence too large; cannot be greater than 32
It wants to say there are greater than 32 dimensions. I don't understand why that happens
and When I try as
a = numpy.ndarray([t])
I get the error
TypeError: only integer scalar arrays can be converted to a scalar index
In short I want to follow the steps as mentioned in the paper, make a complex valued vector like
[[a+jb],[c+jd]...]
and pass it to the DFT function.