ANTsX / ANTsPyNet

Pre-trained models and utilities for deep learning on medical images in Python
https://antspynet.readthedocs.io
Apache License 2.0
182 stars 28 forks source link

Inconsistent patch size from antspynet.extract_image_patches #46

Closed stnava closed 2 years ago

stnava commented 2 years ago

hi @ntustison - do you know a quick solution to this?

img=ants.image_read( ants.get_data( "r16" ) )
radder=[20,20]
msk=ants.get_mask( img )
ptch = antspynet.extract_image_patches( img, tuple(radder), mask_image=msk, 
  max_number_of_patches = 512, return_as_array=False )
for k in range(512):
     print( ptch[k].shape )

shows patches of variable sizes. when trying to compute consistent patch statistics, this can lead to issues of power. I believe this behavior is different from antsrnet.

img=ri(1)
radder=c(20,20)
msk=getMask( img )
ptch = extractImagePatches( img, radder, maskImage=msk, 
  max_number_of_patches = 512, return_as_array=False )
ntustison commented 2 years ago

Oh, that's not good. Let me see if I can figure it out.

ntustison commented 2 years ago

Hey, @stnava , I just ran your code snippet a couple times on a couple different machines (2 macs/python 3.7 and archeozoic/python 3.8) and I'm getting patch shapes of the same size (20, 20). What are you getting?

stnava commented 2 years ago

this should do it more reliably

import ants
import antspynet
msk=ants.image_read("exmsk.nii.gz")
img=ants.image_read("eximg.nii.gz")
ptch = antspynet.extract_image_patches( img, tuple([20,20,20]), mask_image=msk,max_number_of_patches = 1000, return_as_array=False )
for k in range(len(ptch)):
    print(ptch[k].shape)

you see things like: (20, 20, 13)

exmsk.nii.gz eximg.nii.gz

I just ran this on archeozoic - images are in my ~/

stnava commented 2 years ago

image

just trying to get this application correct - images sorted by quality using a blind image quality method

stnava commented 2 years ago

were you able to reproduce?

ntustison commented 2 years ago

Sorry @stnava , just getting breakfast for the kids. I’ll test it in just a sec.

stnava commented 2 years ago

np - am about to head out for surf in 4 degree weather

ntustison commented 2 years ago

Oh, man, that’s insane.

ntustison commented 2 years ago

Okay, yeah, I was able to reproduce. Interesting that it seems to be only in the 3rd dimension which makes me wonder if it is a dimensionality issue when I modified the code from 2-D to 3-D.

I have to go run an errand (on my OneWheel so it'll kind of be like surfing but in 64 degree weather) but I'll work on it when I get back.

ntustison commented 2 years ago

Okay, check this commit which should fix the issue.

stnava commented 2 years ago

that did it - thx! do you have any thoughts on my PR?

ntustison commented 2 years ago

Great. During my attempts at debugging, I found a second, unrelated bug so I'm glad you discovered this issue.

I really didn't have any thoughts on the brain extraction part as I just assumed you had discovered a problem with "nobrainer". If its related to quality assessment than I confess I haven't used that much (although I was thinking quite a bit about these models recently with deep flash and using it to see if it is as I suspect that DeepFlash performs relatively better (compared to e.g., FreeSurfer) on higher quality data.

stnava commented 2 years ago

Ok - I have several approaches to quality assessment

Important to note that outlierness , aesthetic quality versus noise versus information scale and other things are all a piece of the puzzle

On Sat, Jan 15, 2022 at 6:24 PM Nick Tustison @.***> wrote:

Great. During my attempts at debugging, I found a second, unrelated bug so I'm glad you discovered this issue.

I really didn't have any thoughts on the brain extraction part as I just assumed you had discovered a problem with "nobrainer". If its related to quality assessment than I confess I haven't used that much (although I was thinking quite a bit about these models recently with deep flash and using it to see if it is as I suspect that DeepFlash performs relatively better (compared to e.g., FreeSurfer) on higher quality data.

— Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsPyNet/issues/46#issuecomment-1013770288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPE7WNLIMMEQU4STOWC2TUWH6ZNANCNFSM5MBAKWMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>

--

brian