https://github.com/amilworks/segmentation

Applies mask (NIFTI format) to volumetric image (TIFF)

https://github.com/amilworks/segmentation

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 1 committers (100.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.1%) to scientific vocabulary

Keywords

bisque python segmentation
Last synced: 6 months ago · JSON representation

Repository

Applies mask (NIFTI format) to volumetric image (TIFF)

Basic Info
  • Host: GitHub
  • Owner: amilworks
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 19.6 MB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
bisque python segmentation
Created about 7 years ago · Last pushed almost 7 years ago
Metadata Files
Readme

README.md

The Segmentation Mask Merger 5000

Amil Khan | BisQue UCSB | Version 2.0


Plot a Test Image

This helper function takes in one argument, img_path, which is simply the path of the image on your local computer. This step can be stepped if: - You know what your data looks like - Trust that everything in this notebook works - Verified the absolute path of your image

Arguments: - img_path: local path to volumetric image data, i.e. .tif

python def image_visualizer5000(img_path, num_slice=0): img = skimage.io.imread(img_path, plugin='pil') print("Successfully Loaded. Image Shape:", img.shape) filename, file_extension = os.path.splitext(img_path) io.imshow(img[num_slice]) plt.title("Slice Number: {} of {}".format(num_slice, len(img)), loc='left') plt.axis('off')

python image_visualizer5000('/Users/macbook/Downloads/bisque-20190216.005014/T01.tif', num_slice=10)

Successfully Loaded. Image Shape: (28, 512, 512)

png

Segmentation Function

This function overlays a masked image over the original image takes two arguments, NIFTI_img and volumetric_img.

Arguments: - NIFTI_img: local path to NIFTI image, i.e. .nii - volumetric_img: local path to volumetric image data, i.e. .tif

Output: - Overlaid image. Basically, NIFTI image + Volumetric with slight darkening to non-segmented region

```python def segmentation(NIFTIimg, volumetricimg):

filename, file_extension = os.path.splitext(NIFTI_img)
if file_extension != '.nii':
    print("Invalid Filetype  --> ",filename+file_extension,"\nPlease check the filepath and/or if you are importing a valid NIFTI image.")
    return None

nii_img = nib.load(NIFTI_img)
nii_img = nii_img.get_fdata()
print("Successfully Loaded NIFTI Image", nii_img.shape)

mask = skimage.io.imread(volumetric_img, plugin='pil')
mask = np.swapaxes(mask, axis1=0, axis2=2)

print("Successfully Loaded Mask", mask.shape)
overlay = np.zeros_like(nii_img)

for i in range(nii_img.shape[-1]):
    overlay[:,:,i] = np.where((nii_img[:,:,i] >= 2) , mask[:,:,i], nii_img[:,:,i]*mask[:,:,i]+mask[:,:,i]/3)
    print('-', end=' ')
print("\nSegmentation Merge Finished!\nOutput Shape:", np.rollaxis(overlay, axis=2).shape)
return np.rollaxis(overlay, axis=2) # So BisQue can read and view image correctly

```

python tom = segmentation('/Users/macbook/Downloads/bisque-20190216.005040/all.nii', '/Users/macbook/Downloads/bisque-20190216.005014/T01.tif')

Successfully Loaded NIFTI Image (512, 512, 28)
Successfully Loaded Mask (512, 512, 28)
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Segmentation Merge Finished!
Output Shape: (28, 512, 512)

Verify the Output Image

python plt.imshow(tom[16], cmap='gray') plt.title('Segmented Image Overlay') plt.axis('off')

(-0.5, 511.5, 511.5, -0.5)

png

Output to HDF file

If you are feeling ambitious, you can output the image to an HDF file and visualize it in 2D slices and a 3D volume using BisQue. The output file will be created in your current working directory.

Arguments: - filename: name of the output hdf file - key_name: key/name of dataset in the HDF file - img: Output image from segmentation function

python def img_to_HDF(filename, key_name, img): f = h5py.File(filename, 'w') f.create_dataset(key_name, data=img) f.close()

python img_to_HDF(filename='SuperTom.h5', key_name='Finished_Product', img=tom)


Owner

  • Name: Amil Khan
  • Login: amilworks
  • Kind: user
  • Location: UCSB
  • Company: UCSB Electrical & Computer Engineering

PhD student in Electrical & Computer Engineering @ucsb, Lead Engineer @ BisQue

GitHub Events

Total
Last Year

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 10
  • Total Committers: 1
  • Avg Commits per committer: 10.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Amil Khan a****l@u****u 10
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels