{"action":"created","issue":{"url":"https://api.github.com/repos/openimaj/openimaj/issues/86","labels_url":"https://api.github.com/repos/openimaj/openimaj/issues/86/labels{/name}","comments_url":"https://api.github.com/repos/openimaj/openimaj/issues/86/comments","events_url":"https://api.github.com/repos/openimaj/openimaj/issues/86/events","html_url":"https://github.com/openimaj/openimaj/issues/86","id":93631736,"number":86,"title":"java.lang.ArithmeticException: / by zero in ResizeProcessor.resizeMaxArea(FImage, int)","user":{"login":"bisoldi","id":9962726,"avatar_url":"https://avatars.githubusercontent.com/u/9962726?v=3","gravatar_id":"","url":"https://api.github.com/users/bisoldi","html_url":"https://github.com/bisoldi","followers_url":"https://api.github.com/users/bisoldi/followers","following_url":"https://api.github.com/users/bisoldi/following{/other_user}","gists_url":"https://api.github.com/users/bisoldi/gists{/gist_id}","starred_url":"https://api.github.com/users/bisoldi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bisoldi/subscriptions","organizations_url":"https://api.github.com/users/bisoldi/orgs","repos_url":"https://api.github.com/users/bisoldi/repos","events_url":"https://api.github.com/users/bisoldi/events{/privacy}","received_events_url":"https://api.github.com/users/bisoldi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-07T21:19:09Z","updated_at":"2015-07-14T17:49:06Z","closed_at":"2015-07-14T17:49:06Z","body":"While attempting to resize photo's of various unknown sizes, I encountered a divide by zero exception.\r\nThe relevant portion of the stacktrace is below:\r\n\r\nException in thread \"main\" java.lang.ArithmeticException: / by zero\r\nat org.openimaj.image.processing.resize.ResizeProcessor.resizeMaxArea(ResizeProcessor.java:443)\r\n\r\nUpon further review, it appears to only occur when the image height is greater than the width.  In such a circumstance, the whRatio float ends up being 0 as it performs integer division on line 441.  That then causes newWidth on line 442 to be 0 which then causes the exception on line 443.\r\n\r\nI don't know anything about the algorithm in general, however if you cast the width / height division to float prior to setting the result to whRatio, it no longer produces a 0 value.\r\n\r\nAdditionally, i'm not sure if this should be a separate issue or not, but I am also resizing images where the width is greater than the height and the resizing skews the aspect ratio.  Is the resizeMaxArea supposed to keep the aspect ratio?\r\n\r\n    final int width = 2687;\r\n    final int height = 3356;\r\n    final int area = width * height;\r\n    final int maxArea = 3700000;\r\n\r\n    final float whRatio = (float) width / height;\r\n    System.out.println(\"whRatio: \" + whRatio);\r\n        \r\n    final double newWidth = Math.sqrt(maxArea * whRatio);\r\n\r\n    System.out.println(\"New width: \" + newWidth);\r\n"},"comment":{"url":"https://api.github.com/repos/openimaj/openimaj/issues/comments/121321508","html_url":"https://github.com/openimaj/openimaj/issues/86#issuecomment-121321508","issue_url":"https://api.github.com/repos/openimaj/openimaj/issues/86","id":121321508,"user":{"login":"jonhare","id":1141847,"avatar_url":"https://avatars.githubusercontent.com/u/1141847?v=3","gravatar_id":"","url":"https://api.github.com/users/jonhare","html_url":"https://github.com/jonhare","followers_url":"https://api.github.com/users/jonhare/followers","following_url":"https://api.github.com/users/jonhare/following{/other_user}","gists_url":"https://api.github.com/users/jonhare/gists{/gist_id}","starred_url":"https://api.github.com/users/jonhare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonhare/subscriptions","organizations_url":"https://api.github.com/users/jonhare/orgs","repos_url":"https://api.github.com/users/jonhare/repos","events_url":"https://api.github.com/users/jonhare/events{/privacy}","received_events_url":"https://api.github.com/users/jonhare/received_events","type":"User","site_admin":false},"created_at":"2015-07-14T17:49:06Z","updated_at":"2015-07-14T17:49:06Z","body":"Ok, this looks rather buggy - as you've noted there is a problem with performing integer rather than floating point division for the whRatio. There was also an issue with the way the newHeight was computed (using the maxArea rather than the whRatio) which potentially caused the aspect ratio to change. This should now be fixed in commit 8e4fd4acaa65a4a1476126d769d758f6f5071da4 (together with unit tests :))."}}