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
Add bounding box iteration #466
Merged
JoostJM
merged 7 commits into
AIM-Harvard:master
from
JoostJM:add-bounding-box-iteration
Mar 1, 2019
Merged
Add bounding box iteration #466
JoostJM
merged 7 commits into
AIM-Harvard:master
from
JoostJM:add-bounding-box-iteration
Mar 1, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JoostJM
force-pushed
the
add-bounding-box-iteration
branch
5 times, most recently
from
February 20, 2019 16:23
d69cb4c
to
4125f3e
Compare
Update C extensions to iterate only over a view of the image (bounding box). This can be used later on to rapidly define kernels for a voxel based-calculation. - Define bounding box array as {L_0, L_1, ..., L_n, U_0, U_1, ..., U_n} (i.e. first all lower bounds, then all upper bounds). - Start iteration over the image on by calculating the first `i` from the lower bounds. - Upon each increase of `i`, calculate to see if `i` exceeds image bounds, and if so, increase `i` in that dimension to the lower bound. - When computing neighbours, compare against bounding box instead of size to determine valid angles. - For now, fix bb initialization to {0, size - 1} in each dimension. Testing: - Add print statements in GLCM and GLRLM to reflect new behaviour. Finally, add a check to ensure allocation for memory for `size` and `strides` is successful.
Add an extra dimension as the first dimension of each texture matrix, which will correspond to the matrix for the segment (segment-based, size 1) or the specific kernel identified by the voxel index in the passed array (voxel-based). This will allow a more vectorized calculation of kernels when processing in by-voxel mode. Additionally, update the python formulas to allow for this additional dimension by adding axis specifications to all reducing operations and updating defined axes to shift by +1. Use numpy.squeeze to convert the returned result in segment-based calculation from a 1-D array with size 1 to a scalar float value.
Implement vectorized calculation of voxel kernels and remove need of kernel generation for voxel-based calculation of texture matrices. For the latter, define kernels by updating the bounding box for calculation on the fly in the C extension. The mask array is then only utilized to either mask the kernels (`maskedKernel=True`, maskArray elements true where segmented) or no mask, in which case the maskArray is set to `numpy.ones` of `shape(imageArray)`. This reduces both the number of python-based loops, as the iteration time in the C extension (only iterates over the kernel for each voxel, not the entire image). Vectorize all feature formulas (exception: shape and shape2D features) Update firstorder to work with vectorized calculation (add dimension to `targetVoxelArray`, add `discretizedTargetVoxelArray`. Add voxelSetting parameter `voxelBatch`, which controls the maximum number of voxel calculated in a vectorized way (allows specification of less voxels in 1 batch to conserve memory). Default setting of -1 means all voxels are calculated in one batch Additionally, remove `self.matrix`, as this is reference equal to `self.imageArray` when applying binning.
In segment based mode, empty angles are removed from the calculation, but when calculating multiple voxel kernels, empty angles may presist (empty in some kernels, not in others). Exclude those angles from the calculations per voxel by setting them to NaN and using `nanmean` for combining angle results. Additionally, move some of the coefficients that are only used in single features to those features. Conserves memory and prevents unnecessary calculation.
When growing the regions, mask voxels are set to 0 to prevent reprocessing. However, when extracting voxel-based, these need to be reset to allow for correct processing of voxels in the subsequent kernels. Therefore, if Nvox > 1, keep track of the processed voxels and reset them after processing. Additionally, force cast PyArray_DIM to make function `try_parse_voxels_arr` consistent with function `try_parse_arrays`.
JoostJM
force-pushed
the
add-bounding-box-iteration
branch
from
February 20, 2019 16:29
4125f3e
to
aecc8ec
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Builds on PR #463 by adding bounding-box constrained iteration in the C extensions.
This is then used to speed up and simplify voxel-based extraction: