I’m trying to find a way to do an approximated segmentation on graveyard images (in context of CBIR in cultural scienes – but that’s not the topic). So far I’m using this strategy:
- Blurr image twice (experimental findings)
- Apply Canny-Edge-Detector
-
Finding the contours
int main(int argc, const char* argv[]) { cout << "Starting " << endl; Mat sourceImage; sourceImage = imread("singlesegmentation/DSCN5204.JPG", CV_LOAD_IMAGE_COLOR); if (!sourceImage.data) { cout << "No Image found." << endl; return -1; } cv::Mat blurred = imagePro::blurrNtimes(2, sourceImage); cv::Mat target = edged::applyCanny(blurred); cout << "Canny applied " << endl; vector<vector<Point> > contours; vector<Vec4i> hierarchy; cv::Point offset; offset.x = sourceImage.rows / 2; offset.y = sourceImage.cols / 2; cv::findContours(target, contours, hierarchy, CV_RETR_TREE , CV_CHAIN_APPROX_SIMPLE, offset); cout << "Contours applied " << endl; int idx = 0; for (; idx >= 0; idx = hierarchy[idx][0]) { Scalar color(rand() & 255, rand() & 255, rand() & 255); drawContours(target, contours, idx, color, CV_FILLED, 8, hierarchy); } cout << "Lines applied " << endl; cv::namedWindow("Contour", CV_WINDOW_NORMAL); cv::imshow("Contour", target); cv::waitKey(0); return 0;}
The namespaces “imagePro” and “edged” contain simple code of opencv to blur a image and further process it. The code works. Here is an example-picture:

But now I have no idea to segment the image. I want to go from the inside to the outside of the rectangle-stone and when I find a line I want to remember the coordinates and then cut the content. Thank you if you have an idea or hint!
You could try use a Hough-Transformation (cv::HoughLinesP) see the tutorial examples http://docs.opencv.org/modules/imgproc/doc/feature_detection.html
In order to find the coordinates of the stone wihtin the picture you would need to calculate the intersections of the lines found by the hough-transformation. I used Gaussian-Blur followed by Laplace-Transformation (instead of canny-edge) for a similar use case.