Python Forum
AttributeError: 'numpy.ndarray' object has no attribute 'load' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: AttributeError: 'numpy.ndarray' object has no attribute 'load' (/thread-37639.html)



AttributeError: 'numpy.ndarray' object has no attribute 'load' - hobbyist - Jul-04-2022

I have the following error:

Error:
currrent_pixel = my_image.load() AttributeError: 'numpy.ndarray' object has no attribute 'load'
in the following code:

        
        import cv2
        import numpy as np
        my_image = cv2.imread(path_of_my_image, cv2.IMREAD_UNCHANGED) 
        currrent_pixel = my_image.load()
What is wrong???


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - deanhystad - Jul-04-2022

Why are you calling my_image.load()? What is that supposed to do?


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - hobbyist - Jul-04-2022

How else can I read pixel of the image?


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - deanhystad - Jul-04-2022

my_image is a 2D numpy array. How to you get values from a 2D numpy array?

https://numpy.org/devdocs/user/basics.indexing.html

But I am still curious about load(). What made you think that is how you get pixels?


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - JayRichard - Jul-05-2022

This is an essay full of useful information. No doubt I love these and fnf mods


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - hobbyist - Jul-05-2022

I tried this:

Error:
from PIL import Image my_image= Image.open(path_of_my_image)
and I get this error:

  File "/home/someone/.local/lib/python3.8/site-packages/PIL/Image.py", line 3008, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file 'test_images/test_UAV.tif')
What is wrong??

@deanhystad: Do you suggest to transform the image to numpy? I can't even load it now...


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - deanhystad - Jul-05-2022

Verify that PIL supports tiff files.
Output:
>>>Python -m PIL -------------------------------------------------------------------- Pillow 9.0.1 Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] -------------------------------------------------------------------- ... -------------------------------------------------------------------- TIFF image/tiff Extensions: .tif, .tiff Features: open, save, save_all -------------------------------------------------------------------- ...
If you don't see TIFF, you do not have a codex for working with TIFF files.

If you see TIFF in the list of supported file types, try opening your file with something that should be able to open TIFF files. What OS are you using?

If you were able to read the file using cv2 and that no longer works, it sounds like you corrupted the file.


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - hobbyist - Jul-06-2022

(Jul-04-2022, 05:04 PM)deanhystad Wrote: Why are you calling my_image.load()? What is that supposed to do?

(Jul-05-2022, 10:15 PM)deanhystad Wrote: Verify that PIL supports tiff files.
Output:
>>>Python -m PIL -------------------------------------------------------------------- Pillow 9.0.1 Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] -------------------------------------------------------------------- ... -------------------------------------------------------------------- TIFF image/tiff Extensions: .tif, .tiff Features: open, save, save_all -------------------------------------------------------------------- ...
If you don't see TIFF, you do not have a codex for working with TIFF files.

If you see TIFF in the list of supported file types, try opening your file with something that should be able to open TIFF files. What OS are you using?

If you were able to read the file using cv2 and that no longer works, it sounds like you corrupted the file.

I ran the command you mentioned. I get this:

--------------------------------------------------------------------
Pillow 9.0.1
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
       [GCC 9.4.0]
--------------------------------------------------------------------

--------------------------------------------------------------------
TIFF image/tiff
Extensions: .tif, .tiff
Features: open, save, save_all
--------------------------------------------------------------------
I am using Kubuntu OS. The strange thing is that I can open that specific .tif image with QGIS but not via python code...


RE: AttributeError: 'numpy.ndarray' object has no attribute 'load' - deanhystad - Jul-06-2022

Oh, it is a geotiff file.

A geotiff file is a tiff file with additional georeferencing information tags. I found an article about it here:

https://towardsdatascience.com/reading-and-visualizing-geotiff-images-with-python-8dcca7a74510