{"action":"created","issue":{"url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/issues/5","labels_url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/issues/5/comments","events_url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/issues/5/events","html_url":"https://github.com/lucasb-eyer/pydensecrf/pull/5","id":125847828,"number":5,"title":"Fix height width order in dense_inference.py example","user":{"login":"kevin-keraudren","id":802153,"avatar_url":"https://avatars.githubusercontent.com/u/802153?v=3","gravatar_id":"","url":"https://api.github.com/users/kevin-keraudren","html_url":"https://github.com/kevin-keraudren","followers_url":"https://api.github.com/users/kevin-keraudren/followers","following_url":"https://api.github.com/users/kevin-keraudren/following{/other_user}","gists_url":"https://api.github.com/users/kevin-keraudren/gists{/gist_id}","starred_url":"https://api.github.com/users/kevin-keraudren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevin-keraudren/subscriptions","organizations_url":"https://api.github.com/users/kevin-keraudren/orgs","repos_url":"https://api.github.com/users/kevin-keraudren/repos","events_url":"https://api.github.com/users/kevin-keraudren/events{/privacy}","received_events_url":"https://api.github.com/users/kevin-keraudren/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-10T21:44:59Z","updated_at":"2016-01-11T13:09:18Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/pulls/5","html_url":"https://github.com/lucasb-eyer/pydensecrf/pull/5","diff_url":"https://github.com/lucasb-eyer/pydensecrf/pull/5.diff","patch_url":"https://github.com/lucasb-eyer/pydensecrf/pull/5.patch"},"body":"The proper syntax is `dcrf.DenseCRF2D(img.shape[1], img.shape[0], M)`.\r\n\r\nThis has to do with C-ordering versus Fortran ordering, also known as https://en.wikipedia.org/wiki/Row-major_order .\r\n\r\nThis bug can be highlighted with the following parameters:\r\n\r\n```\r\nd.addPairwiseGaussian(sxy=3, compat=0)\r\nd.addPairwiseBilateral(sxy=3, srgb=5, rgbim=img, compat=50)\r\n````\r\n`(img.shape[0], img.shape[1])` gives:\r\n![image](https://cloud.githubusercontent.com/assets/802153/12224213/bf72275c-b7e2-11e5-8087-bfc376297c0b.png)\r\n\r\nNote the straight lines characteristic of a stride misalignement.\r\n\r\nOn the other hand, `(img.shape[1], img.shape[0])` gives:\r\n![image](https://cloud.githubusercontent.com/assets/802153/12224217/c67476ae-b7e2-11e5-9db2-319b7bc31fc3.png)\r\n\r\nThis is confirmed by this other Python wrapper for densecrf:\r\n\r\nSee the order `(D, W, H)` at this line:\r\nhttps://github.com/mbickel/DenseInferenceWrapper/blob/master/denseinference/lib/libDenseCRF/densecrf.cpp#L139\r\n\r\nwhile the original 2D code is `(H, W)`."},"comment":{"url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/issues/comments/170544095","html_url":"https://github.com/lucasb-eyer/pydensecrf/pull/5#issuecomment-170544095","issue_url":"https://api.github.com/repos/lucasb-eyer/pydensecrf/issues/5","id":170544095,"user":{"login":"kevin-keraudren","id":802153,"avatar_url":"https://avatars.githubusercontent.com/u/802153?v=3","gravatar_id":"","url":"https://api.github.com/users/kevin-keraudren","html_url":"https://github.com/kevin-keraudren","followers_url":"https://api.github.com/users/kevin-keraudren/followers","following_url":"https://api.github.com/users/kevin-keraudren/following{/other_user}","gists_url":"https://api.github.com/users/kevin-keraudren/gists{/gist_id}","starred_url":"https://api.github.com/users/kevin-keraudren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevin-keraudren/subscriptions","organizations_url":"https://api.github.com/users/kevin-keraudren/orgs","repos_url":"https://api.github.com/users/kevin-keraudren/repos","events_url":"https://api.github.com/users/kevin-keraudren/events{/privacy}","received_events_url":"https://api.github.com/users/kevin-keraudren/received_events","type":"User","site_admin":false},"created_at":"2016-01-11T13:09:18Z","updated_at":"2016-01-11T13:09:18Z","body":"This is where we access the flattened numpy arrays:\r\nhttps://github.com/lucasb-eyer/pydensecrf/blob/master/densecrf/src/densecrf.cpp#L63-L67\r\nhttps://github.com/lucasb-eyer/pydensecrf/blob/master/densecrf/src/densecrf.cpp#L72-L79\r\n\r\nAnd regarding the pixel ordering of OpenCV images in Python, I refer you to this old thread:\r\nhttp://opencv-users.1802565.n2.nabble.com/OpenCV-y-x-points-for-numpy-x-y-points-td7054352.html#a7059295\r\n\r\nWhich can be summarised by:\r\n```\r\nheight = img.shape[0] # y\r\nwidth = img.shape[1] # x\r\n```\r\n\r\nWhich is consistent with the C++ code:\r\n```\r\nDenseCRF2D::DenseCRF2D(int W, int H, int M) : DenseCRF(W*H,M), W_(W), H_(H) {\r\n}\r\n```\r\n\r\nAnd the python code:\r\n```\r\ndcrf.DenseCRF2D(img.shape[1], img.shape[0], M)\r\n```\r\n"}}