{"action":"created","comment":{"url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/comments/186275530","pull_request_review_id":117828226,"id":186275530,"diff_hunk":"@@ -0,0 +1,129 @@\n+package core.action.edit.space_domain;\n+\n+import core.service.ImageOperationsService;\n+import core.service.MatrixService;\n+import domain.customimage.CustomImage;\n+import domain.customimage.Pixel;\n+import javafx.scene.image.Image;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+\n+public class ApplyGlobalThresholdEstimation {\n+\n+    private MatrixService matrixService;\n+    private int iterations;\n+    private int threshold;\n+    private List<Pixel> g1Pixels;\n+    private List<Pixel> g2Pixels;\n+\n+    public ApplyGlobalThresholdEstimation(MatrixService matrixService){\n+        this.matrixService = matrixService;\n+        this.iterations = 0;\n+        this.threshold = 0;\n+        this.g1Pixels = new ArrayList<Pixel>();\n+        this.g2Pixels = new ArrayList<Pixel>();\n+    }\n+\n+    public Image execute(CustomImage customImage, int initialThreshold, int deltaT){\n+        int[][] imageMatrix = this.matrixService.toGrayMatrix(customImage.toFXImage());\n+        this.threshold = initialThreshold;\n+        int[][] transformedImage = new int[imageMatrix.length][imageMatrix[0].length];\n+        int currentDeltaT = 99999;\n+        this.iterations = 0;\n+\n+        while (currentDeltaT > deltaT){\n+            transformedImage = this.applyThreshold(imageMatrix, threshold);\n+\n+            int[] g1AndG2Quantity = this.countG1AndG2(transformedImage);\n+            int g1Quantity = g1AndG2Quantity[0];\n+            int g2Quantity = g1AndG2Quantity[1];\n+            int m1 = this.calculateM1(imageMatrix, g1Quantity);\n+            int m2 = this.calculateM2(imageMatrix, g2Quantity);\n+            int oldThreshold = threshold;\n+            threshold = this.updateThreshold(m1, m2);\n+            currentDeltaT = Math.abs(oldThreshold - threshold);\n+            this.iterations++;\n+        }\n+        return this.matrixService.toImage(transformedImage, transformedImage, transformedImage);\n+    }\n+\n+    public int getIterations(){\n+        return this.iterations;\n+    }\n+\n+    public int getThreshold(){\n+        return this.threshold;\n+    }\n+\n+    private int[][] applyThreshold(int[][] image, int threshold){\n+        int width = image.length;\n+        int height = image[0].length;\n+        int[][] transformedMatrix = new int[width][height];\n+\n+        for (int i=0; i < width; i++) {\n+            for(int j=0; j < height; j++) {\n+                if (image[i][j] >= threshold) {\n+                    transformedMatrix[i][j] = 255;\n+                } else {\n+                    transformedMatrix[i][j] = 0;\n+                }\n+            }\n+        }\n+        return transformedMatrix;\n+    }\n+\n+    //G1 represents the amount of 0, and G2 the amount of 255\n+    //vector[0] = G1\n+    //vector[1] = G2\n+    private int[] countG1AndG2(int[][] image){","path":"src/core/action/edit/space_domain/ApplyGlobalThresholdEstimation.java","position":80,"original_position":80,"commit_id":"3d17726a920b5a28a05fe39da6cc6ab02326a271","original_commit_id":"9cc82bd8f422ff5b5a3e72b7fa3c18c804bbb0bb","user":{"login":"ferGainey","id":11777271,"avatar_url":"https://avatars3.githubusercontent.com/u/11777271?v=4","gravatar_id":"","url":"https://api.github.com/users/ferGainey","html_url":"https://github.com/ferGainey","followers_url":"https://api.github.com/users/ferGainey/followers","following_url":"https://api.github.com/users/ferGainey/following{/other_user}","gists_url":"https://api.github.com/users/ferGainey/gists{/gist_id}","starred_url":"https://api.github.com/users/ferGainey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ferGainey/subscriptions","organizations_url":"https://api.github.com/users/ferGainey/orgs","repos_url":"https://api.github.com/users/ferGainey/repos","events_url":"https://api.github.com/users/ferGainey/events{/privacy}","received_events_url":"https://api.github.com/users/ferGainey/received_events","type":"User","site_admin":false},"body":"Lo hice por un tema de performance así no recorro la imagen 2 veces","created_at":"2018-05-06T00:27:25Z","updated_at":"2018-05-06T00:27:25Z","html_url":"https://github.com/SynysterLove/ProcesamientoImagenes/pull/44#discussion_r186275530","pull_request_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/comments/186275530"},"html":{"href":"https://github.com/SynysterLove/ProcesamientoImagenes/pull/44#discussion_r186275530"},"pull_request":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44"}},"in_reply_to_id":186269372},"pull_request":{"url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44","id":186161828,"html_url":"https://github.com/SynysterLove/ProcesamientoImagenes/pull/44","diff_url":"https://github.com/SynysterLove/ProcesamientoImagenes/pull/44.diff","patch_url":"https://github.com/SynysterLove/ProcesamientoImagenes/pull/44.patch","issue_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/44","number":44,"state":"open","locked":false,"title":"Automatic threshold value calculation","user":{"login":"ferGainey","id":11777271,"avatar_url":"https://avatars3.githubusercontent.com/u/11777271?v=4","gravatar_id":"","url":"https://api.github.com/users/ferGainey","html_url":"https://github.com/ferGainey","followers_url":"https://api.github.com/users/ferGainey/followers","following_url":"https://api.github.com/users/ferGainey/following{/other_user}","gists_url":"https://api.github.com/users/ferGainey/gists{/gist_id}","starred_url":"https://api.github.com/users/ferGainey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ferGainey/subscriptions","organizations_url":"https://api.github.com/users/ferGainey/orgs","repos_url":"https://api.github.com/users/ferGainey/repos","events_url":"https://api.github.com/users/ferGainey/events{/privacy}","received_events_url":"https://api.github.com/users/ferGainey/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-05T15:33:48Z","updated_at":"2018-05-06T00:27:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b2513d600cd86db2791069efc28f344bd84ad29","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44/commits","review_comments_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44/comments","review_comment_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/44/comments","statuses_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/statuses/3d17726a920b5a28a05fe39da6cc6ab02326a271","head":{"label":"SynysterLove:automatic-threshold-value-calculation","ref":"automatic-threshold-value-calculation","sha":"3d17726a920b5a28a05fe39da6cc6ab02326a271","user":{"login":"SynysterLove","id":11827642,"avatar_url":"https://avatars0.githubusercontent.com/u/11827642?v=4","gravatar_id":"","url":"https://api.github.com/users/SynysterLove","html_url":"https://github.com/SynysterLove","followers_url":"https://api.github.com/users/SynysterLove/followers","following_url":"https://api.github.com/users/SynysterLove/following{/other_user}","gists_url":"https://api.github.com/users/SynysterLove/gists{/gist_id}","starred_url":"https://api.github.com/users/SynysterLove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SynysterLove/subscriptions","organizations_url":"https://api.github.com/users/SynysterLove/orgs","repos_url":"https://api.github.com/users/SynysterLove/repos","events_url":"https://api.github.com/users/SynysterLove/events{/privacy}","received_events_url":"https://api.github.com/users/SynysterLove/received_events","type":"User","site_admin":false},"repo":{"id":115046843,"name":"ProcesamientoImagenes","full_name":"SynysterLove/ProcesamientoImagenes","owner":{"login":"SynysterLove","id":11827642,"avatar_url":"https://avatars0.githubusercontent.com/u/11827642?v=4","gravatar_id":"","url":"https://api.github.com/users/SynysterLove","html_url":"https://github.com/SynysterLove","followers_url":"https://api.github.com/users/SynysterLove/followers","following_url":"https://api.github.com/users/SynysterLove/following{/other_user}","gists_url":"https://api.github.com/users/SynysterLove/gists{/gist_id}","starred_url":"https://api.github.com/users/SynysterLove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SynysterLove/subscriptions","organizations_url":"https://api.github.com/users/SynysterLove/orgs","repos_url":"https://api.github.com/users/SynysterLove/repos","events_url":"https://api.github.com/users/SynysterLove/events{/privacy}","received_events_url":"https://api.github.com/users/SynysterLove/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SynysterLove/ProcesamientoImagenes","description":null,"fork":false,"url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes","forks_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/forks","keys_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/teams","hooks_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/hooks","issue_events_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/events{/number}","events_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/events","assignees_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/assignees{/user}","branches_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/branches{/branch}","tags_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/tags","blobs_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/refs{/sha}","trees_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/statuses/{sha}","languages_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/languages","stargazers_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/stargazers","contributors_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/contributors","subscribers_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/subscribers","subscription_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/subscription","commits_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/commits{/sha}","git_commits_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/commits{/sha}","comments_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/comments{/number}","issue_comment_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/comments{/number}","contents_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/contents/{+path}","compare_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/merges","archive_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/downloads","issues_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues{/number}","pulls_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls{/number}","milestones_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/milestones{/number}","notifications_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/labels{/name}","releases_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/releases{/id}","deployments_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/deployments","created_at":"2017-12-21T21:02:53Z","updated_at":"2018-04-29T19:39:01Z","pushed_at":"2018-05-05T22:41:49Z","git_url":"git://github.com/SynysterLove/ProcesamientoImagenes.git","ssh_url":"git@github.com:SynysterLove/ProcesamientoImagenes.git","clone_url":"https://github.com/SynysterLove/ProcesamientoImagenes.git","svn_url":"https://github.com/SynysterLove/ProcesamientoImagenes","homepage":null,"size":2220,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"SynysterLove:tp2-features","ref":"tp2-features","sha":"b4f96e8de8dc198bb449cbaa1eef7dffa7b6c6a2","user":{"login":"SynysterLove","id":11827642,"avatar_url":"https://avatars0.githubusercontent.com/u/11827642?v=4","gravatar_id":"","url":"https://api.github.com/users/SynysterLove","html_url":"https://github.com/SynysterLove","followers_url":"https://api.github.com/users/SynysterLove/followers","following_url":"https://api.github.com/users/SynysterLove/following{/other_user}","gists_url":"https://api.github.com/users/SynysterLove/gists{/gist_id}","starred_url":"https://api.github.com/users/SynysterLove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SynysterLove/subscriptions","organizations_url":"https://api.github.com/users/SynysterLove/orgs","repos_url":"https://api.github.com/users/SynysterLove/repos","events_url":"https://api.github.com/users/SynysterLove/events{/privacy}","received_events_url":"https://api.github.com/users/SynysterLove/received_events","type":"User","site_admin":false},"repo":{"id":115046843,"name":"ProcesamientoImagenes","full_name":"SynysterLove/ProcesamientoImagenes","owner":{"login":"SynysterLove","id":11827642,"avatar_url":"https://avatars0.githubusercontent.com/u/11827642?v=4","gravatar_id":"","url":"https://api.github.com/users/SynysterLove","html_url":"https://github.com/SynysterLove","followers_url":"https://api.github.com/users/SynysterLove/followers","following_url":"https://api.github.com/users/SynysterLove/following{/other_user}","gists_url":"https://api.github.com/users/SynysterLove/gists{/gist_id}","starred_url":"https://api.github.com/users/SynysterLove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SynysterLove/subscriptions","organizations_url":"https://api.github.com/users/SynysterLove/orgs","repos_url":"https://api.github.com/users/SynysterLove/repos","events_url":"https://api.github.com/users/SynysterLove/events{/privacy}","received_events_url":"https://api.github.com/users/SynysterLove/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SynysterLove/ProcesamientoImagenes","description":null,"fork":false,"url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes","forks_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/forks","keys_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/teams","hooks_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/hooks","issue_events_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/events{/number}","events_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/events","assignees_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/assignees{/user}","branches_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/branches{/branch}","tags_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/tags","blobs_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/refs{/sha}","trees_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/statuses/{sha}","languages_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/languages","stargazers_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/stargazers","contributors_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/contributors","subscribers_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/subscribers","subscription_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/subscription","commits_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/commits{/sha}","git_commits_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/git/commits{/sha}","comments_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/comments{/number}","issue_comment_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/comments{/number}","contents_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/contents/{+path}","compare_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/merges","archive_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/downloads","issues_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues{/number}","pulls_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls{/number}","milestones_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/milestones{/number}","notifications_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/labels{/name}","releases_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/releases{/id}","deployments_url":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/deployments","created_at":"2017-12-21T21:02:53Z","updated_at":"2018-04-29T19:39:01Z","pushed_at":"2018-05-05T22:41:49Z","git_url":"git://github.com/SynysterLove/ProcesamientoImagenes.git","ssh_url":"git@github.com:SynysterLove/ProcesamientoImagenes.git","clone_url":"https://github.com/SynysterLove/ProcesamientoImagenes.git","svn_url":"https://github.com/SynysterLove/ProcesamientoImagenes","homepage":null,"size":2220,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44"},"html":{"href":"https://github.com/SynysterLove/ProcesamientoImagenes/pull/44"},"issue":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/44"},"comments":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/SynysterLove/ProcesamientoImagenes/statuses/3d17726a920b5a28a05fe39da6cc6ab02326a271"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"ferGainey"}}