A police inspector who admitted making or distributing more than 300 indecent images of children, including a film of a six-year-old boy, has been granted bail by a Crown Court judge.

Lee Bartram was ordered to be freed from prison after a court was told prosecutors had wrongly claimed he had filmed a teenager sunbathing while on police bail earlier this week.

A judge sitting at Wolverhampton Crown Court also lifted a court order banning publication of the suspended West Midlands Police officer’s home address.

Bartram’s address was ordered to be withheld at Walsall Magistrates’ Court on Thursday over terrorism fears, after the 44-year-old pleaded guilty to five counts of making indecent images of a child and two counts of distributing similar images.

The charges, spanning a period between August 2013 and the same month of this year, relate to a total of 328 images, including some found on an iPad and an iPhone.

Judge James Burbidge QC was told that Bartram, of Bustleholme Lane, West Bromwich, filmed a teenage boy sunbathing last year, while recording a commentary expressing sexual desire.

A district judge had ordered that Bartram’s address should not be published as it could lead to the Birmingham-based officer or his family being “targeted by terrorists for the most serious acts of violence”.

But Judge Burbidge opted to lift the reporting restriction on Friday, rejecting a joint application by prosecution and defence counsel to keep Bartram’s address secret.

West Midlands Police Assistant Chief Constable Gareth Cann submitted a letter to the court asking the judge to take into consideration the current “severe” terror threat rating.

Mr Cann’s letter stated: “Should you feel able to direct that an address can be withheld, taking into account all the circumstances of the case before you, then you would be making a valuable contribution to mitigating the current threat we face.”

Lifting the order following an application by the Press Association, Judge Burbidge told the court: “I do not believe there is an objective and well founded, heightened risk to his life as a result of these proceedings and him being a police officer.

“There has to be a good reason to make an order prohibiting open reporting.”

After imposing conditional bail, which bans Bartram from using the internet, the judge added: “The fact that I grant him bail should not inform any subsequent judge as to what sentence should be passed.”

Bartram, who has not worked as a counter-terror officer, is due to be sentenced on September 13.