– When officials in an eastern Chinese city were told to root out "uncivilized behavior," they were given a powerful tool to carry out their mission: facial-recognition software.

Their target? People wearing pajamas in public.

On Monday, the urban management department of Suzhou, a city of 6 million people, sparked outrage when it published surveillance photos taken by street cameras of seven local residents wearing pajamas in public along with parts of their names and the locations where their "uncivilized behavior" had taken place.

City officials quickly apologized, but not before stirring nationwide ire over the use of a state-of-the-art digital tool to stamp out a relatively commonplace practice.

On social media, the Suzhou department publicly called out, among others, a Ms. Dong, a young woman in a plush pink robe, matching pants and orange pointy flats, walking on a street, and a Mr. Niu, who was singled out for donning a black and white checkered full pajama suit in a mall.

"Uncivilized behavior refers to when people behave and act in ways that violate public order because they lack public morals," read a post on WeChat, a common social messaging app, which has since been deleted.

The wearing of pajamas in public "has brought about a kind of complacent, undisciplined mind set," it concluded.

The use of facial-recognition software by law enforcement authorities remains a hotly debated topic worldwide and has even been banned in some major American cities.

Not so in China. In just a few years, use of the software has become widespread. Police have used it to create a powerful surveillance dragnet. The technology also is used to solve more mundane problems, including catching tissue bandits at public toilets.

But shaming pajama-wearers might have gone a step too far.

"Facial-recognition technology should be used with caution," wrote a user named Xiu Li De Xiao Wo on Sina Weibo, a popular microblogging platform. "They should really be restricting access."

Some users on the platform said they disagreed with the government's decision to release private information online. Others simply wanted to know what was so wrong with wearing pajamas in public.

Public pajama wearing is common in China, particularly among older women who tend toward bold colors and floral or cartoon patterns. The origin of the practice is widely debated, though virtually everybody agrees on one point: Pajamas are extremely comfortable.

Hung Huang, a Beijing-based writer and proud pajama-wearing fashion blogger, said the government had no business interfering in the fashion choices of the Chinese public.

"The decision [to shame PJ wearers] was probably made by somebody who has no understanding of international fashion and of how to use technology to benefit the people rather than to just control them," she said.

Following the online uproar, officials in Suzhou quickly took down the original post.

"We sincerely apologize," said a statement posted on the city's WeChat account. "The way we released the information and the content of the article were not handled properly."