def ToLinearIndex(ij, NiNj):
    """ Returns the linear index of a flattened 2D image that has dimensions 
        [Ni,Nj] before flattening.

        INPUT:
            - ij, a list of length 2 containing the i and j coordinate 
              as [i,j]
            - NiNj, a list of length 2 containing the dimensions of the 2D 
              domain as [Ni,Nj]

        OUTPUT:
            - ijFlat = ij[0] * NiNj[0] + ij[1]
    """

    return ij[0] * NiNj[0] + ij[1]