コード例 #1
0
def list_of_frames(img_name):
    """Return the list of frames for an image file.

    Details are as described in the imgimport_intelligent docstring.

    """

    img = Image.open(img_name)
    imglist = []

    try:
        for i in xrange(8):
            if img.mode == 'I':
                imdata = np.asarray(img, dtype=np.int16)
            else:
                imdata = np.asarray(img, dtype=np.float32)
            # fix 3-channel TIFF images
            if np.rank(imdata) == 3:
                imdata = imdata[:, :,
                                0] + 256 * imdata[:, :,
                                                  1] + 65536 * imdata[:, :, 2]
            imglist.append(imdata)
            img.seek(i + 1)  # next frame
    except EOFError:
        pass

    if not imglist:
        raise ImportError, 'No frames detected in file %s' % img_name
    else:
        return imglist
コード例 #2
0
def import_rawframes(img_name):
    """Opens an image file containing three frames

    The datatype has to be set to float in Winview, otherwise there is a
    strange problem reading the frames; support for 16-bit tif files is
    lacking a bit in PIL.

    **Inputs**

      * img_name: string containing the full path to an image

    **Outputs**

      * img_array: 3D array, containing the three frames of the image

    """

    img = Image.open(img_name)
    # note the reversed order because Image and asarray have reversed order
    img_array = np.zeros((img.size[1], img.size[0], 3), dtype=np.float32)

    img_array[:, :, 0] = np.asarray(img, dtype=np.float32)
    try:
        img.seek(1)  # next frame
        img_array[:, :, 1] = np.asarray(img, dtype=np.float32)
        img.seek(2)  # next frame
        img_array[:, :, 2] = np.asarray(img, dtype=np.float32)
    except EOFError:
        print 'This image contains less than 3 frames'
        return None

    return img_array
コード例 #3
0
ファイル: imageio.py プロジェクト: edjoesu/odysseus
def import_rawframes(img_name):
    """Opens an image file containing three frames

    The datatype has to be set to float in Winview, otherwise there is a
    strange problem reading the frames; support for 16-bit tif files is
    lacking a bit in PIL.

    **Inputs**

      * img_name: string containing the full path to an image

    **Outputs**

      * img_array: 3D array, containing the three frames of the image

    """

    img = Image.open(img_name)
    # note the reversed order because Image and asarray have reversed order
    img_array = np.zeros((img.size[1], img.size[0], 3), dtype=np.float32)

    img_array[:, :, 0] = np.asarray(img, dtype=np.float32)
    try:
        img.seek(1) # next frame
        img_array[:, :, 1] = np.asarray(img, dtype=np.float32)
        img.seek(2) # next frame
        img_array[:, :, 2] = np.asarray(img, dtype=np.float32)
    except EOFError:
        print 'This image contains less than 3 frames'
        return None

    return img_array
コード例 #4
0
ファイル: imageio.py プロジェクト: MaxParsons/Odysseus
def list_of_frames(img_name):
    """Return the list of frames for an image file.

    Details are as described in the imgimport_intelligent docstring.

    """

    img = Image.open(img_name)
    imglist = []

    try:
        for i in xrange(8):
            if img.mode == 'I':
                imdata = np.asarray(img, dtype=np.int16)
            else:
                imdata = np.asarray(img, dtype=np.float32)
            # fix 3-channel TIFF images
            if np.rank(imdata)==3:
                imdata = imdata[:,:,0] + 256*imdata[:,:,1] + 65536*imdata[:,:,2]
            imglist.append(imdata)
            img.seek(i+1) # next frame
    except EOFError:
        pass

    if not imglist:
        raise ImportError, 'No frames detected in file %s' %img_name
    else:
        return imglist
コード例 #5
0
def import_rawimage(img_name):
    """Opens an image file and returns it as an array."""

    im = Image.open(img_name)

    return np.asarray(im)
コード例 #6
0
ファイル: imageio.py プロジェクト: edjoesu/odysseus
def import_rawimage(img_name):
    """Opens an image file and returns it as an array."""

    im = Image.open(img_name)

    return np.asarray(im)