Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Handle exception when the image is too small after resizing for minimum patch sizes #136

Merged
merged 11 commits into from
Oct 23, 2018

Conversation

mathieuboudreau
Copy link
Member

@mathieuboudreau mathieuboudreau commented Sep 26, 2018

Resolves #34 , and also contributes to #29

The image dimensions are checked, and a descriptive message is printed if certain conditions are not met.

Two tests were added to make sure that an exit code 0 is given for a successful run, and an error code 2 for bad image size/resolution values (code 1 will be used later for invalid/unknown CLI inputs/options).

Example using the file from the issue using too small of a resolution:

(ads36_venv) mathieuboudreau@brassens:~/neuropoly/github/axondeepseg$ axondeepseg -t TEM -i Does_Kelm_072214_021.tif -v 2 -s 0.001
AxonDeepSeg v.2.2dev
EXCEPTION: The size of one of the images (2304x1888) is too small for the provided pixel size (0.001).
 The image size must be at least 512x512 after resampling to a resolution of 0.01 to create standard sized patches.
 One of the dimensions of the image has a size of 189 after resampling to that resolution.
 Image file location: Does_Kelm_072214_021.tif
(ads36_venv) mathieuboudreau@brassens:~/neuropoly/github/axondeepseg$ 

As mentioned in the issue, the processing work as expected for the actual resolution of that file:


(ads36_venv) mathieuboudreau@brassens:~/neuropoly/github/axondeepseg$ axondeepseg -t TEM -i Does_Kelm_072214_021.tif -v 2 -s 0.004
AxonDeepSeg v.2.2dev
Loading acquisitions ...
Rescaling acquisitions to the target resolution ...
Graph construction ...
Beginning inference ...
WARNING:root:Lossy conversion from int64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning.
WARNING:root:Lossy conversion from int64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning.
Image Does_Kelm_072214_021.tif segmented.
Segmentation finished.
(ads36_venv) mathieuboudreau@brassens:~/neuropoly/github/axondeepseg$ 

@coveralls
Copy link

coveralls commented Sep 26, 2018

Coverage Status

Coverage increased (+0.9%) to 81.104% when pulling f133314 on resolution_exception_handling into 476bb3f on master.

@mathieuboudreau
Copy link
Member Author

@jcohenadad this PR resolves an old issue you raised (#34), so I assigned you as the reviewer a while back. Do you have time to check it? If not I can assign @MelanieLu to do so.

Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, it does the trick. There is just a minor change of behaviour when the user does not input "-s" flag:

on master (2b2a15b):

axondeepseg -t TEM -i Does_Kelm_072214_021.tif -v 2
AxonDeepSeg v.2.1
Exception: ERROR: No pixel size is provided, and there is no pixel_size_in_micrometer.txt file in image folder. Please provide a pixel size (using argument -s), or add a pixel_size_in_micrometer.txt file containing the pixel size value.

this PR (1086204):

axondeepseg -t TEM -i Does_Kelm_072214_021.tif -v 2
AxonDeepSeg v.2.2dev
EXCEPTION: The size of one of the images (2304x1888) is too small for the provided pixel size (0.0).
 The image size must be at least 512x512 after resampling to a resolution of 0.01 to create standard sized patches.
 One of the dimensions of the image has a size of 0 after resampling to that resolution.
 Image file location: Does_Kelm_072214_021.tif

@mathieuboudreau
Copy link
Member Author

@jcohenadad Ah ha, nice catch.

This happens because the default CLI pixel size value was set to 0 when not value was given:

https://github.com/neuropoly/axondeepseg/blob/1086204a2c91ec3038d9ab0ce06cd9745f252cd1/AxonDeepSeg/segment.py#L246-L250

It throws my error because evidently a pixel size of 0 is smaller than the minimum size, and the other error you mention is only thrown much further in the pipeline and in another file:

https://github.com/neuropoly/axondeepseg/blob/49795de3617e5a453c2b7bba36f2756f9cfcbc3c/AxonDeepSeg/apply_model.py#L217-L233

instead of at the beginning like mine. They used the exact value of 0 as a an indicator of no given input.

I'll find a workaround for this – all exception handling for input parameters should be done in segment.py anyways, which is the file that interfaces with the command line.

@mathieuboudreau
Copy link
Member Author

@jcohenadad I think both cases are resolved now. I also implemented the exception handling for when a folder is provided instead of a direct link to the image – I had missed that/those case(s) too. All the cases (successes & exceptions) are now also covered by the testing suite, but check by yourself on the command line too.

Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested without -s and it now produces the expected behaviour. Awesome job @mathieuboudreau 👍

however i ventured to uncharted territories (as always), and created this bug (#138), which we can addrss in another PR.

@mathieuboudreau mathieuboudreau merged commit 9e59f53 into master Oct 23, 2018
@vasudev-sharma vasudev-sharma deleted the resolution_exception_handling branch November 4, 2020 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants