def reshape_data(out, h, index, count, force_volume=False):
    """Reshape the data to the proper dimensions.

    :Parameters:

    out : array
          Array with image information from the file
    h : array
        Header information
    index : int
            Index of image
    count : int
            Number of images in file

    :Returns:

    out : array
          Array with image information from the file
    """
    if index is None and int(h['nz'][0]) > 1 and (count == h['nx'][0] or
        force_volume):
        if h['mapc'][0] == 2 and h['mapr'][0] == 1:
            out = out.reshape((int(h['nx'][0]), int(h['ny'][0]), int(h['nz'
                ][0])))
            for i in range(out.shape[2]):
                out[:, :, (i)] = out[:, :, (i)].squeeze().T
        else:
            out = out.reshape((int(h['nx'][0]), int(h['ny'][0]), int(h['nz'
                ][0])))
    elif int(h['ny']) > 1:
        if h['mapc'][0] == 2 and h['mapr'][0] == 1:
            out = out.reshape((int(h['ny'][0]), int(h['nx'][0])))
        else:
            out = out.reshape((int(h['ny'][0]), int(h['nx'][0])))
    return out
