Image basics
Overall goal
To get familiar with the libraries that mialab depends on, so you know what the data types and functions/methods that you'll use for the next several weeks look like.
Libraries here = numpy, SimpleITK. Later on, you will also be friends with matplotlib, pillow and scikit-learn. Optionally, if you're very social and like even more friends, you could try nibabel, scikit-image and our homegrown kid, pymia.
Getting started
GitHub Classroom is no longer used. Start by opening the image basics starter repository, selecting Fork, and creating the fork under your own GitHub account.
Clone your fork and edit image_basics.py, or edit the file directly in the browser.
Work in /<your-GitHub-username>/01-image-basics, not in the ubern-mialab starter repository. If GitHub asks you to enable workflows in your fork, open the Actions tab and enable them.
If you think you've made the right changes to the file, feel free to then commit the change, using the green "commit changes…" button if you are using the browser, and don't forget to include a helpful message about what the change really is.
Then, wait for the cogwheels to run: GitHub runs its 'actions' behind the scenes, and you'll either see a red ❌ or a green ✅ next to the commit message you entered previously.
The goal really is to get the green ✅ every time you make a change, which will only happen when all the functions are completed correctly (correctly as defined by the tests in test_image_basics.py, please don't cheat ;-)). Clicking on the check mark will show more details about completion of the homework.
Once you're done, please share both the link to your fork and the URL or SHA of your final commit with us, so we can confirm you've completed the assignment for the bonus grade (if such a need arises).
Tasks and specifics
The functions to complete, all in image_basics.py:
load_image- load an image using the SimpleITK Python interface, and return the pixel data based on whether it is a label or not.to_numpy_array- transform the SimpleITK image to a numpy ndarray.to_sitk_image- transform the numpy ndarray to a SimpleITK image (the reverse of the previous function).preprocess_rescale_numpy- rescale the intensities of thenp_imgto the range[new_min_val, new_max_val].preprocess_rescale_sitk- rescale the intensities of theimgto the range[new_min_val, new_max_val], but this time using SimpleITK.register_images- execute theregistration_methodon theimg(hint:fixed=atlas_img,moving=img); see the helpful comments within the function body.extract_feature_median- apply a median filter to the image.postprocess_largest_component- get the connected components from the image.
Help?
- Numpy documentation: https://numpy.org/doc/stable/user/absolute_beginners.html
- SimpleITK documentation: https://simpleitk.readthedocs.io/en/master/gettingStarted.html#python-binary-files
If neither of these two help, reach out to the instructors on Slack. Responses are not guaranteed to be time bound, we will do our best.