0
votes

The original image in LEVIR-CD has a size of 1024 * 1024, which will consume too much memory when training. Therefore, needed to cut the origin images into smaller patches.

When image dataset contains images in png format with size 1024x1024 code below doesn't return an error, if I cropped image into 16 parts (256x256px) this code return an error

tmp = np.array(Image.open(L_path), dtype=np.uint32)/255
L_img = Image.fromarray(tmp)

Error

L_img = Image.fromarray(tmp) File "/usr/lib64/python3.6/dist-packages/PIL/Image.py", line 2766, in fromarray raise TypeError("Cannot handle this data type: %s, %s" % typekey) from e TypeError: Cannot handle this data type: (1, 1, 3), <f8

Image sample - (left bottom corner from original image)

Images contains Labels for comparison Dataset

Original image sample

enter image description here

To fix this issue as described in this answer PIL TypeError: Cannot handle this data type question answer

I fix error:

L_img = Image.fromarray(tmp.astype(np.uint8))

Full code described here at STANet project Github page

pip3 imported libs versions:

Pillow 8.1.0

numpy 1.19.5

I misunderstood how can image size can change function behavior. I would be very grateful if someone could explain.

UPDATE: as I understand, it depend on bit depth of an image. Original image 8 bit, but cropped image is 24 bit png. I did not pay attention to this point, but the question has already been resolved.

1
It's not very clear to me what you are doing. Could you put back the import statements and code to chop the image which you have removed please? And also provide the original image rather than the chopped one. I'm guessing you have a problem with data types and ranges. Thank you. - Mark Setchell
@MarkSetchell as I understand, it depend on bit depth of an image. Original image 8 bit, but cropped image is 24 bit png. I did not pay attention to this point, but the question has already been resolved. Thank you for your advice and attention - loviji
Please add a self answer and accept it, if you solved the problem on your own. Or, mark your question as duplicate, if you found the solution in some other question. So, people already know from the overview, that you don't need any further help (question marked accordingly). - HansHirse

1 Answers

0
votes

As I understand, it depend on bit depth of an image. Original image 8 bit, but cropped image is 24 bit png