NEW YORK — Subjecting a sex offender who is no longer incarcerated to “extraordinarily invasive” sexual-stimulation testing risks violating the premise that even convicts retain their humanity, a federal appeals court said Thursday in refuting a Vermont order.

The ruling by the 2nd U.S. Circuit Court of Appeals in Manhattan frees former police officer David McLaurin of a requirement that he submit to a test measuring his response to sexually stimulating images.

An all-male, three-judge appeals panel said it saw a “clear distinction” between such testing and other conditions of supervised release, including restrictions on where sex offenders may live, their interactions with children and their access to pornographic material.

McLaurin, 48, challenged the requirement after a Vermont judge sentenced him to 15 months in prison, to be followed by a treatment program that could include the testing, because McLaurin failed to fill out paperwork required by sex offenders.

McLaurin had notified authorities that he would be working as a chef at a Putney, Vt., inn in 2011, but he later lost the job and went to Alabama, where he was arrested. He was returned to Vermont to face charges and was released from prison last November.

He was required to register as a sex offender because he was convicted more than a decade ago of producing child pornography by photographing a topless 13-year-old girl, who told authorities she had requested a photo shoot to help her modeling career, the court said.

A Vermont federal judge who concluded McLaurin was “unlikely to re-offend again” had said it was “standard” to include a test in which sexual stimulation is measured.

The appeals panel said the government had cited instances when Vermont judges had ordered the procedure, but the court added that judges in New York and Connecticut within the 2nd Circuit had not recently imposed such conditions and that probation officers in Vermont has ceased recommending it.

The appeals court said it seemed “odd” to try to deter someone from committing sex crimes by showing him depictions of sex.

“We hold that this extraordinarily invasive condition is unjustified, is not reasonably related to the statutory goals of sentencing, and violates McLaurin’s right to substantive due process,” it said.

The court found the testing “is unduly intrusive and bears insufficient relation to correctional or medical treatment, the protection of the public or deterrence of a crime.”

McLaurin’s public defender, Steven L. Barth, said he was pleased with the ruling.

“Mr. McLaurin and the Federal Defender Office felt strongly that the invasive plethysmograph testing condition was unwarranted and unconstitutional,” he said.

Prosecutors did not immediately respond to a request for comment.

The judges flatly rejected government arguments that the plethysmograph procedure amounted to “treatment” for sex offenders, saying prosecutors offered no evidence “that this exceedingly intrusive procedure has any therapeutic benefit, and none is apparent to us.”

It cited a similar ruling by the 9th U.S. Circuit Court of Appeals in San Francisco that found the test’s accuracy and reliability “have been severely questioned.”

The 2nd Circuit said even if the test were accurate, “the goal of correctional treatment during supervised release is properly directed at conduct, not at daydreaming.”