quatrope / astroalign

A tool to align astronomical images based on asterism matching
MIT License
140 stars 44 forks source link

TypeError when using Pillow Image object #65

Closed DavidMonk00 closed 3 years ago

DavidMonk00 commented 3 years ago

I have just started using this library and was able to have success when registering two numpy arrays, however when I instead use the code in the README for Image objects, I get the following error:

TypeError: 'JpegImageFile' object is not subscriptable

Is this an error you can recreate? Perhaps a library incompatibility?

Versions: Python: 3.9.2 PIL: 8.1.2 astroalign: 2.3.1

Full error stack:

TypeError                                 Traceback (most recent call last)
~/.local/lib/python3.9/site-packages/astroalign.py in find_transform(source, target, max_control_points, detection_sigma, min_area)
    258     try:
--> 259         if len(_data(source)[0]) == 2:
    260             # Assume it's a list of (x, y) pairs

TypeError: 'JpegImageFile' object is not subscriptable

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-56-6234a8d4138f> in <module>
      3 source = Image.open("capture_200s_iso800_1.jpg")
      4 target = Image.open("capture_200s_iso800_2.jpg")
----> 5 registered, footprint = aa.register(source, target)
      6 # Convert back to pillow image if necessary:
      7 registered = Image.fromarray(registered.astype("unit8"))

~/.local/lib/python3.9/site-packages/astroalign.py in register(source, target, fill_value, propagate_mask, max_control_points, detection_sigma, min_area)
    461 
    462     """
--> 463     t, __ = find_transform(
    464         source=source,
    465         target=target,

~/.local/lib/python3.9/site-packages/astroalign.py in find_transform(source, target, max_control_points, detection_sigma, min_area)
    268             )[:max_control_points]
    269     except Exception:
--> 270         raise TypeError("Input type for source not supported.")
    271 
    272     try:

TypeError: Input type for source not supported.
martinberoiz commented 3 years ago

Hello David,

Thanks for the report! I indeed can reproduce the error. It's a bit embarrassing since I didn't test this case of opening from an image in my unit tests. I am working on a new minor release that will come very soon.

DavidMonk00 commented 3 years ago

I'm glad I can help, looking forward to using the new version when it's released!

martinberoiz commented 3 years ago

Hey David, I just released version 2.3.2 with the bug fix. Sorry for the inconvenience, let me know if this fixes it for you.

DavidMonk00 commented 3 years ago

Hi Martin, I can confirm that with the new version I am no longer seeing the error, thank you very much for your quick work in fixing it!

martinberoiz commented 3 years ago

Awesome, glad to hear that.