ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
608 stars 161 forks source link

Kmeans_segmentation - Probability Map #485

Closed ninea-anasovi closed 1 year ago

ninea-anasovi commented 1 year ago

Is your feature request related to a problem? Please describe. I am using Kmeans_segmentation function and there is option to use mask, I would appriciate to have option to use probability map fro segmentation and not mask. Unfortunately I have tried using probability map and I don't see differance in segmentation with binary mask and probability map. If it is considering values of the probability map there should be some differance.

Describe the solution you'd like I would love to have possibility to include probability map and not mask for kmeans_segmentation.

stnava commented 1 year ago

see help( ants.prior_based_segmentation )

ninea-anasovi commented 1 year ago

@stnava

Hello,

Thank you so much for your reply.

I had a chance to look at that function:

import ants
fi = ants.image_read(ants.get_ants_data('r16'))
seg = ants.kmeans_segmentation(fi,3)
mask = ants.threshold_image(seg['segmentation'], 1, 1e15)
priorseg = ants.prior_based_segmentation(fi, seg['probabilityimages'], mask, 0.25, 0.1, 3)

This is example written in documentation, however I have my very own probability map - map.nii that I want to include but as you can see from example this segmentation takes as an argument already segmented image by kmeans and takes segmentation['segmentation'] as a prior. could you please provide a way to include not kmeans_segmented but just plain .nii file as an input for this function?

it gave me type error while trying ants.image_read( "map.nii") file as an input.

Thank you

ntustison commented 1 year ago

ants.image_read( "map.nii") --- this should work if map.nii is the name of the file and the file is in the current directory.

ninea-anasovi commented 1 year ago
segmented = ants.prior_based_segmentation(coregistered_image, [map_image], binary_mask_image)

This is what I try to run "coregistered_image" is AntsImage map_image is also AntsImage and binary_mask_image is also AntsImage This is error that it gives:

segmented = ants.prior_based_segmentation(coregistered_image, [map_image], binary_mask_image)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ants/segmentation/prior_based_segmentation.py", line 65, in prior_based_segmentation
    pseg = atropos(a=image, m=mrf, c=conv, i=priors, x=mask, priorweight=priorweight)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ants/segmentation/atropos.py", line 146, in atropos
    probimgs = [iio2.image_read(probsout[0])]
IndexError: list index out of range

if I do :

segmented = ants.prior_based_segmentation(coregistered_image, [map_image, map_image], binary_mask_image)

It runs But I should be able to use just 1 image to do priors based segmentation. Isn't it right?

Sorry for asking so many questions and thank you for helping me.

ntustison commented 1 year ago

It runs But I should be able to use just 1 image to do priors based segmentation. Isn't it right?

You need a prior for each label/class including background.

ninea-anasovi commented 1 year ago

Thank you so much for the information. I think it would be better to somehow include that information in documentation. From my perspective as an user. It was not clear why it was not working for just one file.

Thank you again!