Skip to content

Instantly share code, notes, and snippets.

@htp2
Created January 19, 2023 18:35
Show Gist options
  • Save htp2/76df15104f3e063edf53f644ea2bb69a to your computer and use it in GitHub Desktop.
Save htp2/76df15104f3e063edf53f644ea2bb69a to your computer and use it in GitHub Desktop.
Convert CIOS DICOM to Video
#!/bin/bash
xray_dir=$1
output_dir=$2
cwd=$(pwd)
convert_fluoro_file_to_video () {
filename=$(echo $1 | sed 's/[.].*$//') # strip anything after period (e.g. file extension)
frame_rate=$(medcon -f $1 | grep CineRate | sed -n 's/.*\[\([^]]*\)\].*/\1/p') # check to see if this is a set of fluoro images (from the dicom header)
if [ -z ${frame_rate} ]
then
echo $filename "does not appear to be a series of fluoro images"
else
echo "Processing: " $filename "with framerate: " $frame_rate
mkdir -p $2/$filename/
medcon -f $1 -c png -o $2/$filename/slice.png # make a dir of pngs
ffmpeg -r $frame_rate -pattern_type glob -i $2/$filename/"*.png" -c:v libx264 -crf 0 $2/$filename.avi # make pngs into mp4 at specified framerate
fi
}
cd $xray_dir
for FILE in *
do
convert_fluoro_file_to_video $FILE $output_dir & # run all in parallel
done
wait
cd $cwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment