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

Make ImagePlus subscriptable #194

Open
ctrueden opened this issue Apr 28, 2022 · 4 comments
Open

Make ImagePlus subscriptable #194

ctrueden opened this issue Apr 28, 2022 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@ctrueden
Copy link
Member

ctrueden commented Apr 28, 2022

PyImageJ lets you subscript RandomAccessibleInterval objects, but not ImagePlus objects.

For single-element access:

  • GRAY8 (ByteProcessor) is the equivalent of numpy.uint8.
  • GRAY16 (ShortProcessor) is the equivalent of numpy.uint16.
  • GRAY32 (FloatProcessor) is the equivalent of numpy.float32.
  • COLOR_RGB (IntProcessor) has no numpy dtype equivalent to my knowledge.
  • COLOR_256 is apparently also done in numpy with numpy.uint8...
  • Does ImageJ support for uint32 now? I vaguely remember reading on a thread during 2021-2022 about it, but I can't find it now.

Note also that to be consistent with numpy and ImgLib2's behavior, the dtype function should also be implemented, and it should return a class object corresponding to the returned type of single elements.

For slicing: maybe we can use the Duplicator's crop and/or run to limit dimensional min/maxes. But step values other than 1 require more effort. Better to wrap the ImagePlus into some kind of Python-side view object?

@ctrueden ctrueden added this to the unscheduled milestone Apr 28, 2022
@ctrueden
Copy link
Member Author

See also this Gitter chatlog.

@ctrueden
Copy link
Member Author

ctrueden commented Apr 28, 2022

I think our four choices are:

  1. Invent some ImageJ-specific dtypes; or
  2. Reuse the numpy dtypes; or
  3. Use plain Python types but that is ambiguous (GRAY8 vs GRAY16); or
  4. Break the convention of dtypes returning the class of elements you get from single-element slicing.

The advantage of (2) is that those types are already in place. But the disadvantage is that it's inconsistent with how PyImageJ handles RandomAccessibleInterval—why not report the numpy-equivalent dtypes for RAIs too then?

So I think (1) is probably the cleanest solution.

ctrueden added a commit that referenced this issue Apr 28, 2022
This partially reverts commit 62178c1.

As per this discussion:
  https://gitter.im/imagej/pyimagej?at=6269dc98949ae940067e9830

@gselzer pointed out that slicing an ImagePlus down to a single element
should -- in the same way that numpy and ImgLib2 images behave -- return
the element as an instance of the same class that dtype reports. For
ImageJ, this is not so easy, though, because ImageJ does not have
sample value container types like ImgLib2 does. So we would need to:

A) Invent some ImageJ-specific ones; or
B) Reuse the numpy ones; or
C) Use plain Python types but that is ambiguous (GRAY8 vs GRAY16); or
D) Break the convention.

See also #194.
@gselzer
Copy link
Contributor

gselzer commented Apr 28, 2022

I think our four choices are:

1. Invent some ImageJ-specific dtypes; or

2. Reuse the numpy dtypes; or

3. Use plain Python types but that is ambiguous (GRAY8 vs GRAY16); or

4. Break the convention of `dtypes` returning the class of elements you get from single-element slicing.

The advantage of (2) is that those types are already in place. But the disadvantage is that it's inconsistent with how PyImageJ handles RandomAccessibleInterval—why not report the numpy-equivalent dtypes for RAIs too then?

So I think (1) is probably the cleanest solution.

I'd propose not actually making a decision on this. I'd rather focus on making pixel access (i.e. slicing) work the way we want it. Then I think this question of the dtype will follow naturally from the return.

@ctrueden ctrueden added the enhancement New feature or request label Jun 23, 2023
@ctrueden
Copy link
Member Author

My current thinking is: let's not ever implement this. What we could do instead is, if someone tries to slice or subscript an ImagePlus, raise an exception explaining that the original ImageJ data structures do not support this, and to recommend using ImgLib2 structures instead. 👍 No need to make it any easier than we already have for people to keep using ImagePlus forever.

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