Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

ndarray-translate-fft

Package Overview
Dependencies
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndarray-translate-fft - npm Package Compare versions

Comparing version
0.0.0
to
1.0.0
+6
.travis.yml
language: node_js
node_js:
- "0.8"
- "0.10"
before_install:
- npm install -g npm@~1.4.6
"use strict"
var ndarray = require("ndarray")
var ops = require("ndarray-ops")
var mouseChange = require('mouse-change')
//var fit = require('canvas-fit')
var baboon = require("luminance")(require('baboon-image'))
var baboonTranslated = ndarray(new Float32Array(baboon.size), baboon.shape, baboon.stride)
var translate = require("../translate.js")
var render = require("ndarray-canvas")
var canvas = document.createElement('canvas')
document.body.appendChild(canvas)
//window.addEventListener('resize', fit(canvas), false)
var context = canvas.getContext('2d')
canvas.style.position = "absolute"
canvas.style.left = "0"
canvas.style.top = "0"
canvas.style.width = "100%"
canvas.style.height = "100%"
canvas.width = baboon.shape[0]
canvas.height = baboon.shape[1]
var controlDiv = document.createElement('div')
controlDiv.innerHTML = 'click and drag to move image<br><a href="https://github.com/scijs/ndarray-translate-fft">Project page</a>'
controlDiv.style.position = 'absolute'
controlDiv.style['z-index'] = '10'
controlDiv.style.left = controlDiv.style.top = '10px'
document.body.appendChild(controlDiv)
var translationX = 0, translationY = 0
var lastX = 0, lastY = 0
mouseChange(function(buttons, x,y) {
if (buttons) { // Move
translationX += x-lastX
translationY += y-lastY
}
lastX = x
lastY = y
})
function draw() {
//requestAnimationFrame(draw)
console.time("render")
ops.assign(baboonTranslated, baboon)
translate(baboonTranslated, [translationX,translationY])
console.timeEnd("render")
//render(canvas, baboonTranslated)
}
draw()
draw()
+3
-3

@@ -1,6 +0,6 @@

var lena = require("luminance")(require("lena"))
var baboon = require("luminance")(require('baboon-image'))
var translate = require("../translate.js")
translate.wrap(lena, [100, 180])
translate.wrap(baboon, [100, 180])
require("save-pixels")(lena, "png").pipe(process.stdout)
require("save-pixels")(baboon, "png").pipe(process.stdout)

@@ -1,6 +0,6 @@

var lena = require("luminance")(require("lena"))
var baboon = require("luminance")(require('baboon-image'))
var translate = require("../translate.js")
translate(lena, [100, 180])
translate(baboon, [100, 180])
require("save-pixels")(lena, "png").pipe(process.stdout)
require("save-pixels")(baboon, "png").pipe(process.stdout)
{
"name": "ndarray-translate-fft",
"version": "0.0.0",
"version": "1.0.0",
"description": "Translates ndarrays using sinc interpolation",

@@ -10,22 +10,30 @@ "main": "translate.js",

},
"browserify": {
"transform": [
"cwise"
]
},
"dependencies": {
"cwise": "~0.1.2",
"ndarray": "~0.2.3",
"ndarray-fft": "~0.0.2",
"ndarray-ops": "~0.1.3",
"bit-twiddle": "~0.0.2",
"typedarray-pool": "~0.1.1"
"cwise": "^1.0.5",
"ndarray": "^1.0.18",
"ndarray-fft": "^1.0.0",
"ndarray-ops": "^1.2.2",
"next-pow-2": "^1.0.0",
"typedarray-pool": "^1.1.0"
},
"devDependencies": {
"lena": "~0.0.0",
"luminance": "~0.0.0",
"save-pixels": "~0.0.1",
"tap": "~0.4.3"
"baboon-image": "^2.0.0",
"luminance": "^1.0.3",
"mouse-change": "^1.2.1",
"ndarray-canvas": "0.0.0",
"save-pixels": "^2.2.0",
"tape": "^4.0.0",
"test-fuzzy-array": "^1.0.1"
},
"scripts": {
"test": "tap test/*.js"
"test": "tape test/*.js"
},
"repository": {
"type": "git",
"url": "git://github.com/mikolalysenko/ndarray-translate-fft.git"
"url": "git://github.com/scijs/ndarray-translate-fft.git"
},

@@ -44,5 +52,11 @@ "keywords": [

"author": "Mikola Lysenko",
"contributors": [
"Jasper van de Gronde <th.v.d.gronde@hccnet.nl>"
],
"license": "MIT",
"readmeFilename": "README.md",
"gitHead": "d23d40a68dfada1abda5947d33da891fb960874a"
"gitHead": "d23d40a68dfada1abda5947d33da891fb960874a",
"bugs": {
"url": "https://github.com/scijs/ndarray-translate-fft/issues"
}
}
+26
-17

@@ -5,34 +5,41 @@ ndarray-translate-fft

## Example
[![build status](https://secure.travis-ci.org/scijs/ndarray-translate-fft.png)](http://travis-ci.org/scijs/ndarray-translate-fft)
# Example
## Zero padded
Here is a simple example showing how to warp with 0-padding boundary conditions:
```javascript
var lena = require("luminance")(require("lena"))
var baboon = require("luminance")(require('baboon-image'))
var translate = require("../translate.js")
translate(lena, [100, 180])
translate(baboon, [100, 180])
require("save-pixels")(lena, "png").pipe(process.stdout)
require("save-pixels")(baboon, "png").pipe(process.stdout)
```
### Output
Which produces the following image:
<img src="https://raw.github.com/mikolalysenko/ndarray-translate-fft/master/example/zero.png"></img>
<img src="https://raw.github.com/mikolalysenko/ndarray-translate-fft/master/example/zero.png">
## Wrapped
ndarray-fft can also handle periodic boundary conditions by replacing the `translate` line with the following:
```javascript
translate.wrap(lena, [100, 180])
var baboon = require("luminance")(require('baboon-image'))
var translate = require("../translate.js")
translate.wrap(baboon, [100, 180])
require("save-pixels")(baboon, "png").pipe(process.stdout)
```
### Output
This produces the following output:
<img src="https://raw.github.com/mikolalysenko/ndarray-translate-fft/master/example/wrap.png"></img>
## Install
# Install
Install using [npm](https://www.npmjs.com/):
npm install ndarray-translate-fft
## API
# API

@@ -43,11 +50,13 @@ ```javascript

### `translate(array, shift)`
#### `translate(array, shift)`
Translates `array` by `shift` amount in place using sinc interpolation with 0-boundary conditions.
* `array` is an ndarray to translate (get mutated)
* `shift` is the amount to shift by (can be a fractional number)
* `shift` is an array of numbers indicated the amount to shift by (can be a fractional number), should have the same length as `array.shape`
**Returns** `array`
### `translate.wrap(array, shift)`
**Note** that due to not using an infinite amount of padding (and/or using additional corrections), the zero-padded result might not be completely accurate (but since in this case you are shifting out data anyway...).
#### `translate.wrap(array, shift)`
Translates an array by `shift` amount in place using periodic boundary conditions. This is exactly recoverable.

@@ -72,3 +81,3 @@

# Credits
(c) Mikola Lysenko. MIT License
# License
(c) 2013 Mikola Lysenko. MIT License
"use strict"
var translate = require("../translate.js")
var ndarray = require("ndarray")
var fuzz = require("test-fuzzy-array")
require("tap").test("ndarray-translate-fft", function(t) {
require("tape")("ndarray-translate-fft", function(t) {
var almostEqual = fuzz(t, 0.000001)
var array
//var arrayZeroShift = [0.4938717375836403,1.9074040569032518,2.458709679994916,4.010970502471751,4.241666334081412,6.585575582427418] // This would be the result if we just convolved the input (assuming zero boundary conditions) with a sinc kernel
var arrayZeroShift = [0.5622617330441272,1.8516537181033514,2.5028944426581954,3.9775711912180514,4.264837381599642,6.572251895018352] // Due to the use of a limited amount of padding, the solution is not perfect.
var arrayWrapShift = [2.3206249714800427,1.2130636462824271,2.8681926909106736,3.740056987043559,4.429504459170568,6.428557245112723]
var arrayWrapShift2 = [3.0879811422994856,1.4699471535495907,3.2970380688347927,4.851336899176905,3.23330291042701,5.060393825712213] // 2D test
array = ndarray([1,2,3,4,5,6])
almostEqual(translate(array, [0.3]).data, arrayZeroShift, "Zero padded, 1D")
array = ndarray([1,2,3,4,5,6])
almostEqual(translate.wrap(array, [0.3]).data, arrayWrapShift, "Wrapped, 1D")
array = ndarray([1,2,3,4,5,6],[2,3])
almostEqual(translate.wrap(array, [0.3,0.7]).data, arrayWrapShift2, "Wrapped, 2D")
t.end()
})

@@ -8,3 +8,3 @@ "use strict"

var pool = require("typedarray-pool")
var bits = require("bit-twiddle")
var nextPow2 = require("next-pow-2")

@@ -25,5 +25,5 @@ var do_translate = cwise({

for(var i=0; i<this.d; ++i) {
var p = this.weights[i] * idx[i]
var p = this.weights[i] * (2*idx[i]<shape[i] ? idx[i] : idx[i]-shape[i])
var c = this.cos(p)
var s = this.sin(p)
var s = 2*idx[i] == shape[i] ? 0 : this.sin(p)
k1 = a * (c + s)

@@ -41,8 +41,8 @@ k2 = c * (b - a)

function translatePeriodicBC(arr, t) {
var s = ndarray.size(arr)
var s = arr.size
var y_t = pool.mallocDouble(s)
, y = ndarray.ctor(y_t,
arr.shape.slice(0),
ndarray.stride(arr.shape, ndarray.order(arr)),
0)
, y = ndarray(y_t,
arr.shape.slice(0)/*,
ndarray.stride(arr.shape, arr.order),
0*/)
ops.assigns(y, 0.0)

@@ -57,2 +57,3 @@ fft(1, arr, y)

function translateZeroBC(arr, t) {
console.time("pre")
var d = arr.shape.length

@@ -62,3 +63,3 @@ , nshape = new Array(d)

for(i=0; i<d; ++i) {
nshape[i] = bits.nextPow2(2 * arr.shape[i] - 1)
nshape[i] = nextPow2(2 * arr.shape[i] - 1)
if(Math.abs(t[i]) >= arr.shape[i]) {

@@ -70,17 +71,25 @@ ops.assigns(arr, 0.0)

}
var nstride = ndarray.stride(nshape, ndarray.order(arr))
console.timeEnd("pre")
console.time("alloc")
/*var nstride = ndarray.stride(nshape, arr.order)*/
var x_t = pool.mallocDouble(sz)
, x = ndarray.ctor(x_t, nshape, nstride, 0)
, x = ndarray(x_t, nshape/*, nstride, 0*/)
, xl = x.lo.apply(x, arr.shape)
, xh = x.hi.apply(x, arr.shape)
ops.assigns(x, 0)
ops.assigns(xl, 0)
ops.assign(xh, arr)
var y_t = pool.mallocDouble(sz)
, y = ndarray.ctor(y_t, nshape, nstride, 0)
, y = ndarray(y_t, nshape/*, nstride, 0*/)
ops.assigns(y, 0)
console.timeEnd("alloc")
console.time("filter")
fft(1, x, y)
do_translate(x, y, t)
//do_translate(x, y, t)
fft(-1, x, y)
console.timeEnd("filter")
console.time("post")
ops.assign(arr, xh)
pool.freeDouble(x_t)
pool.freeDouble(y_t)
console.timeEnd("post")
return arr

@@ -90,2 +99,2 @@ }

module.exports = translateZeroBC
module.exports.wrap = translatePeriodicBC
module.exports.wrap = translatePeriodicBC

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display