From 84b7bba13f98b23af69349314efd8556813548bf Mon Sep 17 00:00:00 2001 From: hs05june Date: Tue, 21 Mar 2023 02:40:03 +0530 Subject: [PATCH 1/2] Sobel / Scharr Derivative Signed-off-by: hs05june --- imagelab_electron/operations.js | 2 + imagelab_electron/src/controller/main.js | 12 +++++ .../sobelderivatives/ScharrDerivate.js | 49 +++++++++++++++++++ .../sobelderivatives/SobleDerivate.js | 49 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js create mode 100644 imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js diff --git a/imagelab_electron/operations.js b/imagelab_electron/operations.js index 43d40ed..2121190 100644 --- a/imagelab_electron/operations.js +++ b/imagelab_electron/operations.js @@ -21,6 +21,8 @@ const PROCESS_OPERATIONS = { EROSION: "filtering_erosion", DILATION: "filtering_dilation", MORPHOLOGICAL: "filtering_morphological", + SOBEL: "sobelderivatives_soblederivate", + SCHARR: "sobelderivatives_scharrderivate" }; module.exports = PROCESS_OPERATIONS; diff --git a/imagelab_electron/src/controller/main.js b/imagelab_electron/src/controller/main.js index 2afe87e..afa782a 100644 --- a/imagelab_electron/src/controller/main.js +++ b/imagelab_electron/src/controller/main.js @@ -21,6 +21,8 @@ const AffineImage = require("../operator/geometric/AffineImage"); const ReflectImage = require("../operator/geometric/ReflectImage"); const RotateImage = require("../operator/geometric/RotateImage"); const ScaleImage = require("../operator/geometric/ScaleImage"); +const ScharrDerivate = require("../operator/sobelderivatives/ScharrDerivate") +const SobleDerivate = require("../operator/sobelderivatives/SobleDerivate") class MainController { // This private field is used to store the applied operators in the workspace @@ -209,6 +211,16 @@ class MainController { new Morphological(PROCESS_OPERATIONS.MORPHOLOGICAL, id) ); break; + case PROCESS_OPERATIONS.SOBEL: + this.#appliedOperators.push( + new SobleDerivate(PROCESS_OPERATIONS.SOBEL, id) + ); + break; + case PROCESS_OPERATIONS.SCHARR: + this.#appliedOperators.push( + new ScharrDerivate(PROCESS_OPERATIONS.SCHARR, id) + ); + break; default: break; } diff --git a/imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js b/imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js new file mode 100644 index 0000000..99cd2f5 --- /dev/null +++ b/imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js @@ -0,0 +1,49 @@ +const OpenCvOperator = require("../OpenCvOperator"); + + /** + * This class contains the main logic to apply simple threshold + * to an image + */ + + class ScharrDerivate extends OpenCvOperator { + #x = 0; + #y = 1; + #type = "HORIZONTAL" + #ddepth = 0 + constructor(type, id) { + super(type, id); + } + + setParams(type, value) { + if (type === "type") { + this.#type = value; + if(value==="HORIZONTAL"){ + this.#x = 0; + this.#y = 1; + } + else if(value === "VERTICAL"){ + this.#x = 1; + this.#y = 0; + } + } else if (type === "ddepth") { + this.#ddepth = value; + } + } + + + /** + * + * @param {Mat} image + * @returns + * + * This function processes simple threshold + * to the mat image + */ + compute(image) { + const dst = new this.cv2.Mat(); + this.cv2.Scharr(image, dst, this.#ddepth, this.#x, this.#y); + return dst; + } + } + + module.exports = ScharrDerivate; \ No newline at end of file diff --git a/imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js b/imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js new file mode 100644 index 0000000..abbba64 --- /dev/null +++ b/imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js @@ -0,0 +1,49 @@ +const OpenCvOperator = require("../OpenCvOperator"); + + /** + * This class contains the main logic to apply simple threshold + * to an image + */ + + class SobleDerivate extends OpenCvOperator { + #x = 0; + #y = 1; + #type = "HORIZONTAL" + #ddepth = 0 + constructor(type, id) { + super(type, id); + } + + setParams(type, value) { + if (type === "type") { + this.#type = value; + if(value==="HORIZONTAL"){ + this.#x = 0; + this.#y = 1; + } + else if(value==="VERTICAL"){ + this.#x = 1; + this.#y = 0; + } + } else if (type === "ddepth") { + this.#ddepth = value; + } + } + + + /** + * + * @param {Mat} image + * @returns + * + * This function processes simple threshold + * to the mat image + */ + compute(image) { + const dst = new this.cv2.Mat(); + this.cv2.Sobel(image, dst, this.#ddepth, this.#x, this.#y); + return dst; + } + } + + module.exports = SobleDerivate; \ No newline at end of file From 4a574234f84e83719fba875ec60239229089051c Mon Sep 17 00:00:00 2001 From: hs05june Date: Tue, 21 Mar 2023 03:17:55 +0530 Subject: [PATCH 2/2] ColorMap Signed-off-by: hs05june --- imagelab_electron/operations.js | 3 +- imagelab_electron/src/controller/main.js | 12 +--- .../src/operator/convertions/ColorMaps.js | 67 +++++++++++++++++++ .../sobelderivatives/ScharrDerivate.js | 49 -------------- .../sobelderivatives/SobleDerivate.js | 49 -------------- 5 files changed, 71 insertions(+), 109 deletions(-) create mode 100644 imagelab_electron/src/operator/convertions/ColorMaps.js delete mode 100644 imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js delete mode 100644 imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js diff --git a/imagelab_electron/operations.js b/imagelab_electron/operations.js index 2121190..d1d5fad 100644 --- a/imagelab_electron/operations.js +++ b/imagelab_electron/operations.js @@ -21,8 +21,7 @@ const PROCESS_OPERATIONS = { EROSION: "filtering_erosion", DILATION: "filtering_dilation", MORPHOLOGICAL: "filtering_morphological", - SOBEL: "sobelderivatives_soblederivate", - SCHARR: "sobelderivatives_scharrderivate" + COLORMAPS: "imageconvertions_colormaps", }; module.exports = PROCESS_OPERATIONS; diff --git a/imagelab_electron/src/controller/main.js b/imagelab_electron/src/controller/main.js index afa782a..9bf0a5d 100644 --- a/imagelab_electron/src/controller/main.js +++ b/imagelab_electron/src/controller/main.js @@ -21,8 +21,7 @@ const AffineImage = require("../operator/geometric/AffineImage"); const ReflectImage = require("../operator/geometric/ReflectImage"); const RotateImage = require("../operator/geometric/RotateImage"); const ScaleImage = require("../operator/geometric/ScaleImage"); -const ScharrDerivate = require("../operator/sobelderivatives/ScharrDerivate") -const SobleDerivate = require("../operator/sobelderivatives/SobleDerivate") +const ColorMaps = require("../operator/convertions/ColorMaps") class MainController { // This private field is used to store the applied operators in the workspace @@ -211,14 +210,9 @@ class MainController { new Morphological(PROCESS_OPERATIONS.MORPHOLOGICAL, id) ); break; - case PROCESS_OPERATIONS.SOBEL: + case PROCESS_OPERATIONS.COLORMAPS: this.#appliedOperators.push( - new SobleDerivate(PROCESS_OPERATIONS.SOBEL, id) - ); - break; - case PROCESS_OPERATIONS.SCHARR: - this.#appliedOperators.push( - new ScharrDerivate(PROCESS_OPERATIONS.SCHARR, id) + new ColorMaps(PROCESS_OPERATIONS.COLORMAPS, id) ); break; default: diff --git a/imagelab_electron/src/operator/convertions/ColorMaps.js b/imagelab_electron/src/operator/convertions/ColorMaps.js new file mode 100644 index 0000000..2f0ab0f --- /dev/null +++ b/imagelab_electron/src/operator/convertions/ColorMaps.js @@ -0,0 +1,67 @@ +const OpenCvOperator = require("../OpenCvOperator"); + +/** + * This class contains the main logic to apply simple threshold + * to an image + */ + +class ColorMaps extends OpenCvOperator { + #type = "HOT" + constructor(type, id) { + super(type, id); + } + + setParams(type, value) { + if (type === "type") { + this.#type = value; + } + } + + + /** + * + * @param {Mat} image + * @returns + * + * This function processes simple threshold + * to the mat image + */ + compute(image) { + const dst = new this.cv2.Mat(); + switch (this.#type) { + case "AUTUMN": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_AUTUMN) + break; + case "HOT": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_HOT); + break; + case "BONE": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_BONE); + break; + case "COOL": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_COOL); + break; + case "HSV": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_HSV); + break; + case "JET": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_JET); + break; + case "OCEAN": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_OCEAN); + break; + case "PARULA": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_PARULA); + break; + case "PINK": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_PINK); + break; + case "RAINBOW": + this.cv2.applyColorMap(image, dst, this.cv2.COLORMAP_RAINBOW); + break; + } + return dst; + } +} + +module.exports = ColorMaps; \ No newline at end of file diff --git a/imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js b/imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js deleted file mode 100644 index 99cd2f5..0000000 --- a/imagelab_electron/src/operator/sobelderivatives/ScharrDerivate.js +++ /dev/null @@ -1,49 +0,0 @@ -const OpenCvOperator = require("../OpenCvOperator"); - - /** - * This class contains the main logic to apply simple threshold - * to an image - */ - - class ScharrDerivate extends OpenCvOperator { - #x = 0; - #y = 1; - #type = "HORIZONTAL" - #ddepth = 0 - constructor(type, id) { - super(type, id); - } - - setParams(type, value) { - if (type === "type") { - this.#type = value; - if(value==="HORIZONTAL"){ - this.#x = 0; - this.#y = 1; - } - else if(value === "VERTICAL"){ - this.#x = 1; - this.#y = 0; - } - } else if (type === "ddepth") { - this.#ddepth = value; - } - } - - - /** - * - * @param {Mat} image - * @returns - * - * This function processes simple threshold - * to the mat image - */ - compute(image) { - const dst = new this.cv2.Mat(); - this.cv2.Scharr(image, dst, this.#ddepth, this.#x, this.#y); - return dst; - } - } - - module.exports = ScharrDerivate; \ No newline at end of file diff --git a/imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js b/imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js deleted file mode 100644 index abbba64..0000000 --- a/imagelab_electron/src/operator/sobelderivatives/SobleDerivate.js +++ /dev/null @@ -1,49 +0,0 @@ -const OpenCvOperator = require("../OpenCvOperator"); - - /** - * This class contains the main logic to apply simple threshold - * to an image - */ - - class SobleDerivate extends OpenCvOperator { - #x = 0; - #y = 1; - #type = "HORIZONTAL" - #ddepth = 0 - constructor(type, id) { - super(type, id); - } - - setParams(type, value) { - if (type === "type") { - this.#type = value; - if(value==="HORIZONTAL"){ - this.#x = 0; - this.#y = 1; - } - else if(value==="VERTICAL"){ - this.#x = 1; - this.#y = 0; - } - } else if (type === "ddepth") { - this.#ddepth = value; - } - } - - - /** - * - * @param {Mat} image - * @returns - * - * This function processes simple threshold - * to the mat image - */ - compute(image) { - const dst = new this.cv2.Mat(); - this.cv2.Sobel(image, dst, this.#ddepth, this.#x, this.#y); - return dst; - } - } - - module.exports = SobleDerivate; \ No newline at end of file