Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 快速傅里叶变换出错了_Javascript_Opencv_Image Processing_Fft - Fatal编程技术网

Javascript 快速傅里叶变换出错了

Javascript 快速傅里叶变换出错了,javascript,opencv,image-processing,fft,Javascript,Opencv,Image Processing,Fft,我尝试使用以下代码实现FFT: 下面是我得到的结果的屏幕截图: 以下是我在图像上使用上述FFT的代码: function fastFourier(img){ let height=img.rows; let width=img.cols; let tmp=createArray(height,width); let temp=createArray(height,width); let rows=createArray(height,width); let prettypls=img.clo

我尝试使用以下代码实现FFT:

下面是我得到的结果的屏幕截图:

以下是我在图像上使用上述FFT的代码:

function fastFourier(img){

let height=img.rows;
let width=img.cols;
let tmp=createArray(height,width);
let temp=createArray(height,width);
let rows=createArray(height,width);
let prettypls=img.clone();

//new complex array
for(i=0;i<height;i++){
  for(j=0;j<width;j++){
  rows[i][j]=new Complex(0, 0);
    }
}

//put pixel values in complex array
if(height%2==0&&width%2==0){
  for ( y = 0; y < height; y++) {
    for ( x = 0; x < width; x++) {
    let pixel = img.ucharPtr(y,x);
    rows[y][x].re=pixel[0];
  }
}

//perform fft
for(y=0;y<height;y++){
  tmp[y]=cfft(rows[y]);
}

//take the magnitudes
for(i=0;i<height;i++){
  for(j=0;j<width;j++){
    temp[i][j]=Math.round(tmp[i][j].re);
  }
}

//do a log transform
temp=logTransform(temp,height,width);

//put the real values into Mat
for(i=0;i<height;i++){
  for(j=0;j<width;j++){
    let pixel = prettypls.ucharPtr(i,j);
    pixel[0]=Math.round(temp[i][j]);
  }
}
cv.imshow('fourierTransform', prettypls);
rows=[];temp=[];tmp=[];prettypls.delete();
}
else alert('Image size must be a power of 2.');
}
函数快速傅里叶变换(img){
让高度=img.rows;
让宽度=img.cols;
设tmp=createArray(高度、宽度);
设temp=createArray(高度、宽度);
让行=createArray(高度、宽度);
设prettypls=img.clone();
//新型复合阵列

对于(i=0;i您得到的正是您所要求的:对于图像中的每一行,对该行中的强度频率进行分析。您的代码将每一行视为一个单独的样本数组,并对其进行FFT

您可能需要的是如下所述的二维FFT:


现在,您只是在计算一系列一维FFT,这是不一样的。

您得到的正是您所要求的:对于图像中的每一行,分析该行中的强度频率。您的代码将每一行视为单独的样本数组,并对其进行FFT

您可能需要的是如下所述的二维FFT:

现在,你只是在计算一系列一维FFT,这是不一样的。

在他的回答中,你想说的是,你需要在你得到的结果的列上计算FFT

二维DFT是可分离的。这意味着它可以通过沿每一行,然后沿结果的每一列计算一维DFT来计算。或者等效地,先沿列,然后沿行。

在他的回答中,你想说的是,你需要在你得到的结果的列上计算FFT

二维DFT是可分离的。这意味着它可以通过沿每一行,然后沿结果的每一列,或者等效地,先沿列,然后沿行,来计算

function logTransform(img,h,w){
//https://homepages.inf.ed.ac.uk/rbf/HIPR2/pixlog.htm
let max=findMax2d(img,h,w);
let c=255/(Math.log(1+max));
for(i=0;i<h;i++){
  for(j=0;j<w;j++){
    img[i][j]=c*Math.log(1+Math.abs(img[i][j]));
  }
}
return img;
}