BOULDER, Colo. — Recreational marijuana is both illegal and controversial in most of the country, and its relationship to food does not rise much above a joke about brownies or a stoner chef’s late-night pork belly poutine.

But cooking with cannabis is emerging as a legitimate and very lucrative culinary pursuit.

In Colorado, which has issued more than 160 edible marijuana licenses, skilled line cooks are leaving respected restaurants to take more lucrative jobs infusing cannabis into food and drinks. In Washington, one of four states that allow recreational marijuana sales, a large cannabis bakery dedicated to affluent customers with good palates will soon open in Seattle.

Major New York publishing houses and noted cookbook authors are pondering marijuana projects, and chefs on both coasts and in food-forward countries like Denmark have been staging underground meals with modern twists like compressed watermelon, smoked cheese and marijuana-oil vinaigrette.

“It really won’t be long until it becomes part of haute cuisine and part of respectable culinary culture, instead of just an illegal doobie in the backyard,” said Ken Albala, director of the food studies program at the University of the Pacific in San Francisco.