-
Notifications
You must be signed in to change notification settings - Fork 100
fft() failed: “index -2 is out of bounds for axis 0 with size 1” #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you make a little snippet that doesn't depend on anything else? Show that it works in Python and that it fails in Numpy.NET. Then I can fix the problem quickly. |
And no huge data like images please. |
test.py:
the above code is very work. any kind of image like tif or png is OK . |
I have here a snippet without cv2 that works in python: >>> img = np.arange(27).reshape(3,3,3)
>>> img
array([[[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8]],
[[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]],
[[18, 19, 20],
[21, 22, 23],
[24, 25, 26]]])
>>> fft_img = np.fft.fft2(img)
>>> fft_img = np.fft.fftshift(fft_img)
>>> fft_img
array([[[ 0. +0.j , -13.5-7.79422863j, 0. +0.j ],
[ -4.5-2.59807621j, 198. +0.j , -4.5+2.59807621j],
[ 0. +0.j , -13.5+7.79422863j, 0. +0.j ]],
[[ 0. +0.j , -13.5-7.79422863j, 0. +0.j ],
[ -4.5-2.59807621j, 36. +0.j , -4.5+2.59807621j],
[ 0. +0.j , -13.5+7.79422863j, 0. +0.j ]],
[[ 0. +0.j , -13.5-7.79422863j, 0. +0.j ],
[ -4.5-2.59807621j, 117. +0.j , -4.5+2.59807621j],
[ 0. +0.j , -13.5+7.79422863j, 0. +0.j ]]])
>>> It also works in C# with Numpy.NET [TestMethod]
public async Task IssueByTimiil()
{
var img = np.arange(27).reshape(3, 3, 3);
var fft_img = np.fft.fft2(img);
fft_img = np.fft.fftshift(fft_img);
Console.WriteLine(fft_img.repr);
} So my conclusion is that the data you input is wrong. I guess the shape is wrong because I get the same error in python when I apply fft2 to a one-dimensional array. |
opencv load an image into an struct Image<Gray, byte> , which should be a 'two dimensional matrix', do i need to convert 'Image<Gray, byte>' or 'Mat' into a one-dimensional array to join fftshift method ?? |
By doing a GetRawData you get a 1D array and you create a 1D arra |
To be clear you need to do this: var data = img.Mat.GetRawData();
var ndasrc = np.asfarray(data).reshape(imagew, imageh); before doing the fft2 |
thanks very much, it is all WORK for now:
Thanks you very much. BTW, hou can i convert the NDArray back to CLR types ?
|
Getting the data of an NDarray as a C# array is documented here: https://github.com/SciSharp/Numpy.NET#create-a-numpy-array-from-a-c-array-and-vice-versa |
test.csproj:
Program.cs:
failed:
The text was updated successfully, but these errors were encountered: