Skip to content

Failed

OmeroPy.test.integration.scriptstest.test_script_utils.TestScriptUtils.test_numpy_to_image (from pytest)

Failing for the past 3 builds (Since #412 )
Took 2.2 sec.

Error Message

AttributeError: module 'PIL.Image' has no attribute 'fromstring'

Stacktrace

self = <test.integration.scriptstest.test_script_utils.TestScriptUtils object at 0x7f203a40d890>

    def test_numpy_to_image(self):
        client = self.new_client()
        image = self.create_test_image(100, 100, 2, 3, 4, client.getSession())
        conn = BlitzGateway(client_obj=client)
        image = conn.getObject("Image", image.id.val)
        pixels = image.getPrimaryPixels()
        channel_min_max = []
        for c in image.getChannels():
            min_c = c.getWindowMin()
            max_c = c.getWindowMax()
            channel_min_max.append((min_c, max_c))
        z = image.getSizeZ() // 2
        t = 0
        c = 0
        try:
            for min_max in channel_min_max:
                plane = pixels.getPlane(z, c, t)
>               i = scriptUtil.numpy_to_image(plane, min_max, int32)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

test/integration/scriptstest/test_script_utils.py:79: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

plane = array([[ 0,  1,  2, ..., 97, 98, 99],
       [ 0,  1,  2, ..., 97, 98, 99],
       [ 0,  1,  2, ..., 97, 98, 99],
    ...7, 98, 99],
       [ 0,  1,  2, ..., 97, 98, 99],
       [ 0,  1,  2, ..., 97, 98, 99]], shape=(100, 100), dtype=int16)
min_max = (0.0, 99.0), dtype = <class 'numpy.int32'>

    def numpy_to_image(plane, min_max, dtype):
        """
        Converts the numpy plane to a PIL Image, converting data type if necessary.
    
        :param plane The plane to handle
        :param min_max the min and the max values for the plane
        :param dtype the data type to use for scaling
        """
    
        conv_array = convert_numpy_array(plane, min_max, dtype)
        if plane.dtype.name not in (PixelsTypeint8, PixelsTypeuint8):
>           return Image.fromstring('I', plane.shape, conv_array)
                   ^^^^^^^^^^^^^^^^
E           AttributeError: module 'PIL.Image' has no attribute 'fromstring'

../../../../.venv3/lib64/python3.11/site-packages/omero/util/script_utils.py:1506: AttributeError