Skip to content

Commit

Permalink
Merge pull request #138 from abdullahranginwala/adapt-thresholding
Browse files Browse the repository at this point in the history
Added functionality for adaptive thresholding
  • Loading branch information
SahanDisa authored Jul 19, 2023
2 parents 35ae078 + 3d6091c commit dd2d095
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions imagelab_electron/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const PROCESS_OPERATIONS = {
EROSION: "filtering_erosion",
DILATION: "filtering_dilation",
MORPHOLOGICAL: "filtering_morphological",
ADAPTIVETHRESHOLDING: "thresholding_adaptivethreshold"
SIMPLETHRESHOLDING: "thresholding_applythreshold",
};

Expand Down
4 changes: 4 additions & 0 deletions imagelab_electron/src/controller/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 AdaptiveThreshold = require("../operator/thresholding/AdaptiveThresholding");
const ApplyThreshold = require("../operator/thresholding/ApplyThreshold");

class MainController {
Expand Down Expand Up @@ -233,6 +234,9 @@ class MainController {
new Morphological(PROCESS_OPERATIONS.MORPHOLOGICAL, id)
);
break;
case PROCESS_OPERATIONS.ADAPTIVETHRESHOLDING:
this.#appliedOperators.push(
new AdaptiveThreshold(PROCESS_OPERATIONS.ADAPTIVETHRESHOLDING, id)
case PROCESS_OPERATIONS.SIMPLETHRESHOLDING:
this.#appliedOperators.push(
new ApplyThreshold(PROCESS_OPERATIONS.SIMPLETHRESHOLDING, id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const OpenCvOperator = require("../OpenCvOperator");

/**
* This class contains the main logic to apply adaptive threshold
* to an image
*/

class AdaptiveThreshold extends OpenCvOperator {
#maxvalue = 0;
constructor(type, id) {
super(type, id);
}

setParams(type, value) {
if (type === "maxValue") {
this.#maxvalue = value;
}
}


/**
*
* @param {Mat} image
* @returns
*
* This function processes adaptive threshold
* to the mat image
*/
compute(image) {
const dst = new this.cv2.Mat();
this.cv2.cvtColor(image, image, this.cv2.COLOR_RGBA2GRAY, 0);
this.cv2.adaptiveThreshold(image, dst, this.#maxvalue, this.cv2.ADAPTIVE_THRESH_GAUSSIAN_C, this.cv2.THRESH_BINARY, 3, 2);
return dst;
}
}

module.exports = AdaptiveThreshold;

0 comments on commit dd2d095

Please sign in to comment.