Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

salient-image

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

salient-image - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

89

lib/salient-image.js
var cv = require('opencv');
var getSalientPerChannel = function(channel, gaussianKernel, sigmaOpt){
var getSalientPerChannel = function(channel, gaussianKernel, sigmaOpt, debugFn){
var width = channel.width();

@@ -13,3 +13,3 @@ var height = channel.height();

var sigma = sigmaOpt || Math.min(width, height)/50;
debugFn && debugFn("start");
channel.convertTo(floatInputMatrix, cv.Constants.CV_32FC1);

@@ -19,23 +19,39 @@

for(var i = 0; i < width; i++){
for(var j = 0; j < height; j++){
if(dct.get(i,j) < 0){
signs.set(i, j, -1);
} else if(dct.get(i,j) == 0){
signs.set(i, j, 0);
debugFn && debugFn("af dct");
//var arrDct = dct.toArray();
//debugFn && debugFn("af toArray");
var dctW = dct.width();
var dctH = dct.height();
var zeros = new cv.Matrix.Zeros(dctH, dctW, cv.Constants.CV_32FC1);
var signs = new cv.Matrix.Zeros(dctH, dctW, cv.Constants.CV_32FC1);
var greater = new cv.Matrix.Zeros(dctH, dctW, cv.Constants.CV_32FC1);
var lesser = new cv.Matrix.Zeros(dctH, dctW, cv.Constants.CV_32FC1);
dct.compare(zeros, cv.Constants.CMP_GT).convertTo(greater, cv.Constants.CV_32FC1);
dct.compare(zeros, cv.Constants.CMP_LT).convertTo(lesser, cv.Constants.CV_32FC1);
signs.addWeighted(greater, 1/255, lesser, -1/255);
console.log(signs.toArray())
/*for(var i = 0; i < height; i++){
for(var j = 0; j < width; j++){
if(arrDct[i][j][0] < 0){
arrDct[i][j][0] = -1;
} else if(arrDct[i][j][0] == 0){
arrDct[i][j][0] = 0;
} else {
signs.set(i, j, 1);
arrDct[i][j][0] = 1;
}
}
}
}*/
//debugFn && debugFn("bf fromArray");
//var signs = cv.Matrix.fromArray(arrDct, cv.Constants.CV_32FC1);
debugFn && debugFn("bf idct");
var iDct = signs.idct();
//console.log(afterDoubleDct.getData())
for(var i = 0; i < width; i++){
for(var j = 0; j < height; j++){
var v = iDct.get(i,j)
squaredFloat.set(i,j, v * v)
}
}
var squaredFloat = iDct.mul(iDct);

@@ -47,2 +63,3 @@ squaredFloat.gaussianBlur(kernelSize, sigma);

squaredFloat.convertTo(outChannel, cv.Constants.CV_64F);
debugFn && debugFn("end");

@@ -59,3 +76,12 @@ return outChannel;

module.exports = function(filename, options, cb){
if(typeof(filename) === "object"){
cb = options;
options = filename;
filename = options.filename;
}
if(!cb && typeof(options) === "function"){

@@ -74,3 +100,5 @@ cb = options;

cv.readImage(filename, function(err, img) {
var debugFn = options.debugFn;
var onImg = function(err, img) {
if (err) return cb(err);

@@ -85,5 +113,12 @@

img.cvtColor(options.colorSpace);
var channels;
var channels = img.split();
if(img.channels() === 1){
channels = img.split();
} else {
img.cvtColor(options.colorSpace);
channels = img.split();
}
var outChannels = [];

@@ -94,6 +129,10 @@

debugFn && debugFn("before getSalientPerChannel")
for(var chanIdx = 0; chanIdx < channels.length; chanIdx++){
var salient = getSalientPerChannel(channels[chanIdx], options.gaussianKernel, options.sigma)
var salient = getSalientPerChannel(channels[chanIdx], options.gaussianKernel, options.sigma, function(lbl){
debugFn && debugFn("chanIdx"+chanIdx+lbl);
})
out = out.add(salient)
}
debugFn && debugFn("after getSalientPerChannel")

@@ -104,3 +143,9 @@ out.normalize(0,1);

});
};
if(options.image){
return onImg(null, options.image)
}
cv.readImage(filename, onImg);
};
{
"name": "salient-image",
"version": "1.0.0",
"version": "1.0.1",
"description": "Image signature: highlighting sparse salient regions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -67,1 +67,13 @@ # salient-image

```
## With existing opencv image as input
```
var img = new cv.Matrix(<...>);
salient({
image : img,
resize : [200, 200], // the resize size
sigma : 0.045, // the sigma of the gaussian kernel
gaussianKernel : [11, 11] // the size of the gaussian kernel
}, function(err, saliency){ ... });
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc