The method includes providing n prediction modes, where n is a positive integer, selecting first prediction modes among the n prediction modes using a first cost function, and selecting a final prediction mode among the first prediction modes using a second cost function different from the first cost function.