DICOM2VIDEO
Source CodeMain file:
import numpy as np
from cv2 import VideoWriter, VideoWriter_fourcc
import os
import glob
import cv2
from pprint import pprint
import sys,os
from datetime import datetime
import dcminout_root
import datetime
strt_time = datetime.datetime.now()
print(strt_time)
# width = 300
# height = 300
#FPS = 24
#seconds = 10
FPS =10
seconds =10
# var='nb'
var = sys.argv[1]
re=dcminout_root.inout_root(var)
files=re[4]
file_count = files
# tot=file_count-1
# start_n=tot/2
# if type(start_n)==float:
# startn=np.ceil(start_n)
# var_mul_str=startn*0.6
# var_mul_str=np.ceil(var_mul_str)
# endn=np.floor(start_n)
# var_mul_end=endn*0.6
# var_mul_end=np.ceil(var_mul_end)
# else:
# startn=np.ceil(start_n)
# endn=np.ceil(start_n)
# var_mul_str=startn*0.6
# var_mul_end=endn*0.6
# print(start_n,endn)
def color_gray(var):
rt=var
# rt='var'
dcm=dcminout_root.inout_root(rt)
# indir=data[0]
# input_dir=indir["dicom_dir"]
input_dir=dcm[0]
# oudir=data[1]
# output_dir=oudir["out_dir"]
output_dir=dcm[1]
videoheight=dcm[2]
videoheight=int(videoheight)
videowidth=dcm[3]
videowidth=int(videowidth)
# dcm_len=dcm[4]
# video_direction=dcm[4]
# dcmaxis_dir=dcm[5]
# dcmdecimal_val=dcm[6]
# actl_center=dcm[7]
# actl_center=int(actl_center)
# end_val=dcm[8]
# end_val=int(end_val)
# print(dcmaxis_dir,dcmdecimal_val)
# video_direction=str(video_direction)
# slids_incval=dcm[5]
# # videowidth=videowidth["Video_widh"]
# fourcc = VideoWriter_fourcc(*'MP4v')
out_videoname=dcm[9]
video_outputname=output_dir+"/"+out_videoname+'.mp4'
video_out = os.path.join(output_dir, video_outputname)
################################################################################################
data_path = os.path.join(input_dir, '*jpg')
files = glob.glob(data_path)
RGB=[]
# dr=dcmaxis_dir
# if dr=='x':
# # print('x')
# framx='x-axis='
# framy='y-axis=NA'
# framz='z-axis=NA'
# cv2.putText(RGB, framx+str(xr), (width-650, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255),3)
# cv2.putText(RGB, framy, (width-650, 103), cv2.FONT_HERSHEY_SIMPLEX,2, (0, 0, 255),3)
# cv2.putText(RGB, framz, (width-650, 158), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255),3)
# elif dr=='y':
# # print('y')
# framx='x-axis=NA'
# framy='y-axis='
# framz='z-axis=NA'
# cv2.putText(RGB, framx, (width-650, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255),3)
# cv2.putText(RGB, framy+str(xr), (width-650, 103), cv2.FONT_HERSHEY_SIMPLEX,2, (0, 0, 255),3)
# cv2.putText(RGB, framz, (width-650, 158), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255),3)
# else:
# # print('z')
# framx='x-axis=NA'
# framy='y-axis=NA'
# framz='z-axis='
# cv2.putText(RGB, framx, (width-650, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255),3)
# cv2.putText(RGB, framy, (width-650, 103), cv2.FONT_HERSHEY_SIMPLEX,2, (0, 0, 255),3)
# cv2.putText(RGB, framz+str(xr), (width-650, 158), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255),3)
files = glob.glob(data_path)
file_count = len(files)
# framx='x-axis='
# framy='y-axis=NA'
# framz='z-axis=NA'
# Unit=' unit=mm'
# img_array = []
out = cv2.VideoWriter(video_out,cv2.VideoWriter_fourcc(*'DIVX'), float(FPS), (videowidth,videoheight))
# out = cv2.VideoWriter(video_out,cv2.VideoWriter_fourcc(*'DIVX'), float(FPS), (4000,2588))
# mn=float(dcmdecimal_val)
# ########### SHORT CUT FOR 0.6 CODE
# tot=file_count-1
# # ovl_ln=tot*mn ##0.6
# # half_ln=ovl_ln/2
# # ### for this below code for center based will change
# # # actl_center=1465 ## for z direction2041 ##35
# # actl_center=2041 ## for z direction2041 ##35
# # start_val=actl_center-1
# # # end_val=7869-actl_center ## 2630 ##100 x
# # end_val=3573-actl_center ## 2630 ##100
# # cc=start_val
# # vv=end_val
# ## By Changes '0' Center variation 0.6 from left and right May 21
# LN=actl_center
# LNend=LN*mn
# RP=file_count-actl_center
# RPend=RP*mn
# lxr=[]
# LNend=round(LNend,1)
# for l in np.arange(-LNend,0,mn):
# # rx=round(r,1)
# lx=round(l,2)
# lxr.append(lx)
# # print(lxr)
# RPend=round(RPend,1)
# for r in np.arange(0,RPend,mn):
# rx=round(r,1)
# lxr.append(rx)
# print(lxr)
# print(len(lxr))
# print(lxr)
# import fram_decimal
# res=fram_decimal.fram_dcml(actl_center,file_count,mn)
for f1 in sorted(files):
# for f1,xx in zip(sorted(files),lxr):
# for f1,xx in zip(sorted(files),np.arange(-1*np.int(cc),np.int(vv),mn)):
# for f1,xx in zip(sorted(files),np.arange(-1*np.int(half_ln),np.int(half_ln),0.6)):
# xr=round(xx,1)
# xr=np.array(xr)
# print(xr)
# print(xr)
# print(new)
# for xn in range(-1*file_count,file_count):
# print(xn)
RGB = cv2.imread(f1)
n=25
sum=0
i=1
while i
out.write(RGB)
i=i+1
# out.write(RGB)
# del gray ,xx,f1
# end_time = datetime.datetime.now()
# print(end_time)
# del RGB ,img,framx,width,size,data_path,files,file_count ##indir,oudir,data,
# del video_out,videoheight,videowidth
out.release()
## Main Function
color_gray(var)
end_time = datetime.datetime.now()
print(end_time)
Sub file:
import numpy as np
import os
import glob
def inout_root(var):
cwd = os.path.dirname(os.path.abspath(__file__))
# var='nb'
path=cwd+"/"+var+'.txt'
f = open(path,'r')
message = f.readline()
txp=message.split("#")
dcm_dir=txp
input_dir=dcm_dir[1]
output_dir=dcm_dir[3]
dcm_height=dcm_dir[5]
dcm_width=dcm_dir[7]
dcmaxis_dir=dcm_dir[9]
dcmdecimal_val=dcm_dir[11]
actaul_center=dcm_dir[13]
end_value=dcm_dir[15]
out_videoname=dcm_dir[17]
# print(input_dir,output_dir,dcm_height,dcm_width)
data_path = os.path.join(str(input_dir), '*jpg')
files = glob.glob(data_path)
# RGB=[]
files = glob.glob(data_path)
file_count = len(files)
# print(message)
return [input_dir,output_dir,dcm_height,dcm_width,file_count,dcmaxis_dir,dcmdecimal_val,actaul_center,end_value,out_videoname]
# stl_name=stl_name["stl_name"]
# stl_rootname=outdir+"/"+stl_name+'.stl'
# dcm=inout_root('nbx')
# input_dir=dcm[0]
# output_dir=dcm[1]
# videoheight=dcm[2]
# videoheight=int(videoheight)
# videowidth=dcm[3]
# videowidth=int(videowidth)
# dcm_len=dcm[4]
# dcmaxis_dir=dcm[5]
# dcmdecimal_val=dcm[6]
# actual_center=dcm[7]
# actual_center=int(actual_center)
# end_value=dcm[8]
# end_value=int(end_value)
# out_videoname=dcm[9]
# vide_name=output_dir+"/"+out_videoname+'.mp4'
# # print(vide_name)
print(input_dir,output_dir,videoheight,videowidth,dcm_len,dcmaxis_dir,dcmdecimal_val,actual_center,end_value)
# # print(dcm)
input_dir#/home/hp/Desktop/vscode/WORD2VIDEO/IMAGE#out_dir#/home/hp/Desktop/vscode/WORD2VIDEO#Video_height#3508#Video_widh#2481#direction#y#slidesvalue#0.5#actl_center#2092#end_val#4184#videoname#E-tron-Y-fram#