-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from abdullahranginwala/adapt-thresholding
Added functionality for adaptive thresholding
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
imagelab_electron/src/operator/thresholding/AdaptiveThresholding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |