Ask Your Question
1

How to Draw contours when have Chaincode (openCV)

asked 2017-06-01 20:34:18 -0600

mrduc9x gravatar image

Hi guys, I want to draw Contours of Breast Cancer Image...I have Chain code of Cancer. Can you help me, how to draw countour by Chaincode using Opencv C++ Thank you so much ftp://figment.csee.usf.edu/pub/DDSM/cases/benigns/benign_03/case1368/A_1368_1.LEFT_CC.OVERLAY

Chaincode: 1829 and 2844 are starting point coordinates (x, y)

BOUNDARY

1829 2844 2 2 2 2 2 2 2 2 7 7 7 7 7 7 7 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... (more)

edit retag flag offensive close merge delete

Comments

how did you generate the chain ?

berak gravatar imageberak ( 2017-06-01 23:57:01 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2017-06-02 00:40:18 -0600

berak gravatar image

updated 2017-06-02 00:44:35 -0600

assuming, 0 goes up, and clockwise order, like here:

image description

you can reconstruct the contours from a starting point:

Point next(const Point &p, uchar code) {
    int o[8*2] = {0,-1, 1,-1, 1,0, 1,1, 0,1, -1,1, -1,0, -1,-1};
    return Point(p.x+o[code*2], p.y+o[code*2+1]);
}
void reconstruct(const vector<uchar> &_chain, vector<Point> &contours, Point offset) {
    contours.push_back(offset);
    for (int i=0; i<_chain.size(); i++) {
        Point p = next(offset, _chain[i]);
        contours.push_back(p);
        offset = p;
    }
}

and then draw them like ordinary contours in opencv:

vector<uchar> chain {2, 2, 2, 2, 2, 2, 2, 2, 7, 7, 7, 7, .... (+ ~1700points) ..}

Mat draw(624,624,CV_8UC3,Scalar(0));
vector<vector<Point>> contours(1); // for drawContours
reconstruct(chain, contours[0], Point(10,300));
drawContours(draw, contours, -1, Scalar(0, 255, 0), 1);

image description

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-01 20:34:18 -0600

Seen: 809 times

Last updated: Jun 02 '17