Python Forum
AttributeError: 'numpy.ndarray' object has no attribute 'load'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'numpy.ndarray' object has no attribute 'load'
#1
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???
Reply
#2
Why are you calling my_image.load()? What is that supposed to do?
hobbyist likes this post
Reply
#3
How else can I read pixel of the image?
Reply
#4
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?
hobbyist likes this post
Reply
#5
This is an essay full of useful information. No doubt I love these and fnf mods
Reply
#6
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...
Reply
#7
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.
hobbyist likes this post
Reply
#8
(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...
Reply
#9
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-a...cca7a74510
hobbyist likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 765 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,672 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,470 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 744 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,867 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 730 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,332 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,592 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  WebDriver' object has no attribute 'find_element_by_css_selector rickadams 3 5,900 Sep-19-2022, 06:11 PM
Last Post: Larz60+
  'dict_items' object has no attribute 'sort' Calli 6 4,475 Jul-29-2022, 09:19 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020