Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Add crop = cutout function #4

Closed

Description

@cdeil

One of the basic image processing functions is crop, a.k.a. cutout.

API proposal:

def crop(data, wcs, bounding_box):
    data_new = # a view, not a copy
    wcs_new = # copy and modify the input wcs
    return data_new, wcs_new

Existing implementations (please add links if there is other code that might be useful):

To be discussed:

  • How should the bounding_box be specified? (In Gammapy I've started to implement a class for this)

Activity

  1. astrofrog commented on Oct 2, 2014

    @astrofrog
    Member

    Well I can see different ways to specify the region to cutout. For starters, one might want to accept a SkyCoord and a radius. Or give a range of pixels in x and y. I guess there's not too many options. What API are you using in gammapy?

  2. cdeil commented on Oct 2, 2014

    @cdeil
    MemberAuthor

    My idea in Gammapy was to have the crop_image function only accept a BoundingBox object which simply represents a slice in pixel coordinates and then there could be various ways to create a BoundingBox.

    I think a BoundingBox class would be a useful addition to imageutils (and then also be used in photutils or gammapy), because it's needed as input or internally for many methods.
    But I'm not 100% sure it's a good idea ... @astrofrog what do you think?

  3. cdeil commented on Oct 2, 2014

    @cdeil
    MemberAuthor

    PS: the Gammapy imageutils functions and classes are mostly crap and unfinished / untested, so don't look at them too closely ... the idea is to find a good API and then implement it well here in astropy.image and remove the versions from Gammapy.

  4. crawfordsm commented on Oct 3, 2014

    @crawfordsm
    Member

    As another example, there's also the trim_image function in ccdproc: https://github.com/astropy/ccdproc/blob/master/ccdproc/core.py#L230

    This doesn't have the WCS slicing and worries about FITS header format, which I am not sure if it is needed here, but it depends on how general the task should be.

  5. added a commit that references this issue on Nov 12, 2014
  6. cdeil commented on Dec 2, 2014

    @cdeil
    MemberAuthor

    @larrybradley @astrofrog What do you think about introducing a ImageBoundingBox or ImageSlice or ImageCutout class in astropy.image and then using it in photutils, gammapy, ccdproc, ...

    At the moment slices are mostly used internally and not part of the API and something definitely needs to be done about #40 ... we can't leave these slice helper functions as is.

  7. larrybradley commented on Dec 17, 2014

    @larrybradley
    Member

    @cdeil This could be useful if we can find a good API. Perhaps a simple ImageCutout class that takes data and x0, x1, y0, y1 as input and have a slice tuple, bounding box, and center pixel, etc. as object properties?

  8. cdeil commented on Dec 17, 2014

    @cdeil
    MemberAuthor

    @larrybradley – As I said ... I don't know what a good solution is here even after discussing this for an hour with @adonath ... I'd have to write down simple examples with the various use cases first to see what works best.

    The smallest useful thing would be to have an NDSlice class that has a Python list of slice objects as a data member and provides convenience functions (e.g. create it from a center position) and attributes.

    For other use cases it would be better if the class has a reference to the image and sometimes also a reference to a kernel ... probably these could be optional and one could have a single class that is useful to implement a lot of image processing stuff e.g. in modeling and photutils and gammapy where one operates on image cutouts for speed.

    So +10 if you can make a concrete proposal ... I'm very interested and will try it out for my use cases.

  9. keflavich commented on Jun 30, 2015

    @keflavich

    Over the past few days, I've had a need for this functionality on 3 separate occasions. So, big 👍.

  10. cdeil commented on Jun 30, 2015

    @cdeil
    MemberAuthor

    @larrybradley has implemented this in astropy/astropy#3823 .
    Closing this issue so that discussion can continue there ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions