Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crop and pad around mask center #104

Closed
romainVala opened this issue Mar 24, 2020 · 8 comments
Closed

crop and pad around mask center #104

romainVala opened this issue Mar 24, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@romainVala
Copy link
Contributor

Hello

what do you things of the possibility to do the same as CenterCropOrPad, but instead of take the center of the image I would like to take the centre of a label mask (center of non zero element)

Could be very useful to get the same field of view center on the brain, if you have a brain mask.

It could either be an option in CenerCropOrPad, or a new class ... ?

this may be a little bit tricky since there could be a crop for the lower part and a pad for the upper part ...

++

@fepegar
Copy link
Owner

fepegar commented Mar 24, 2020

Hi Romain,
Is this something you would like to use? It does seem a bit complex for a transform and more like something that could be done beforehand.

In case we wanted to implement it, I guess it could be something like: CenterCropOrPad(padding, around=x), where x can be the name of the label image or even a point in voxel or world coordinates.

What if the label image has more than one connected component? Only the largest should be used? What should be used, the centroid of the component or the middle of its bounding box?

Once there is a center, I think the best would be creating a new image with the desired bounds (being careful about computing the origin) and resampling the intensity images with an identity transform using the computed image as reference. Would you like to work on this?

@fepegar fepegar added the enhancement New feature or request label Mar 24, 2020
@romainVala
Copy link
Contributor Author

Hi
yes I need it to process T1 'raw' images that have different field of view, and different head position.
I agree usually one use to coregister and reslice to a common template, but since I try to learn the motion, keeping the acquisition plan is importante, so I would like to avoid reslicing

In my case I will apply it with brain mask so only one connected component, and then If I understand correctly the centroid is the same a the middle of the bounding box, no ?

The way I imagine is to find min max index of nozero voxel of the mask. this gives me a mask field of view and I take the center to then compute crop and pad

I do not understand your last point, once I have the center, why do I need to reslice ? I want to compute crop or pad in each side of the center separatly

I can try to make a proposition and let you choose to incorporate it or not. Should I make a new class ?

@fepegar
Copy link
Owner

fepegar commented Mar 24, 2020

You're right that reslicing/resampling is not needed. I just thought of it as the fastest way of implementing, but I'm probably wrong/lazy. Note, though, that no interpolation would be needed so the operation would be lossless and very fast.

What I meant with preprocessing is cropping all images before training. But I guess you're planning to apply e.g. rotations on the fly and then you want to crop the image around the brain, wherever it ends up. And that's why you want a transform. Is this correct?

Maybe a general CropOrPad class can be used to crop or pad around a point, not necessarily the center.

About the centroid vs bounding box. Consider this image:

1 1 1
1 0 0
1 0 0

The bounding box center is (1, 1). The centroid/center of mass of the connected component is (0.6, 0.6).

@romainVala
Copy link
Contributor Author

yes exactly having it as a transform will make it easy to check different order (first motion then crop)
thanks for the difference between box center and centroid, from this example I would prefer the box center, because what is importante is to have a field of view center around min and max (in each directions)

I'll see what we can achieve and let you know

@fepegar
Copy link
Owner

fepegar commented Mar 24, 2020

Great, thanks! I think the code would be quite similar to CenterCropOrPad, so you can start from there.

@romainVala
Copy link
Contributor Author

but better to do a new class, or add an option ?

@fepegar
Copy link
Owner

fepegar commented Mar 24, 2020

I feel like if an option is added to CenterCropOrPad, then is not necessarily "Center" anymore. That's why I think a generalised CropOrPad could be created that is a superclass of CenterCropOrPad. CenterCropOrPad can be modified to something like

class CenterCropOrPad(CropOrPad):
    def __init__(self, bla):
        super().__init__(bla, mode='center')

and be deprecated in favor of the new class.

This was referenced Apr 1, 2020
@fepegar
Copy link
Owner

fepegar commented Apr 18, 2020

Resolved in #110.

@fepegar fepegar closed this as completed Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants