Here are some examples:
* Correct: The imam led the prayers.
* Correct: I met with Imam Ali.
* Correct: The imams of the mosque are respected leaders.
However, when "imam" is part of a specific title or name, it should be capitalized:
* Correct: Imam Ali (a specific person's name)
* Correct: The Grand Imam of Al-Azhar (a specific title)
In general, the rule of thumb is to capitalize titles and names, but not common nouns.