{"action":"created","comment":{"url":"https://api.github.com/repos/Itseez/opencv/pulls/comments/23289725","id":23289725,"diff_hunk":"@@ -0,0 +1,163 @@\n+Image Segmentation with Distance Transform and Watershed Algorithm {#distance_transform}\n+=============\n+\n+Goal\n+----\n+\n+In this tutorial you will learn how to:\n+\n+-   Use the OpenCV function @ref cv::filter2D in order to perform some laplacian filtering for image sharpening\n+-   Use the OpenCV function @ref cv::distanceTransform in order to obtain the derived representation of a binary image, where the value of each pixel is replaced by its distance to the nearest background pixel\n+-   Use the OpenCV function @ref cv::watershed in order to isolate objects in the image from the background\n+\n+Theory\n+------\n+\n+Code\n+----\n+\n+This tutorial code's is shown lines below. You can also download it from\n+    [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/image_segmentation.cpp).\n+@includelineno samples/cpp/tutorial_code/ImgTrans/image_segmentation.cpp\n+\n+Explanation / Result\n+--------------------\n+\n+-#  Load the source image and check if it is loaded without any problem, then show it:\n+    @code{.cpp}\n+    \n+    Mat src = imread(argv[1]);\n+    \n+    if (!src.data)\n+        return -1;\n+     \n+    imshow(\"Source Image\", src);\n+    @endcode\n+![](images/source.jpeg)\n+\n+-#  Then if we have an image with white background, it is good to tranform it black. This will help us to desciminate the foreground objects easier when we will apply the Distance Transform:\n+    @code{.cpp}\n+    \n+    for( int x = 0; x < src.rows; x++ ) {\n+      for( int y = 0; y < src.cols; y++ ) {\n+          if ( src.at<Vec3b>(x, y) == Vec3b(255,255,255) ) {\n+            src.at<Vec3b>(x, y)[0] = 0;\n+            src.at<Vec3b>(x, y)[1] = 0;\n+            src.at<Vec3b>(x, y)[2] = 0;\n+          }\n+        }\n+    }\n+    \n+    imshow(\"Black Background Image\", src);\n+    @endcode\n+![](images/black_bg.jpeg)\n+\n+-#  Afterwards we will sharp our image in order to acute the edges of the foreground objects. We will apply a laplacian filter with a quite strong filter (an approximation of second derivative):\n+    @code{.cpp}\n+    \n+    Mat kernel = (Mat_<float>(3,3) <<\n+            1,  1, 1,\n+            1, -8, 1,\n+            1,  1, 1);\n+    \n+    Mat imgLaplacian;\n+    Mat sharp = src;\n+    filter2D(sharp, imgLaplacian, CV_32F, kernel);\n+    src.convertTo(sharp, CV_32F);\n+    Mat imgResult = sharp - imgLaplacian;\n+\n+    imgResult.convertTo(imgResult, CV_8UC3);\n+    imgLaplacian.convertTo(imgLaplacian, CV_8UC3);\n+\n+    imshow( \"Laplace Filtered Image\", imgLaplacian );\n+    imshow( \"New Sharped Image\", imgResult );\n+    @endcode\n+![](images/laplace.jpeg)![](images/sharp.jpeg)","path":"doc/tutorials/imgproc/imgtrans/distance_transformation/distance_transform.markdown","position":75,"original_position":75,"commit_id":"9b9719609c2722707a7934a304ea245a380b5449","original_commit_id":"9b9719609c2722707a7934a304ea245a380b5449","user":{"login":"mshabunin","id":3304494,"avatar_url":"https://avatars.githubusercontent.com/u/3304494?v=3","gravatar_id":"","url":"https://api.github.com/users/mshabunin","html_url":"https://github.com/mshabunin","followers_url":"https://api.github.com/users/mshabunin/followers","following_url":"https://api.github.com/users/mshabunin/following{/other_user}","gists_url":"https://api.github.com/users/mshabunin/gists{/gist_id}","starred_url":"https://api.github.com/users/mshabunin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshabunin/subscriptions","organizations_url":"https://api.github.com/users/mshabunin/orgs","repos_url":"https://api.github.com/users/mshabunin/repos","events_url":"https://api.github.com/users/mshabunin/events{/privacy}","received_events_url":"https://api.github.com/users/mshabunin/received_events","type":"User","site_admin":false},"body":"try to place a newline between these images:\r\n```\r\n![](images/laplace.jpeg)\r\n![](images/sharp.jpeg)\r\n```","created_at":"2015-01-21T10:23:13Z","updated_at":"2015-01-21T10:23:13Z","html_url":"https://github.com/Itseez/opencv/pull/3632#discussion_r23289725","pull_request_url":"https://api.github.com/repos/Itseez/opencv/pulls/3632","_links":{"self":{"href":"https://api.github.com/repos/Itseez/opencv/pulls/comments/23289725"},"html":{"href":"https://github.com/Itseez/opencv/pull/3632#discussion_r23289725"},"pull_request":{"href":"https://api.github.com/repos/Itseez/opencv/pulls/3632"}}},"pull_request":{"url":"https://api.github.com/repos/Itseez/opencv/pulls/3632","id":27734238,"html_url":"https://github.com/Itseez/opencv/pull/3632","diff_url":"https://github.com/Itseez/opencv/pull/3632.diff","patch_url":"https://github.com/Itseez/opencv/pull/3632.patch","issue_url":"https://api.github.com/repos/Itseez/opencv/issues/3632","number":3632,"state":"open","locked":false,"title":"Image Segmentation .cpp tutorial","user":{"login":"theodr","id":10189018,"avatar_url":"https://avatars.githubusercontent.com/u/10189018?v=3","gravatar_id":"","url":"https://api.github.com/users/theodr","html_url":"https://github.com/theodr","followers_url":"https://api.github.com/users/theodr/followers","following_url":"https://api.github.com/users/theodr/following{/other_user}","gists_url":"https://api.github.com/users/theodr/gists{/gist_id}","starred_url":"https://api.github.com/users/theodr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theodr/subscriptions","organizations_url":"https://api.github.com/users/theodr/orgs","repos_url":"https://api.github.com/users/theodr/repos","events_url":"https://api.github.com/users/theodr/events{/privacy}","received_events_url":"https://api.github.com/users/theodr/received_events","type":"User","site_admin":false},"body":"Since it is my first trial to contribute with github, I hope that I did everything correct.","created_at":"2015-01-21T04:12:11Z","updated_at":"2015-01-21T10:23:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f273d2981a33dc245ea2163dee94868018b6f88","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Itseez/opencv/pulls/3632/commits","review_comments_url":"https://api.github.com/repos/Itseez/opencv/pulls/3632/comments","review_comment_url":"https://api.github.com/repos/Itseez/opencv/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Itseez/opencv/issues/3632/comments","statuses_url":"https://api.github.com/repos/Itseez/opencv/statuses/9b9719609c2722707a7934a304ea245a380b5449","head":{"label":"theodr:dist_transf_tutorial","ref":"dist_transf_tutorial","sha":"9b9719609c2722707a7934a304ea245a380b5449","user":{"login":"theodr","id":10189018,"avatar_url":"https://avatars.githubusercontent.com/u/10189018?v=3","gravatar_id":"","url":"https://api.github.com/users/theodr","html_url":"https://github.com/theodr","followers_url":"https://api.github.com/users/theodr/followers","following_url":"https://api.github.com/users/theodr/following{/other_user}","gists_url":"https://api.github.com/users/theodr/gists{/gist_id}","starred_url":"https://api.github.com/users/theodr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theodr/subscriptions","organizations_url":"https://api.github.com/users/theodr/orgs","repos_url":"https://api.github.com/users/theodr/repos","events_url":"https://api.github.com/users/theodr/events{/privacy}","received_events_url":"https://api.github.com/users/theodr/received_events","type":"User","site_admin":false},"repo":{"id":29554278,"name":"opencv","full_name":"theodr/opencv","owner":{"login":"theodr","id":10189018,"avatar_url":"https://avatars.githubusercontent.com/u/10189018?v=3","gravatar_id":"","url":"https://api.github.com/users/theodr","html_url":"https://github.com/theodr","followers_url":"https://api.github.com/users/theodr/followers","following_url":"https://api.github.com/users/theodr/following{/other_user}","gists_url":"https://api.github.com/users/theodr/gists{/gist_id}","starred_url":"https://api.github.com/users/theodr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theodr/subscriptions","organizations_url":"https://api.github.com/users/theodr/orgs","repos_url":"https://api.github.com/users/theodr/repos","events_url":"https://api.github.com/users/theodr/events{/privacy}","received_events_url":"https://api.github.com/users/theodr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/theodr/opencv","description":"Open Source Computer Vision Library","fork":true,"url":"https://api.github.com/repos/theodr/opencv","forks_url":"https://api.github.com/repos/theodr/opencv/forks","keys_url":"https://api.github.com/repos/theodr/opencv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theodr/opencv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theodr/opencv/teams","hooks_url":"https://api.github.com/repos/theodr/opencv/hooks","issue_events_url":"https://api.github.com/repos/theodr/opencv/issues/events{/number}","events_url":"https://api.github.com/repos/theodr/opencv/events","assignees_url":"https://api.github.com/repos/theodr/opencv/assignees{/user}","branches_url":"https://api.github.com/repos/theodr/opencv/branches{/branch}","tags_url":"https://api.github.com/repos/theodr/opencv/tags","blobs_url":"https://api.github.com/repos/theodr/opencv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theodr/opencv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theodr/opencv/git/refs{/sha}","trees_url":"https://api.github.com/repos/theodr/opencv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theodr/opencv/statuses/{sha}","languages_url":"https://api.github.com/repos/theodr/opencv/languages","stargazers_url":"https://api.github.com/repos/theodr/opencv/stargazers","contributors_url":"https://api.github.com/repos/theodr/opencv/contributors","subscribers_url":"https://api.github.com/repos/theodr/opencv/subscribers","subscription_url":"https://api.github.com/repos/theodr/opencv/subscription","commits_url":"https://api.github.com/repos/theodr/opencv/commits{/sha}","git_commits_url":"https://api.github.com/repos/theodr/opencv/git/commits{/sha}","comments_url":"https://api.github.com/repos/theodr/opencv/comments{/number}","issue_comment_url":"https://api.github.com/repos/theodr/opencv/issues/comments/{number}","contents_url":"https://api.github.com/repos/theodr/opencv/contents/{+path}","compare_url":"https://api.github.com/repos/theodr/opencv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theodr/opencv/merges","archive_url":"https://api.github.com/repos/theodr/opencv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theodr/opencv/downloads","issues_url":"https://api.github.com/repos/theodr/opencv/issues{/number}","pulls_url":"https://api.github.com/repos/theodr/opencv/pulls{/number}","milestones_url":"https://api.github.com/repos/theodr/opencv/milestones{/number}","notifications_url":"https://api.github.com/repos/theodr/opencv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theodr/opencv/labels{/name}","releases_url":"https://api.github.com/repos/theodr/opencv/releases{/id}","created_at":"2015-01-20T21:56:54Z","updated_at":"2015-01-20T21:57:03Z","pushed_at":"2015-01-21T04:07:46Z","git_url":"git://github.com/theodr/opencv.git","ssh_url":"git@github.com:theodr/opencv.git","clone_url":"https://github.com/theodr/opencv.git","svn_url":"https://github.com/theodr/opencv","homepage":"opencv.org","size":430810,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Itseez:master","ref":"master","sha":"95ecdc3af965cd34412ebc6c39112e8b765326da","user":{"login":"Itseez","id":1786446,"avatar_url":"https://avatars.githubusercontent.com/u/1786446?v=3","gravatar_id":"","url":"https://api.github.com/users/Itseez","html_url":"https://github.com/Itseez","followers_url":"https://api.github.com/users/Itseez/followers","following_url":"https://api.github.com/users/Itseez/following{/other_user}","gists_url":"https://api.github.com/users/Itseez/gists{/gist_id}","starred_url":"https://api.github.com/users/Itseez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Itseez/subscriptions","organizations_url":"https://api.github.com/users/Itseez/orgs","repos_url":"https://api.github.com/users/Itseez/repos","events_url":"https://api.github.com/users/Itseez/events{/privacy}","received_events_url":"https://api.github.com/users/Itseez/received_events","type":"Organization","site_admin":false},"repo":{"id":5108051,"name":"opencv","full_name":"Itseez/opencv","owner":{"login":"Itseez","id":1786446,"avatar_url":"https://avatars.githubusercontent.com/u/1786446?v=3","gravatar_id":"","url":"https://api.github.com/users/Itseez","html_url":"https://github.com/Itseez","followers_url":"https://api.github.com/users/Itseez/followers","following_url":"https://api.github.com/users/Itseez/following{/other_user}","gists_url":"https://api.github.com/users/Itseez/gists{/gist_id}","starred_url":"https://api.github.com/users/Itseez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Itseez/subscriptions","organizations_url":"https://api.github.com/users/Itseez/orgs","repos_url":"https://api.github.com/users/Itseez/repos","events_url":"https://api.github.com/users/Itseez/events{/privacy}","received_events_url":"https://api.github.com/users/Itseez/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Itseez/opencv","description":"Open Source Computer Vision Library","fork":false,"url":"https://api.github.com/repos/Itseez/opencv","forks_url":"https://api.github.com/repos/Itseez/opencv/forks","keys_url":"https://api.github.com/repos/Itseez/opencv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Itseez/opencv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Itseez/opencv/teams","hooks_url":"https://api.github.com/repos/Itseez/opencv/hooks","issue_events_url":"https://api.github.com/repos/Itseez/opencv/issues/events{/number}","events_url":"https://api.github.com/repos/Itseez/opencv/events","assignees_url":"https://api.github.com/repos/Itseez/opencv/assignees{/user}","branches_url":"https://api.github.com/repos/Itseez/opencv/branches{/branch}","tags_url":"https://api.github.com/repos/Itseez/opencv/tags","blobs_url":"https://api.github.com/repos/Itseez/opencv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Itseez/opencv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Itseez/opencv/git/refs{/sha}","trees_url":"https://api.github.com/repos/Itseez/opencv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Itseez/opencv/statuses/{sha}","languages_url":"https://api.github.com/repos/Itseez/opencv/languages","stargazers_url":"https://api.github.com/repos/Itseez/opencv/stargazers","contributors_url":"https://api.github.com/repos/Itseez/opencv/contributors","subscribers_url":"https://api.github.com/repos/Itseez/opencv/subscribers","subscription_url":"https://api.github.com/repos/Itseez/opencv/subscription","commits_url":"https://api.github.com/repos/Itseez/opencv/commits{/sha}","git_commits_url":"https://api.github.com/repos/Itseez/opencv/git/commits{/sha}","comments_url":"https://api.github.com/repos/Itseez/opencv/comments{/number}","issue_comment_url":"https://api.github.com/repos/Itseez/opencv/issues/comments/{number}","contents_url":"https://api.github.com/repos/Itseez/opencv/contents/{+path}","compare_url":"https://api.github.com/repos/Itseez/opencv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Itseez/opencv/merges","archive_url":"https://api.github.com/repos/Itseez/opencv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Itseez/opencv/downloads","issues_url":"https://api.github.com/repos/Itseez/opencv/issues{/number}","pulls_url":"https://api.github.com/repos/Itseez/opencv/pulls{/number}","milestones_url":"https://api.github.com/repos/Itseez/opencv/milestones{/number}","notifications_url":"https://api.github.com/repos/Itseez/opencv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Itseez/opencv/labels{/name}","releases_url":"https://api.github.com/repos/Itseez/opencv/releases{/id}","created_at":"2012-07-19T09:40:17Z","updated_at":"2015-01-21T09:42:13Z","pushed_at":"2015-01-20T15:26:12Z","git_url":"git://github.com/Itseez/opencv.git","ssh_url":"git@github.com:Itseez/opencv.git","clone_url":"https://github.com/Itseez/opencv.git","svn_url":"https://github.com/Itseez/opencv","homepage":"opencv.org","size":1081597,"stargazers_count":4263,"watchers_count":4263,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3904,"mirror_url":null,"open_issues_count":26,"forks":3904,"open_issues":26,"watchers":4263,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Itseez/opencv/pulls/3632"},"html":{"href":"https://github.com/Itseez/opencv/pull/3632"},"issue":{"href":"https://api.github.com/repos/Itseez/opencv/issues/3632"},"comments":{"href":"https://api.github.com/repos/Itseez/opencv/issues/3632/comments"},"review_comments":{"href":"https://api.github.com/repos/Itseez/opencv/pulls/3632/comments"},"review_comment":{"href":"https://api.github.com/repos/Itseez/opencv/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Itseez/opencv/pulls/3632/commits"},"statuses":{"href":"https://api.github.com/repos/Itseez/opencv/statuses/9b9719609c2722707a7934a304ea245a380b5449"}}}}