{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install pydicom","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:20:28.828567Z","iopub.execute_input":"2023-02-08T12:20:28.829582Z","iopub.status.idle":"2023-02-08T12:20:42.364223Z","shell.execute_reply.started":"2023-02-08T12:20:28.829477Z","shell.execute_reply":"2023-02-08T12:20:42.362544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install nilearn","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:28:31.299186Z","iopub.execute_input":"2023-02-08T12:28:31.300125Z","iopub.status.idle":"2023-02-08T12:28:42.697454Z","shell.execute_reply.started":"2023-02-08T12:28:31.300086Z","shell.execute_reply":"2023-02-08T12:28:42.696125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np \nimport nrrd\nimport cv2\nimport os\nfrom os import listdir\nfrom tqdm import tqdm\nfrom random import randint\nimport nibabel as nib\nimport pydicom as pdm\nimport nilearn as nl\nimport nilearn.plotting as nlplt\nimport h5py\nimport glob\n\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm\nimport matplotlib.animation as anim\n\nimport imageio\nfrom skimage.transform import resize\nfrom skimage.util import montage\n\nfrom IPython.display import Image as show_gif\n\nimport warnings\nwarnings.simplefilter(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:29:00.512312Z","iopub.execute_input":"2023-02-08T12:29:00.512827Z","iopub.status.idle":"2023-02-08T12:29:00.523765Z","shell.execute_reply.started":"2023-02-08T12:29:00.512758Z","shell.execute_reply":"2023-02-08T12:29:00.522415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = []\n\n\nfor directory_path in glob.glob(\"/kaggle/working/\"):\n    for img_path in glob.glob(os.path.join(directory_path, \"*.jpg\")):\n        print(img_path)\n        img = cv2.imread(img_path, 1)       \n        train_images.append(img)\n       \n#Convert list to array for machine learning processing        \ntrain_images = np.array(train_images)","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:29:12.497255Z","iopub.execute_input":"2023-02-08T12:29:12.498167Z","iopub.status.idle":"2023-02-08T12:29:12.506266Z","shell.execute_reply.started":"2023-02-08T12:29:12.498108Z","shell.execute_reply":"2023-02-08T12:29:12.50504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_images)","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:29:16.052702Z","iopub.execute_input":"2023-02-08T12:29:16.053143Z","iopub.status.idle":"2023-02-08T12:29:16.060057Z","shell.execute_reply.started":"2023-02-08T12:29:16.053106Z","shell.execute_reply":"2023-02-08T12:29:16.058513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:30:17.525368Z","iopub.execute_input":"2023-02-08T12:30:17.525809Z","iopub.status.idle":"2023-02-08T12:30:17.53097Z","shell.execute_reply.started":"2023-02-08T12:30:17.525756Z","shell.execute_reply":"2023-02-08T12:30:17.52982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dicom_folder = '/kaggle/input/osic-pulmonary-fibrosis-progression/test/ID00419637202311204720264' \njpg_folder = '/kaggle/input/jpg' #Set the folder of your output folder for jpg files \n# Step 1. prepare your input(.dcm) and output(.jpg) filepath \ndcm_jpg_map = {}\nfor dicom_f in os.listdir(dicom_folder):\n    dicom_filepath = os.path.join(dicom_folder, dicom_f)\n    jpg_f = dicom_f.replace('.dcm', '.jpg') \n    jpg_filepath = os.path.join(jpg_folder,jpg_f)\n    dcm_jpg_map[dicom_filepath] = jpg_filepath\n\n# Now, dcm_jpg_map is key,value pair of input dcm filepath and output jpg filepath\n# Step 2. process your image by input/output information\n\nfor dicom_filepath, jpg_filepath in dcm_jpg_map.items():\n    # convert dicom file into jpg file\n    dicom = pydicom.read_file(dicom_filepath)\n    np_pixel_array = dicom.pixel_array\n    cv2.imwrite(jpg_filepath, np_pixel_array)","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:30:20.373242Z","iopub.execute_input":"2023-02-08T12:30:20.373637Z","iopub.status.idle":"2023-02-08T12:30:20.527825Z","shell.execute_reply.started":"2023-02-08T12:30:20.373605Z","shell.execute_reply":"2023-02-08T12:30:20.526644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from skimage import io\nfrom skimage.filters import unsharp_mask","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:30:23.25277Z","iopub.execute_input":"2023-02-08T12:30:23.253511Z","iopub.status.idle":"2023-02-08T12:30:23.258021Z","shell.execute_reply.started":"2023-02-08T12:30:23.253471Z","shell.execute_reply":"2023-02-08T12:30:23.257081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unsharped_img = unsharp_mask(img , radius=3, amount=1)\nimport matplotlib.pyplot as plt\nfig = plt.figure(figsize=(12, 12))\nax1 = fig.add_subplot(2,2,1)\nax1.imshow(img, cmap='gray')\nax1.title.set_text('Input Image')\nax2 = fig.add_subplot(2,2,2)\nax2.imshow(unsharped_img, cmap='gray')\nax2.title.set_text('Unsharped Image')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-08T12:33:10.876145Z","iopub.execute_input":"2023-02-08T12:33:10.87654Z","iopub.status.idle":"2023-02-08T12:33:10.911163Z","shell.execute_reply.started":"2023-02-08T12:33:10.87651Z","shell.execute_reply":"2023-02-08T12:33:10.909993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}