[Tex/LaTex] Solve overfull \hbox in equation’s case

equations

I have just started LaTeX so this may be a silly question, but I am getting a warning "Overfull \hbox(—pt too wide) detected" and the compiled pdf shows this text "if the sum of edge densities in the patch (x', y') is greater than threshold" (line 3 in the code) in a single line and this line is going out of bounds. Ideally that line should've been printed in two lines. I have tried linebreak but that doesn't work here. How to correct this?

\begin{equation}
I^p(x',y') = \left\{\begin{array}{rl}
    1 & \text{if the sum of edge densities in the patch (x', y') is greater than threshold}\\
    0 & \text{otherwise}\\
    \end{array}\right.
\end{equation}

Best Answer

You can't break lines in \text, but you can use a \parbox; adjust the width to suit.

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum}% for mock text

\begin{document}

\lipsum*[3]
\begin{equation}
I^p(x',y') =
\begin{cases}
  1 & \parbox[t]{.5\textwidth}{\raggedright
        if the sum of edge densities in the patch
        $(x', y')$ is greater than threshold
      }\\[4ex]
  0 & \text{otherwise}
\end{cases}
\end{equation}
\lipsum[4]

\end{document}

enter image description here