ofgulban / segmentator

3D MRI data exploration and segmentation tool.
https://github.com/ofgulban/segmentator/wiki
BSD 3-Clause "New" or "Revised" License
74 stars 13 forks source link

Upgrades code for Python 3.8 & adds slider for image brightness and mask alpha channel #89

Open klezm opened 4 years ago

klezm commented 4 years ago

Overall there are 4 changes to the code

  1. Upgrade the code to be ready for Python 3.8 (using https://github.com/asottile/pyupgrade)
  2. I added a slider to control the brightness of the image. Actually i change the alpha channel and set or unset a black Background.
  3. Another slider for the alpha channel of the mask
  4. minor changes in the appearance
    1. Change palette from Reds to white and magenta
    2. more space for the plots in the matplotlib window

Examples:

1

The same as above, but now with a bright image and a more transparent mask:

2

ofgulban commented 4 years ago

Hi @klezm ,

Thanks a lot for your detailed and orderly pull request. Looks very good already. I will have a more detailed look next week after tuesday for merging :)

May I ask what type of image is your input in the pictures above? Just curiosity :)

klezm commented 4 years ago

I found some open datasets on http://www.informatik.uni-leipzig.de/~wiebel/public_data/index.html where I picked the "Abdominal MRI" dataset.

But for my purpose I used your tools to analyse microscopy images.

Btw. I would recommend you to look at the commits separately since most of the changes are from pyupgrade

klezm commented 4 years ago

That's the code i used to convert a numpy array to the nifti format.

import nibabel
import numpy as np

ims = np.arange(3*5*5).reshape((3, 5, 5))
print(ims.shape)  # 3 Images of shape (5, 5)

ims = np.moveaxis(ims, 0, -1)  # segmentator has a "cylce" button to move the axes as well
nii = nibabel.Nifti1Image(ims, affine = np.eye(4))
print(nii.dataobj.shape)

nibabel.save(nii, "test.nii")
# nii.to_filename("test.nii")  # equivalent to the command above

Maybe I could implement the functionality to load folders as well.

ofgulban commented 4 years ago

Hey @klezm , cool. I did not work with microscopy images but I am happy to hear that Segmentator is being used on images other than MRI brains :).

If you would like to add functionality to load such images, I would be happy to have it as another pull request. Though, your code seems perfect for a quick nifti conversion. I also have similar scripts to generate synthetic images etc.

Sorry I was a bit late responding, had a paper came back for revision recently. Probably I will only have time to inspect the pull requests around a month or so. But I really appreciate your contribution, and do feel free to add the additional image loading capability if you wish so :)