summaryrefslogtreecommitdiff
path: root/sci_gateway/cpp/opencv_bwdistgeodesic.cpp
diff options
context:
space:
mode:
authorshamikam2017-01-16 02:56:17 +0530
committershamikam2017-01-16 02:56:17 +0530
commita6df67e8bcd5159cde27556f4f6a315f8dc2215f (patch)
treee806e966b06a53388fb300d89534354b222c2cad /sci_gateway/cpp/opencv_bwdistgeodesic.cpp
downloadFOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.tar.gz
FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.tar.bz2
FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.zip
First CommitHEADmaster
Diffstat (limited to 'sci_gateway/cpp/opencv_bwdistgeodesic.cpp')
-rw-r--r--sci_gateway/cpp/opencv_bwdistgeodesic.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/sci_gateway/cpp/opencv_bwdistgeodesic.cpp b/sci_gateway/cpp/opencv_bwdistgeodesic.cpp
new file mode 100644
index 0000000..7f83652
--- /dev/null
+++ b/sci_gateway/cpp/opencv_bwdistgeodesic.cpp
@@ -0,0 +1,88 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = bwdistgeodesic(input_image, mask)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ #include "../common.h"
+
+ int opencv_bwdistgeodesic(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat marker, mask;
+ retrieveImage(marker, 1);
+ retrieveImage(mask, 2);
+
+ if (marker.type() != CV_8UC1)
+ {
+ Mat tempM;
+ tempM = marker.clone();
+ cvtColor(tempM, marker, CV_BGR2GRAY);
+ }
+
+ if (mask.type() != CV_8UC1)
+ {
+ Mat tempM;
+ tempM = mask.clone();
+ cvtColor(tempM, mask, CV_8UC1);
+ }
+
+ int i = 1;
+
+ Mat temp0;
+ Mat temp2 = marker.clone();
+ Mat fin_image = marker.clone();
+
+ do {
+ temp0 = temp2.clone();
+ Mat temp1, temp3;
+ dilate(temp0, temp1, Mat());
+ min(temp1, mask, temp2);
+ temp3 = temp2 - temp0;
+ temp3.convertTo(temp3, CV_32F);
+ temp3 = temp3 * ((255 - i)/255.0);
+ temp3.convertTo(temp3, CV_8UC1);
+ max(fin_image, temp3, fin_image);
+ i++;
+ } while((countNonZero(temp0 != temp2) != 0) && (i != 255));
+
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_image, 1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}