-
Notifications
You must be signed in to change notification settings - Fork 3
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 a function to extract regions from a 2D image #1
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1 +/- ##
=========================================
Coverage ? 49.04%
=========================================
Files ? 5
Lines ? 314
Branches ? 0
=========================================
Hits ? 154
Misses ? 160
Partials ? 0
Continue to review full report at Codecov.
|
FYI, I am waiting on the feedback, via basecamp, on weather this should be here or in NSLS-II-SIX/sixtools before removing the "Do not merge" tag. |
The return value of this function -- a dictionary with labels mapped to subarrays -- is not the most useful representation. It is more useful to pass around slices: regions = {1: [slice(1, 2), slice(3, 4)], 2: [slice(3, 6), slice(2, 4)]} or so-called label arrays, which are a "paint by number" representation of this array: labels = np.zeros_like(arr) # an array of zeros with the same dimensions as arr
for i, region.items()
# Paint the subarray region with the number i.
labels[region] = i Then our label array array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 2., 2., 0., 0., 0., 0., 0., 0.],
[0., 0., 2., 2., 0., 0., 0., 0., 0., 0.],
[0., 0., 2., 2., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) Which of these is better depends on that context. Scikit-image provides tools for switching between them. |
Recommended reading: http://scikit-image.org/docs/dev/user_guide/numpy_images.html |
This is a good point, and much better form a memory usage point of view. I am about to move this stuff to NSLS-II-SIX/sixtools but will make this change at the same time. |
closing this as it is being moved to NSLS-II-SIX/sixtools |
This commit adds a function <extract_regions> which extracts regions from a 2D array and returns a dictionary containing the regions as well as the arrays related to those regions.