{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1475","labels_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1475/labels{/name}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1475/comments","events_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1475/events","html_url":"https://github.com/scikit-image/scikit-image/pull/1475","id":69606185,"number":1475,"title":"Fixed crashing bug in slic.","user":{"login":"gustavla","id":902935,"avatar_url":"https://avatars.githubusercontent.com/u/902935?v=3","gravatar_id":"","url":"https://api.github.com/users/gustavla","html_url":"https://github.com/gustavla","followers_url":"https://api.github.com/users/gustavla/followers","following_url":"https://api.github.com/users/gustavla/following{/other_user}","gists_url":"https://api.github.com/users/gustavla/gists{/gist_id}","starred_url":"https://api.github.com/users/gustavla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gustavla/subscriptions","organizations_url":"https://api.github.com/users/gustavla/orgs","repos_url":"https://api.github.com/users/gustavla/repos","events_url":"https://api.github.com/users/gustavla/events{/privacy}","received_events_url":"https://api.github.com/users/gustavla/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-20T14:56:52Z","updated_at":"2015-04-20T17:25:10Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1475","html_url":"https://github.com/scikit-image/scikit-image/pull/1475","diff_url":"https://github.com/scikit-image/scikit-image/pull/1475.diff","patch_url":"https://github.com/scikit-image/scikit-image/pull/1475.patch"},"body":"The enforce connectivity step of slic runs a BFS and puts the\r\nresults in `coord_list`. This `coord_list` has room for `max_size` elements,\r\nwhich is easily overrun if there is a large connected element. This\r\nchange limits the BFS to `max_size`, so that if a connected area is bigger\r\nthan `max_size`, it will be split up instead of causing the program to crash.\r\n\r\nI'll add that this crash happens a lot for me with natural images and the default \r\n`max_size_factor` of 3. The easiest way to reproduce this bug though is to \r\nreduce `max_size_factor`:\r\n\r\n    from skimage.segmentation import slic\r\n    import numpy as np\r\n    rs = np.random.RandomState(0)\r\n    x = rs.uniform(size=(32, 32))\r\n    slic(x, n_segments=100, enforce_connectivity=True, max_size_factor=1)\r\n\r\nRandom noise does not generate large connected elements, which is why \r\n`max_size_factor` needs to be set so low to reproduce the error."},"comment":{"url":"https://api.github.com/repos/scikit-image/scikit-image/issues/comments/94515406","html_url":"https://github.com/scikit-image/scikit-image/pull/1475#issuecomment-94515406","issue_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1475","id":94515406,"user":{"login":"stefanv","id":45071,"avatar_url":"https://avatars.githubusercontent.com/u/45071?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanv","html_url":"https://github.com/stefanv","followers_url":"https://api.github.com/users/stefanv/followers","following_url":"https://api.github.com/users/stefanv/following{/other_user}","gists_url":"https://api.github.com/users/stefanv/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanv/subscriptions","organizations_url":"https://api.github.com/users/stefanv/orgs","repos_url":"https://api.github.com/users/stefanv/repos","events_url":"https://api.github.com/users/stefanv/events{/privacy}","received_events_url":"https://api.github.com/users/stefanv/received_events","type":"User","site_admin":false},"created_at":"2015-04-20T17:25:09Z","updated_at":"2015-04-20T17:25:09Z","body":"@gustavla Thank you very much for working out a fix to this problem!  Would you kindly add a unit test to trigger the behaviour?"}}