Image Basics

Overall Goal

To get familiar with libraries that mialab depends onarrow-up-right, so you know what the data types and functions/methods that you'll use for the next several weeks look like.

Libraries here = numpyarrow-up-right, simpleITKarrow-up-right. 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

This exercise is organized using GitHub Classroom, where every time you commit a change, it automatically runs the test script and evaluates if you did the right thing or not. To attempt the assignment:

https://classroom.github.com/a/zarh_Oy7arrow-up-right

This should create a private repository for you. Then, you can simply open the script image_basics.py and then edit it, all within the browser or clone to work on it.

circle-info

Note that you'll have to change the location of the repository from */ubern-mialab/* to */<your-GitHub-username>/* in the above links, once you have forked correctly.

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 it's '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 a link to your fork with us, so we can confirm you've completed the assignment for the bonus grade (if such a need arises).

This is the first time we set up every exercise using GitHub classroom, so do not hesitate to contact us on Slack if you meet any trouble.

Tasks and specifics

load_image - load an image using the SimpleITK python interface, and return the pixel data based on if it is a label or not.

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L5arrow-up-right

to_numpy_array - transform the SimpleITK image to a numpy ndarray.

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L18arrow-up-right

to_sitk_image - transform the numpy ndarray to a SimpleITK image (the reverse of the previous function)

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L28arrow-up-right

preprocess_rescale_numpy - rescale the intensities of the np_img to the range [new_min_val, new_max_val].

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L42arrow-up-right

preprocess_rescale_sitk - rescale the intensities of the img to the range [new_min_val, new_max_val], but this time, using SimpleITK

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L56arrow-up-right

register_images - execute the registration_method to the img (hint: fixed=atlas_img, moving=img); see helpful comments within the function body here: https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L67arrow-up-right

extract_feature_median - apply median filter to image

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L93arrow-up-right

postprocess_largest_component - get the connected components from the image

https://github.com/ubern-mialab/01-image-basics/blob/d05df6945dee4841f7016cd2aab28a2eb800ffd7/image_basics.py#L103arrow-up-right

Help?

Numpy documentation: https://numpy.org/doc/stable/user/absolute_beginners.htmlarrow-up-right

SimpleITK documentation: https://simpleitk.readthedocs.io/en/master/gettingStarted.html#python-binary-filesarrow-up-right

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.

Last updated