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

Add filter2D in the electron project #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions imagelab_electron/imagelab-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,29 @@ Blockly.defineBlocksWithJsonArray([
"Erosion is quite a similar process as dilation. With this procedure the areas of dark regions grow in size and bright regions reduce. The size of an object in white shade or bright shade increases. while it decreases in white shade or bright shade",
helpUrl: "",
},
{
type: "filtering_filter2d",
message0: "Apply filter2d with ddepth %1 and kernel %2",
args0: [
{
type: "field_number",
name: "ddepth",
value: -1,
},
{
type: "field_number",
name: "kernelSize",
value: 2,
},
],
inputsInline: true,
previousStatement: null,
nextStatement: null,
colour: 135,
tooltip:
"Filter2D operation can be used to convolve an image with a kernel of a specific shape ",
helpUrl: "",
},
{
type: "filtering_bilateral",
message0:
Expand Down
1 change: 1 addition & 0 deletions imagelab_electron/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<block type="filtering_pyramiddown"></block>
<block type="filtering_erosion"></block>
<block type="filtering_dilation"></block>
<block type="filtering_filter2d"></block>
<block type="filtering_morphological"></block>
</category>
<category
Expand Down
1 change: 1 addition & 0 deletions imagelab_electron/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const PROCESS_OPERATIONS = {
PYRAMIDDOWN: "filtering_pyramiddown",
EROSION: "filtering_erosion",
DILATION: "filtering_dilation",
FILTER2D: "filtering_filter2d",
MORPHOLOGICAL: "filtering_morphological",
};

Expand Down
7 changes: 7 additions & 0 deletions imagelab_electron/src/controller/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { FILTER2D } = require("../../operations");
const PROCESS_OPERATIONS = require("../../operations");
const ReadImage = require("../operator/basic/ReadImage");
const WriteImage = require("../operator/basic/WriteImage");
Expand All @@ -14,6 +15,7 @@ const BilateralFilter = require("../operator/filtering/BilateralFilter");
const BoxFilter = require("../operator/filtering/BoxFilter");
const Dilation = require("../operator/filtering/Dilation");
const Erosion = require("../operator/filtering/Erosion");
const Filter2D = require("../operator/filtering/Filter2D");
const Morphological = require("../operator/filtering/Morphological");
const PyramidDown = require("../operator/filtering/PyramidDown");
const PyramidUp = require("../operator/filtering/PyramidUp");
Expand Down Expand Up @@ -204,6 +206,11 @@ class MainController {
new Dilation(PROCESS_OPERATIONS.DILATION, id)
);
break;
case PROCESS_OPERATIONS.FILTER2D:
this.#appliedOperators.push(
new Filter2D(PROCESS_OPERATIONS.FILTER2D, id)
);
break;
case PROCESS_OPERATIONS.MORPHOLOGICAL:
this.#appliedOperators.push(
new Morphological(PROCESS_OPERATIONS.MORPHOLOGICAL, id)
Expand Down
49 changes: 49 additions & 0 deletions imagelab_electron/src/operator/filtering/Filter2D.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const OpenCvOperator = require("../OpenCvOperator");

/**
* This class contains the main logic to add Filter2D
* to an image
*/

class Filter2D extends OpenCvOperator {
#kernelSize = 2;
#ddepth = -1;
constructor(type, id) {
super(type, id);
}

setParams(type, value) {
if (type === "kernelSize") {
this.#kernelSize = value;
} else if (type === "ddepth") {
this.#ddepth = value;
}
}


/**
*
* @param {Mat} image
* @returns
*
* This function processes the filter2D
* to the mat image
*/
compute(image) {
const dst = new this.cv2.Mat();
let M = this.cv2.Mat.eye(this.#kernelSize, this.#kernelSize, this.cv2.CV_32FC1);
let anchor = new this.cv2.Point(-1, -1);
this.cv2.filter2D(
image,
dst,
this.#ddepth,
M,
anchor,
0,
this.cv2.BORDER_DEFAULT
);
return dst;
}
}

module.exports = Filter2D;