mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-17 05:40:00 +01:00
[GCI] Standardised Blob Analysis module comments (#1351)
* fix comments * Update src/modules/BlobAnalysis/BlobAnalysis.js Fix double image * Update src/modules/BlobAnalysis/BlobAnalysis.js * . fix
This commit is contained in:
committed by
Jeffrey Warren
parent
3d4025fd93
commit
0ce2cf9492
@@ -1,6 +1,6 @@
|
|||||||
module.exports = function(pixels, options, priorStep){
|
module.exports = function(pixels, options, priorStep){
|
||||||
|
|
||||||
var $ = require('jquery'); // to make Blob-analysis work for node.js
|
var $ = require('jquery'); // To make Blob-analysis work in Node
|
||||||
|
|
||||||
var img = $(priorStep.imgElement);
|
var img = $(priorStep.imgElement);
|
||||||
if(Object.keys(img).length === 0){
|
if(Object.keys(img).length === 0){
|
||||||
@@ -25,26 +25,26 @@ module.exports = function(pixels, options, priorStep){
|
|||||||
let unknown = new cv.Mat();
|
let unknown = new cv.Mat();
|
||||||
let markers = new cv.Mat();
|
let markers = new cv.Mat();
|
||||||
|
|
||||||
// gray and threshold image
|
// Gray and Threshold the image
|
||||||
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
|
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
|
||||||
cv.threshold(gray, gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU);
|
cv.threshold(gray, gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU);
|
||||||
|
|
||||||
// get background
|
// Get background
|
||||||
let M = cv.Mat.ones(3, 3, cv.CV_8U);
|
let M = cv.Mat.ones(3, 3, cv.CV_8U);
|
||||||
cv.erode(gray, gray, M);
|
cv.erode(gray, gray, M);
|
||||||
cv.dilate(gray, opening, M);
|
cv.dilate(gray, opening, M);
|
||||||
cv.dilate(opening, imageBg, M, new cv.Point(-1, -1), 3);
|
cv.dilate(opening, imageBg, M, new cv.Point(-1, -1), 3);
|
||||||
|
|
||||||
// distance transform
|
// Distance transform
|
||||||
cv.distanceTransform(opening, distTrans, cv.DIST_L2, 5);
|
cv.distanceTransform(opening, distTrans, cv.DIST_L2, 5);
|
||||||
cv.normalize(distTrans, distTrans, 1, 0, cv.NORM_INF);
|
cv.normalize(distTrans, distTrans, 1, 0, cv.NORM_INF);
|
||||||
|
|
||||||
// get foreground
|
// Get foreground
|
||||||
cv.threshold(distTrans, imageFg, 0.7 * 1, 255, cv.THRESH_BINARY);
|
cv.threshold(distTrans, imageFg, 0.7 * 1, 255, cv.THRESH_BINARY);
|
||||||
imageFg.convertTo(imageFg, cv.CV_8U, 1, 0);
|
imageFg.convertTo(imageFg, cv.CV_8U, 1, 0);
|
||||||
cv.subtract(imageBg, imageFg, unknown);
|
cv.subtract(imageBg, imageFg, unknown);
|
||||||
|
|
||||||
// get connected components markers
|
// Get connected components markers
|
||||||
cv.connectedComponents(imageFg, markers);
|
cv.connectedComponents(imageFg, markers);
|
||||||
for (let i = 0; i < markers.rows; i++) {
|
for (let i = 0; i < markers.rows; i++) {
|
||||||
for (let j = 0; j < markers.cols; j++) {
|
for (let j = 0; j < markers.cols; j++) {
|
||||||
@@ -58,13 +58,13 @@ module.exports = function(pixels, options, priorStep){
|
|||||||
cv.cvtColor(src, src, cv.COLOR_RGBA2RGB, 0);
|
cv.cvtColor(src, src, cv.COLOR_RGBA2RGB, 0);
|
||||||
cv.watershed(src, markers);
|
cv.watershed(src, markers);
|
||||||
|
|
||||||
// draw barriers
|
// Grow barriers
|
||||||
for (let i = 0; i < markers.rows; i++) {
|
for (let i = 0; i < markers.rows; i++) {
|
||||||
for (let j = 0; j < markers.cols; j++) {
|
for (let j = 0; j < markers.cols; j++) {
|
||||||
if (markers.intPtr(i, j)[0] == -1) {
|
if (markers.intPtr(i, j)[0] == -1) {
|
||||||
src.ucharPtr(i, j)[0] = 255; // R
|
src.ucharPtr(i, j)[0] = 255; // Red
|
||||||
src.ucharPtr(i, j)[1] = 0; // G
|
src.ucharPtr(i, j)[1] = 0; // Green
|
||||||
src.ucharPtr(i, j)[2] = 0; // B
|
src.ucharPtr(i, j)[2] = 0; // Blue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module.exports = function BlobAnalysis(options, UI){
|
|||||||
|
|
||||||
var step = this;
|
var step = this;
|
||||||
|
|
||||||
var priorStep = this.getStep(-1); // get the previous step to process it
|
var priorStep = this.getStep(-1); // Get the previous step to process it
|
||||||
|
|
||||||
function extraManipulation(pixels){
|
function extraManipulation(pixels){
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user