Comments (9)
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.
from numpy.net.
And no huge data like images please.
from numpy.net.
test.py:
import cv2
import numpy as np
img = cv2.imread("green.tif", cv2.IMREAD_GRAYSCALE)
fft_img = np.fft.fft2(img)
fft_img = np.fft.fftshift(fft_img)
print(fft_img.size)
python3 ./test.py
the above code is very work. any kind of image like tif or png is OK .
from numpy.net.
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.
from numpy.net.
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 ??
from numpy.net.
Image<Gray, byte> img = new Image<Gray, byte>(args[0]);
var data = img.Mat.GetRawData();
var ndasrc = np.asfarray(data);
var ndaFFT = np.fft.fft2(ndasrc); //failed here ->
By doing a GetRawData you get a 1D array and you create a 1D arra ndasrc
from it. I guess you need to reshape it so that it has the dimensions of the image.
from numpy.net.
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
from numpy.net.
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:
var file = args.Length > 0 ? args[0] : @"..\..\..\..\green.tif";
Image<Gray, byte> img = new Image<Gray, byte>(file);
var data = img.Mat.GetRawData();
var ndasrc = np.asfarray(data);
var reshape = ndasrc.reshape(img.Height, img.Width);
var ndaFFT = np.fft.fft2(reshape);
var fftShift = np.fft.fftshift(ndaFFT);
...
Thanks you very much.
BTW, hou can i convert the NDArray back to CLR types ?
var file = args.Length > 0 ? args[0] : @"..\..\..\..\green.tif";
Image<Gray, byte> img = new Image<Gray, byte>(file);
var data = img.Mat.GetRawData();
var ndasrc = np.asfarray(data);
var reshape = ndasrc.reshape(img.Height, img.Width);
byte[,] backraw = null; //which API can make reshape convert (boxing) back to backraw ??
from numpy.net.
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
from numpy.net.
Related Issues (20)
- Error on visualisation of NDArray in dotnet interactive jupyter notebook HOT 3
- Cannot slice by passing either a string or a Numpy.Models.Slice as an index. HOT 6
- Slow Conversion for 3D arrays HOT 3
- np.load of np.savez impossible to get values back out? HOT 3
- np.array leaks memory HOT 12
- Numpy hangs on exit since version 3.10.1.29 (last stable 3.7.1.28) HOT 7
- Support for CuPy HOT 1
- Please Sign and assign StrongName for Numpy Nuget package
- np.split HOT 12
- `Half` type arrays HOT 7
- Set conditions as NDArray Type HOT 3
- Problem with passing imaginery numbers HOT 3
- NDarray of DateTime HOT 3
- Azure AppService and System.DllNotFoundException: Could not load python311.dll with flags RTLD_NOW | RTLD_GLOBAL: python311.dll: cannot open shared object file: No such file or directory HOT 5
- Could not find platform dependent libraries <exec_prefix> HOT 6
- System.TypeLoadException: Could not load type 'Python.Runtime.PyLong' from assembly 'Python.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd'. HOT 5
- Numpy.Bare build for Python 3.11 HOT 3
- np.sum(NDArray, axis:1) not supported? HOT 5
- Unable to use Numpy.NET from linux environment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numpy.net.