Since I spent multiple days trying to address this issue in my project and cannot find any documented information on why this could be occurring on either StackExchange or the Pillow Issues board, I'm posting it here for some help.
What did you do?
Attempted to import a .tif image using Image.open() and then convert the Image to an array.

What did you expect to happen?
Successful conversion of the pillow image to a numpy ndarray.
As documented per #3301
What actually happened?
Both numpy.array() and numpy.asarray() returned an instance of Pil.TiffImagePlugin.TiffImageFile instead of a numpy ndarray when called once. Calling numpy.asarray() or numpy.array() more than once on the instance of Pil.TiffImagePlugin.TiffImageFile causes the numpy.asarray() or numpy.array() to return a numpy ndarray even if no assignment of the returned value from the first call occurs. it's as if the call to numpy.array() or numpy.asarray() is mutating the Pil.TiffImagePlugin.TiffImageFile instance.
I ran the following tests to show the oddity of the behavior, each time I got the console print message "tempfile.tif: Cannot read TIFF header." This error message was not part of my code base and was not raise with an exception. The image I'm using is a scanned .tiff image in grayscale sent through Microsoft outlook.
Case 1:
Code:

Result:

Case 2:
Code:

Result:

Case 3 :
Code:

Result:

Case 4:
Code:

Result:

Case 5:
Code:

Result:

Unfortunately, I'm unable to post the image I'm analyzing as it contains confidential information from my employer. However, since the behavior of the library itself is the really strange thing I'm hoping that should be enough to start looking into why this strange behavior is occurring.
However, here is some file information for the file that I can provide:

What versions of Pillow and Python are you using?



Since I spent multiple days trying to address this issue in my project and cannot find any documented information on why this could be occurring on either StackExchange or the Pillow Issues board, I'm posting it here for some help.
What did you do?
Attempted to import a .tif image using Image.open() and then convert the Image to an array.

What did you expect to happen?
Successful conversion of the pillow image to a numpy ndarray.
As documented per #3301
What actually happened?
Both numpy.array() and numpy.asarray() returned an instance of Pil.TiffImagePlugin.TiffImageFile instead of a numpy ndarray when called once. Calling numpy.asarray() or numpy.array() more than once on the instance of Pil.TiffImagePlugin.TiffImageFile causes the numpy.asarray() or numpy.array() to return a numpy ndarray even if no assignment of the returned value from the first call occurs. it's as if the call to numpy.array() or numpy.asarray() is mutating the Pil.TiffImagePlugin.TiffImageFile instance.
I ran the following tests to show the oddity of the behavior, each time I got the console print message "tempfile.tif: Cannot read TIFF header." This error message was not part of my code base and was not raise with an exception. The image I'm using is a scanned .tiff image in grayscale sent through Microsoft outlook.
Case 1:
Code:


Result:
Case 2:
Code:

Result:

Case 3 :
Code:

Result:

Case 4:
Code:

Result:

Case 5:
Code:

Result:

Unfortunately, I'm unable to post the image I'm analyzing as it contains confidential information from my employer. However, since the behavior of the library itself is the really strange thing I'm hoping that should be enough to start looking into why this strange behavior is occurring.
However, here is some file information for the file that I can provide:

What versions of Pillow and Python are you using?


