Why converting my data to ndarray gives me "python" terminated with a SIGBUS signal (Misaligned address error)?

img

is a PIL image. Below is the terminal output when I try to import data into ndarray. Do you think the error is what I did or something with numpy?

>>> img
<PIL.TiffImagePlugin.TiffImageFile image mode=I;16 size=1280x1080 at 0x110CB1560>
>>> img.getdata()
<ImagingCore object at 0x1105df7b0>
>>> np.array(img.getdata(), np.uint16)
fish: Job 1, 'python' terminated by signal SIGBUS (Misaligned address error)

      

+3


source to share


1 answer


This code works for me, in Python 3.4, Numpy 1.9:

import os
from PIL import Image
import numpy as np

def img_data_in_nd_array():
    img_dir = 'img'
    file_name = 'avatar_physical_attraction.jpg'
    img = Image.open(os.path.join(img_dir, file_name))

    print (img.getdata())
    print (np.array(img.getdata(), np.uint16))

if __name__ == '__main__':
    img_data_in_nd_array()

      

Result:



<ImagingCore object at 0x105b958f0>
[[ 53 152 254]
 [ 53 152 254]
 [ 53 152 254]
 ..., 
 [ 52 151 253]
 [ 52 151 253]
 [ 52 151 253]]

      

Perhaps you can provide an image that goes wrong, so we can check if there is something wrong with that. Have you tried another image yet?

0


source







All Articles