Comparing version 1.3.3 to 1.3.4
{ | ||
"name": "ml-fft", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "fft", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -72,3 +72,4 @@ 'use strict' | ||
*/ | ||
fft2DArray:function(data, nRows, nCols) { | ||
fft2DArray:function(data, nRows, nCols, opt) { | ||
var options = Object.assign({},{inplace:true}) | ||
var ftCols = (nCols / 2 + 1); | ||
@@ -111,2 +112,3 @@ var ftRows = nRows * 2; | ||
var finalTransform = new Array(ftRows * ftCols); | ||
FFT.init(nRows); | ||
@@ -193,9 +195,9 @@ var tmpCols = {re: new Array(nRows), im: new Array(nRows)}; | ||
re = ftSignal[(iRow * 2) * ftCols + iCol] | ||
* ftFilter[(iRow * 2) * ftCols + iCol] | ||
- ftSignal[(iRow * 2 + 1) * ftCols + iCol] | ||
* ftFilter[(iRow * 2 + 1) * ftCols + iCol]; | ||
* ftFilter[(iRow * 2) * ftCols + iCol] | ||
- ftSignal[(iRow * 2 + 1) * ftCols + iCol] | ||
* ftFilter[(iRow * 2 + 1) * ftCols + iCol]; | ||
im = ftSignal[(iRow * 2) * ftCols + iCol] | ||
* ftFilter[(iRow * 2 + 1) * ftCols + iCol] | ||
+ ftSignal[(iRow * 2 + 1) * ftCols + iCol] | ||
* ftFilter[(iRow * 2) * ftCols + iCol]; | ||
* ftFilter[(iRow * 2 + 1) * ftCols + iCol] | ||
+ ftSignal[(iRow * 2 + 1) * ftCols + iCol] | ||
* ftFilter[(iRow * 2) * ftCols + iCol]; | ||
// | ||
@@ -223,2 +225,3 @@ ftSignal[(iRow * 2) * ftCols + iCol] = re; | ||
var dimR = kernel.length; | ||
@@ -241,3 +244,2 @@ var dimC = kernel[0].length; | ||
} | ||
ftFilterData = this.fft2DArray(ftFilterData, nRows, nCols); | ||
@@ -249,20 +251,9 @@ | ||
return this.ifft2DArray(ftSpectrum, ftRows, ftCols); | ||
return this.ifft2DArray(ftSpectrum, ftRows, ftCols); | ||
}, | ||
/** | ||
* ZeroFilling of the image in to make nRows and nCols radix-2 | ||
* @param data | ||
* @param nRows | ||
* @param nCols | ||
*/ | ||
toRadix2:function(data, nRows, nCols, opt){ | ||
var options = Object.assign({},{inplace:true},opt); | ||
var output = data; | ||
if(!options.inplace){ | ||
output = data.slice(0, data.length); | ||
} | ||
var i, padding; | ||
var cols = nCols, rows = nRows | ||
toRadix2:function(data, nRows, nCols){ | ||
var i,j,irow, icol; | ||
var cols = nCols, rows = nRows, prows=0, pcols=0; | ||
if(!(nCols !== 0 && (nCols & (nCols - 1)) === 0)) { | ||
@@ -273,9 +264,3 @@ //Then we have to make a pading to next radix2 | ||
cols=1<<cols; | ||
padding = new Array(cols-nCols); | ||
for(i=0;i<padding.length;i++){ | ||
padding[i]=0; | ||
} | ||
for(i=nRows-1;i>=0;i--){ | ||
output.splice(i*nCols,0,...padding); | ||
} | ||
pcols = cols-nCols; | ||
} | ||
@@ -287,9 +272,18 @@ if(!(nRows !== 0 && (nRows & (nRows - 1)) === 0)) { | ||
rows=1<<rows; | ||
padding = new Array((rows-nRows)*cols); | ||
for(i=0;i<padding.length;i++){ | ||
padding[i]=0; | ||
prows = (rows-nRows)*cols; | ||
} | ||
if(rows==nRows&&cols==nCols)//Do nothing. Returns the same input!!! Be careful | ||
return {data:data, rows:nRows, cols:nCols}; | ||
var output = new Array(rows*cols); | ||
var shiftR = Math.floor((rows-nRows)/2)-nRows; | ||
var shiftC = Math.floor((cols-nCols)/2)-nCols; | ||
for( i=0;i<rows;i++){ | ||
irow = i*cols; | ||
icol = ((i-shiftR) % nRows) * nCols; | ||
for( j = 0;j<cols;j++){ | ||
output[irow+j]=data[(icol+(j-shiftC) % nCols) ]; | ||
} | ||
output.splice(output.length,0,...padding); | ||
} | ||
return {data:output, rows:rows, cols:cols}; | ||
@@ -301,17 +295,23 @@ }, | ||
*/ | ||
crop:function(data, nRows, nCols, newNRows, newNCols, opt){ | ||
var options = Object.assign({},{inplace:true},opt); | ||
crop:function(data, rows, cols, nRows, nCols, opt){ | ||
var colsToCrop = nCols-newNCols; | ||
var rowsToCrop = (nRows-newNRows); | ||
if(rows == nRows && cols == nCols)//Do nothing. Returns the same input!!! Be careful | ||
return data; | ||
var output = data; | ||
if(!options.inplace){ | ||
output = data.slice(0, data.length); | ||
var options = Object.assign({}, opt); | ||
var output = new Array(nCols*nRows); | ||
var shiftR = Math.floor((rows-nRows)/2); | ||
var shiftC = Math.floor((cols-nCols)/2); | ||
var irow, icol, i, j; | ||
for( i=0;i<nRows;i++){ | ||
irow = i*nRows; | ||
icol = (i+shiftR)*cols; | ||
for( j = 0;j<nCols;j++){ | ||
output[irow+j]=data[icol+(j+shiftC)]; | ||
} | ||
} | ||
output.splice(output.length-rowsToCrop*nCols,rowsToCrop*nCols);//Remove the rows | ||
for(var i=newNRows-1;i>=0;i--){ | ||
output.splice(i*nCols, colsToCrop); | ||
} | ||
return output; | ||
@@ -318,0 +318,0 @@ } |
90581
1122