Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the Marching Squares algorithm to create the level set contour. Here is some code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour.

Best of luck.

You can use the Marching Squares algorithm to create the level set contour. Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour.

Best of luck.luck. If you like this answer, please mark the answer as correct.

You can use the Marching Squares algorithm to create the level set contour. contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour.

Best of luck. If you like this answer, please mark the answer as correct.

You can use the Marching Squares algorithm to create the level set contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour.contour(s).

Best of luck. If you like this answer, please mark the answer as correct.

You can use the Marching Squares algorithm to create the level set contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour(s).

Best of luck. If you like this answer, please mark the answer as correct.

Source image: image description

Contours image: image description

You can use the Marching Squares algorithm to create the level set contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour(s).

Best of luck. If you like this answer, please mark the answer as correct.

There is also the threshold and findContours functions, which can be used to get the level set, if you find that Marching Squares is too complicated:

https://docs.opencv.org/3.3.1/d4/d73/tutorial_py_contours_begin.html

Source image: image description

Contours image: image description

You can use the Marching Squares algorithm to create the level set contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour(s).

Best of luck. If you like this answer, please mark the answer as correct.

There is also the threshold and findContours functions, which can be used to get the level set, if you find that Marching Squares is too complicated:

https://docs.opencv.org/3.3.1/d4/d73/tutorial_py_contours_begin.html

Source image: image description

Contours image: image description

#pragma comment(lib, "opencv_world340.lib")

#include <opencv2/opencv.hpp>
using namespace cv;

#include <iostream>
using namespace std;


int main(void)
{
    Mat cat_img = imread("cat.png", CV_LOAD_IMAGE_GRAYSCALE);

    threshold(cat_img, cat_img, 127, 255, THRESH_BINARY);

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    findContours(cat_img, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));

    Mat cat_contours = Mat::zeros(cat_img.size(), CV_8UC3);

    for (size_t i = 0; i < contours.size(); i++)
        drawContours(cat_contours, contours, (int)i, Scalar(255, 0, 0), 2, 8, hierarchy, 0, Point());

    imshow("cat img", cat_contours);

    waitKey(0);

    destroyAllWindows();

    return 0;
}

You If you want to do it yourself from the ground up, you can use the Marching Squares algorithm to create the level set contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour(s).

Best of luck. If you like this answer, please mark the answer as correct.

There is also the threshold and findContours functions, which can be used to get the level set, if you find that Marching Squares is too complicated:

#pragma comment(lib, "opencv_world340.lib")

#include <opencv2/opencv.hpp>
using namespace cv;

#include <iostream>
using namespace std;


int main(void)
{
    Mat cat_img = imread("cat.png", CV_LOAD_IMAGE_GRAYSCALE);

    threshold(cat_img, cat_img, 127, 255, THRESH_BINARY);

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    findContours(cat_img, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));

    Mat cat_contours = Mat::zeros(cat_img.size(), CV_8UC3);

    for (size_t i = 0; i < contours.size(); i++)
        drawContours(cat_contours, contours, (int)i, Scalar(255, 0, 0), 2, 8, hierarchy, 0, Point());

    imshow("cat img", cat_contours);

    waitKey(0);

    destroyAllWindows();

    return 0;
}

If you want to do it yourself from the ground up, you can use the Marching Squares algorithm to create the level set contour(s). Here is some C++ code that I wrote some time ago:

https://github.com/sjhalayka/Marching-Squares

The code uses the OpenGL/GLUT libraries to draw the image and the contour(s).

Best of luck. If you like this answer, please mark the answer as correct.

There is also the OpenCV threshold and findContours functions, which can be used to get the level set, if you find that Marching Squares is too complicated:

#pragma comment(lib, "opencv_world340.lib")

#include <opencv2/opencv.hpp>
using namespace cv;

#include <iostream>
using namespace std;


int main(void)
{
    Mat cat_img = imread("cat.png", CV_LOAD_IMAGE_GRAYSCALE);

    threshold(cat_img, cat_img, 127, 255, THRESH_BINARY);

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    findContours(cat_img, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));

    Mat cat_contours = Mat::zeros(cat_img.size(), CV_8UC3);

    for (size_t i = 0; i < contours.size(); i++)
        drawContours(cat_contours, contours, (int)i, Scalar(255, 0, 0), 2, 8, hierarchy, 0, Point());

    imshow("cat img", cat_contours);

    waitKey(0);

    destroyAllWindows();

    return 0;
}