Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Sharpening Module added #1849

Merged
merged 5 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions docs/MODULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ List of Module Documentations
36. [Rotate](#rotate-module)
37. [Saturation](#saturation-module)
38. [Segmented-Colormap](#segmented-colormap-module)
39. [Text-Overlay](#text-overlay)
40. [Threshold](#threshold)
41. [Tint](#tint)
42. [WebGL-Distort](#webgl-distort-module)
43. [White-Balance](#white-balance-module)
39. [Sharpen](#sharpening-module)
40. [Text-Overlay](#text-overlay)
41. [Threshold](#threshold)
42. [Tint](#tint)
43. [WebGL-Distort](#webgl-distort-module)
44. [White-Balance](#white-balance-module)


## add-qr-module
Expand Down Expand Up @@ -667,6 +668,20 @@ where `options` is an object with the property `colormap`. `options.colormap` ca
* A custom array.


## sharpen-module

This module is used to sharpen the pixels of the image using a 3x3 convolution filter.
#### Usage

```js
sequencer.loadImage('PATH')
.addSteps('sharpen',options)
.run()
```

where `options` is an object with the property `sharpenStrength`, which can be set to achieve the desired level of sharpening on the image.


## Text Overlay

The modules allows to add text to image in both browser and node environment. We have the options to modify the font-size and also support few font-styles. The text color can also be modified.
Expand Down
1 change: 1 addition & 0 deletions src/Modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
'rotate': require('./modules/Rotate'),
'saturation': require('./modules/Saturation'),
'shadow': require('./modules/Shadow'),
'sharpen': require('./modules/Sharpen'),
'text-overlay': require('./modules/TextOverlay'),
'threshold': require('./modules/Threshold'),
'tint': require('./modules/Tint'),
Expand Down
46 changes: 46 additions & 0 deletions src/modules/Sharpen/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Sharpen an image
*/
module.exports = function Sharpen(options, UI) {

let defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.sharpenStrength = options.sharpenStrength || defaults.sharpenStrength;
options.sharpenStrength = parseFloat(options.sharpenStrength); //returns a float
let output;

function draw(input, callback, progressObj) {

progressObj.stop(true);
progressObj.overrideFlag = true;

let step = this;

function extraManipulation(pixels) {
pixels = require('./Sharpen')(pixels, options.sharpenStrength);
return (pixels);
}

function output(image, datauri, mimetype, wasmSuccess) {
step.output = { src: datauri, format: mimetype, wasmSuccess, useWasm: options.useWasm };
}

return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
ui: options.step.ui,
inBrowser: options.inBrowser,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback,
useWasm:options.useWasm
});

}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

48 changes: 48 additions & 0 deletions src/modules/Sharpen/Sharpen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Generates a 3x3 convolution sharpening kernel
function kernelGenerator(strength = 1) { //default value of sharpeningStrength set to 1

let kernel = [
[0, -1 * strength, 0],
[-1 * strength, 5 * strength, -1 * strength],
[0, -1 * strength, 0]
];
return kernel;
}

module.exports = exports = function(pixels, sharpen) {
const pixelSetter = require('../../util/pixelSetter.js');

let kernel = kernelGenerator(sharpen), // Generate the kernel based on the strength input.
pixs = { // Separates the rgb channel pixels to convolve on the GPU.
r: [],
g: [],
b: [],
};
for (let y = 0; y < pixels.shape[1]; y++){
pixs.r.push([]);
pixs.g.push([]);
pixs.b.push([]);

for (let x = 0; x < pixels.shape[0]; x++){
pixs.r[y].push(pixels.get(x, y, 0));
pixs.g[y].push(pixels.get(x, y, 1));
pixs.b[y].push(pixels.get(x, y, 2));
}
}

const convolve = require('../_nomodule/gpuUtils').convolve; // GPU convolution function.

const conPix = convolve([pixs.r, pixs.g, pixs.b], kernel); // Convolves the pixels (all channels separately) on the GPU.

for (let y = 0; y < pixels.shape[1]; y++){
for (let x = 0; x < pixels.shape[0]; x++){
var pixelvalue = [Math.max(0, Math.min(conPix[0][y][x], 255)),
Math.max(0, Math.min(conPix[1][y][x], 255)),
Math.max(0, Math.min(conPix[2][y][x], 255))];

pixelSetter(x, y, pixelvalue, pixels); // Sets the image pixels according to the sharpened values.

}
}
return (pixels);
};
4 changes: 4 additions & 0 deletions src/modules/Sharpen/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
require('./Module'),
require('./info.json')
];
15 changes: 15 additions & 0 deletions src/modules/Sharpen/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "sharpen",
"description": "Applies a sharpening filter given by the intensity value",
"inputs": {
"sharpenStrength": {
"type": "float",
"desc": "Amount of sharpening (More sharpening gives more detail, but may lead to overexposure)",
"default": 1,
"min": 1,
"max": 1.5,
"step": 0.05
}
},
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#sharpen-module"
}
2 changes: 2 additions & 0 deletions test/core/images/moon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/core/modules/sharpen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.