{"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":"markdown","source":"## Base code:\nhttps://www.kaggle.com/code/theoviel/dicom-resized-png-jpg\nI just changed the size of img from base code.\n\n## Dataset Links :\n\n - [256x256 pngs](https://www.kaggle.com/datasets/theoviel/rsna-breast-cancer-256-pngs)\n - [512x512 pngs](https://www.kaggle.com/datasets/theoviel/rsna-breast-cancer-512-pngs)\n - [768x768 pngs](https://www.kaggle.com/datasets/theoviel/rsna-breast-cancer-768-pngs)\n - [1024x1024 pngs](https://www.kaggle.com/datasets/theoviel/rsna-breast-cancer-1024-pngs)\n\n**Changes :**\n- Invert images with PhotometricInterpretation == \"MONOCHROME1\" ","metadata":{}},{"cell_type":"code","source":"def describe_details(arr):# measures of dispersion\n    min = np.amin(arr)\n    max = np.amax(arr)\n    range = np.ptp(arr)\n    variance = np.var(arr)\n    sd = np.std(arr)\n    mean = np.mean(t)\n    median = np.median(t)\n\n    #print(\"Array =\", arr)\n    print(\"Measures of Dispersion\")\n    print(\"Minimum =\", min)\n    print(\"Maximum =\", max)\n    print(\"Range =\", range)\n    print(\"Variance =\", variance)\n    print(\"Standard Deviation =\", sd)\n    print(\"Mean =\", mean)\n    print(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:31.167073Z","iopub.execute_input":"2023-01-15T10:38:31.168497Z","iopub.status.idle":"2023-01-15T10:38:31.202245Z","shell.execute_reply.started":"2023-01-15T10:38:31.168358Z","shell.execute_reply":"2023-01-15T10:38:31.201057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport tensorflow as tf\nprint(tf.__version__)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:31.204217Z","iopub.execute_input":"2023-01-15T10:38:31.204696Z","iopub.status.idle":"2023-01-15T10:38:37.88913Z","shell.execute_reply.started":"2023-01-15T10:38:31.204635Z","shell.execute_reply":"2023-01-15T10:38:37.887799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"package='/kaggle/input/wavetf/WaveTF-master/* ./'\n#!cp -r ../input/kagglepet/kagglePet/* ./\n!cp -r /kaggle/input/wavetf/WaveTF-master/* ./\n!cp -r /kaggle/input/wavetf/WaveTF-master/wavetf/* ./","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:37.891289Z","iopub.execute_input":"2023-01-15T10:38:37.892699Z","iopub.status.idle":"2023-01-15T10:38:40.213382Z","shell.execute_reply.started":"2023-01-15T10:38:37.89263Z","shell.execute_reply":"2023-01-15T10:38:40.211952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wavetf\nfrom wavetf import WaveTFFactory","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:40.217821Z","iopub.execute_input":"2023-01-15T10:38:40.219062Z","iopub.status.idle":"2023-01-15T10:38:41.335949Z","shell.execute_reply.started":"2023-01-15T10:38:40.218993Z","shell.execute_reply":"2023-01-15T10:38:41.334721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Initialization","metadata":{}},{"cell_type":"code","source":"!pip install -qU python-gdcm pydicom pylibjpeg","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:41.338058Z","iopub.execute_input":"2023-01-15T10:38:41.33892Z","iopub.status.idle":"2023-01-15T10:38:57.589223Z","shell.execute_reply.started":"2023-01-15T10:38:41.338873Z","shell.execute_reply":"2023-01-15T10:38:57.58798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport glob\nimport gdcm\nimport pydicom\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nfrom tqdm.notebook import tqdm\nfrom joblib import Parallel, delayed","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:57.591556Z","iopub.execute_input":"2023-01-15T10:38:57.592348Z","iopub.status.idle":"2023-01-15T10:38:58.76083Z","shell.execute_reply.started":"2023-01-15T10:38:57.592293Z","shell.execute_reply":"2023-01-15T10:38:58.75952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = glob.glob(\"/kaggle/input/rsna-breast-cancer-detection/train_images/*/*.dcm\")\n\nlen(train_images)  # 54706","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:38:58.762563Z","iopub.execute_input":"2023-01-15T10:38:58.763059Z","iopub.status.idle":"2023-01-15T10:39:39.754967Z","shell.execute_reply.started":"2023-01-15T10:38:58.763015Z","shell.execute_reply":"2023-01-15T10:39:39.753509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Examples","metadata":{}},{"cell_type":"code","source":"for f in tqdm(train_images[:3]):\n    patient = f.split('/')[-2]\n    image = f.split('/')[-1][:-4]\n\n    dicom = pydicom.dcmread(f)\n    img = dicom.pixel_array\n    print('max and min for image before normalisation',img.max(),img.min())\n    img = (img - img.min()) / (img.max() - img.min())\n    print('max and min for image',img.max(),img.min())\n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        img = 1 - img\n        \n    plt.figure(figsize=(15, 15))\n    plt.imshow(img, cmap=\"magma\")\n    plt.title(f\"{patient} {image}\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:39:39.759136Z","iopub.execute_input":"2023-01-15T10:39:39.759578Z","iopub.status.idle":"2023-01-15T10:39:44.623806Z","shell.execute_reply.started":"2023-01-15T10:39:39.759538Z","shell.execute_reply":"2023-01-15T10:39:44.622978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Denoising","metadata":{}},{"cell_type":"code","source":"w = WaveTFFactory().build('haar', dim=2)\nfor f in tqdm(train_images[:3]):\n    patient = f.split('/')[-2]\n    image = f.split('/')[-1][:-4]\n\n    dicom = pydicom.dcmread(f)\n    img = dicom.pixel_array\n    img_to_tensor = tf.convert_to_tensor(img,dtype=tf.float64)\n    img_to_tensor = img_to_tensor[tf.newaxis, ...,]\n    img_to_tensor =tf.expand_dims(img_to_tensor, -1)\n    print(img_to_tensor.shape.as_list())  # [batch, height, width, channels]\n    print('max and min for image before normalisation',img.max(),img.min())\n    \n    t1 = w.call(img_to_tensor)\n    LL=t1[:,:,:,0]\n    LH=t1[:,:,:,1]\n    HL=t1[:,:,:,2]\n    HH=t1[:,:,:,3]\n    numitor=tf.matmul(LL,LL,transpose_b=True)\n    numarator=tf.matmul(LL,LH,transpose_b=True)\n    numaratorhl=tf.matmul(LL,HL,transpose_b=True)\n    numaratorhl=tf.matmul(LL,HL,transpose_b=True)\n    numaratorhh=tf.matmul(LL,HH,transpose_b=True)\n    s_lh=np.trace(numarator.numpy()[0])/np.trace(numitor.numpy()[0])\n    s_hl=np.trace(numaratorhl.numpy()[0])/np.trace(numitor.numpy()[0])\n    s_hh=np.trace(numaratorhh.numpy()[0])/np.trace(numitor.numpy()[0])\n    #https://www.tensorflow.org/api_docs/python/tf/unstack\n    #unstack channels for denoising operation\n    t1_denoised=t1\n    p, q, r,t  =tf.unstack(t1_denoised,axis=3)\n    q=tf.math.scalar_mul(s_lh, p)\n    r=tf.math.scalar_mul(s_hl, p)\n    t=tf.math.scalar_mul(s_hh, p)\n    t1_denoised =tf.stack([p, q, r,t],axis=3)\n    w_i = WaveTFFactory().build('haar', dim=2, inverse=True)\n    image_denoised = w_i.call(t1_denoised)\n    img=image_denoised[0,:,:,0].numpy()#.astype(\"uint8\")\n    img = (img - img.min()) / (img.max() - img.min())\n    print('max and min for image',img.max(),img.min())\n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        img = 1 - img\n        \n    plt.figure(figsize=(15, 15))\n    plt.imshow(img, cmap=\"magma\")\n    plt.title(f\"{patient} {image}\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:39:44.627162Z","iopub.execute_input":"2023-01-15T10:39:44.628238Z","iopub.status.idle":"2023-01-15T10:39:53.059542Z","shell.execute_reply.started":"2023-01-15T10:39:44.628199Z","shell.execute_reply":"2023-01-15T10:39:53.058426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### resizing","metadata":{}},{"cell_type":"code","source":"w = WaveTFFactory().build('haar', dim=2)\nfor f in tqdm(train_images[:3]):\n    patient = f.split('/')[-2]\n    image = f.split('/')[-1][:-4]\n\n    dicom = pydicom.dcmread(f)\n    img = dicom.pixel_array\n    \n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        img = 1 - img\n    img_to_tensor = tf.convert_to_tensor(img,dtype=tf.float64)\n    img_to_tensor = img_to_tensor[tf.newaxis, ...,]\n    img_to_tensor =tf.expand_dims(img_to_tensor, -1)\n    print(img_to_tensor.shape.as_list())  # [batch, height, width, channels]\n    print('max and min for image before normalisation',img.max(),img.min())\n    \n    t1 = w.call(img_to_tensor)\n    img=t1[0,:,:,:3].numpy()#.astype(\"uint8\")\n    print(img.shape)\n    img = (img - img.min()) / (img.max() - img.min())\n    print('max and min for image',img.max(),img.min()) \n    plt.figure(figsize=(15, 15))\n    plt.imshow(img, cmap=\"magma\")\n    plt.title(f\"{patient} {image}\")\n    #plt.imshow(img[:,:,0], cmap=\"magma\")\n    #plt.title(f\"{patient} {image}\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:39:53.061048Z","iopub.execute_input":"2023-01-15T10:39:53.061393Z","iopub.status.idle":"2023-01-15T10:39:58.234473Z","shell.execute_reply.started":"2023-01-15T10:39:53.061364Z","shell.execute_reply":"2023-01-15T10:39:58.233346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\n#     plt.imshow(img, cmap=\"magma\")\n#     plt.title(f\"{patient} {image}\")\nplt.imshow(img[:,:,0], cmap=\"magma\")\nplt.title(f\"{patient} {image}\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:39:58.236181Z","iopub.execute_input":"2023-01-15T10:39:58.236543Z","iopub.status.idle":"2023-01-15T10:39:58.787748Z","shell.execute_reply.started":"2023-01-15T10:39:58.236508Z","shell.execute_reply":"2023-01-15T10:39:58.786548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\n#     plt.imshow(img, cmap=\"magma\")\n#     plt.title(f\"{patient} {image}\")\nplt.imshow(img[:,:,:], cmap=\"magma\")\nplt.title(f\"{patient} {image}\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:39:58.78927Z","iopub.execute_input":"2023-01-15T10:39:58.789634Z","iopub.status.idle":"2023-01-15T10:39:59.698108Z","shell.execute_reply.started":"2023-01-15T10:39:58.789604Z","shell.execute_reply":"2023-01-15T10:39:59.69713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"w = WaveTFFactory().build('haar', dim=2)\nfor f in tqdm(train_images[:3]):\n    patient = f.split('/')[-2]\n    image = f.split('/')[-1][:-4]\n\n    dicom = pydicom.dcmread(f)\n    img = dicom.pixel_array\n    \n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        img = 1 - img\n    img_to_tensor = tf.convert_to_tensor(img,dtype=tf.float64)\n    img_to_tensor = img_to_tensor[tf.newaxis, ...,]\n    img_to_tensor =tf.expand_dims(img_to_tensor, -1)\n    print(img_to_tensor.shape.as_list())  # [batch, height, width, channels]\n    print('max and min for image before normalisation',img.max(),img.min())\n    \n    t1 = w.call(img_to_tensor)\n    img=t1[0,:,:,:].numpy()#.astype(\"uint8\")\n    print(img.shape)\n#     img = (img - img.min()) / (img.max() - img.min())\n    print('max and min for image',img.max(),img.min()) \n    plt.figure(figsize=(15, 15))\n    plt.imshow(img, cmap=\"bone\")\n    plt.title(f\"{patient} {image}\")\n    #plt.imshow(img[:,:,0], cmap=\"magma\")\n    #plt.title(f\"{patient} {image}\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:39:59.699451Z","iopub.execute_input":"2023-01-15T10:39:59.699979Z","iopub.status.idle":"2023-01-15T10:40:04.564284Z","shell.execute_reply.started":"2023-01-15T10:39:59.699945Z","shell.execute_reply":"2023-01-15T10:40:04.563108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\n#     plt.imshow(img, cmap=\"magma\")\n#     plt.title(f\"{patient} {image}\")\nplt.imshow(img[:,:,0], cmap=\"bone\")\nplt.title(f\"{patient} {image}\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:40:04.566044Z","iopub.execute_input":"2023-01-15T10:40:04.566431Z","iopub.status.idle":"2023-01-15T10:40:05.111218Z","shell.execute_reply.started":"2023-01-15T10:40:04.566387Z","shell.execute_reply":"2023-01-15T10:40:05.110033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\n#     plt.imshow(img, cmap=\"magma\")\n#     plt.title(f\"{patient} {image}\")\nplt.imshow(img[:,:,3], cmap=\"bone\")\nplt.title(f\"{patient} {image}\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:40:05.113026Z","iopub.execute_input":"2023-01-15T10:40:05.113593Z","iopub.status.idle":"2023-01-15T10:40:05.649934Z","shell.execute_reply.started":"2023-01-15T10:40:05.113545Z","shell.execute_reply":"2023-01-15T10:40:05.648715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Save the processed data\n**Images are quite big so resizing them is necessary.**\n  - Use 256 to train your first models, or if you don't have a lot of compute\n  - use 512 to have competitive models\n  - Check if 768/1024 is better, if you have the compute power\n\n**I advise using the `png` format because the jpg compression can be annoying during inference.**","metadata":{}},{"cell_type":"code","source":"def process(f, size=1024, save_folder=\"\", extension=\"png\"):\n    patient = f.split('/')[-2]\n    image = f.split('/')[-1][:-4]\n\n    dicom = pydicom.dcmread(f)\n    img = dicom.pixel_array\n\n    #img = (img - img.min()) / (img.max() - img.min())\n    \n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        img = 1 - img\n    img_to_tensor = tf.convert_to_tensor(img,dtype=tf.float64)\n    img_to_tensor = img_to_tensor[tf.newaxis, ...,]\n    img_to_tensor =tf.expand_dims(img_to_tensor, -1)\n#     print(img_to_tensor.shape.as_list())  # [batch, height, width, channels]\n#     print('max and min for image before normalisation',img.max(),img.min())\n    \n    t1 = w.call(img_to_tensor)\n    img=t1[0,:,:,:3].numpy()#.astype(\"uint8\")\n    img[:,:,0] = (img[:,:,0] - img[:,:,0].min()) / (img[:,:,0].max() - img[:,:,0].min())\n#     img[:,:,1] = (img[:,:,1] - img[:,:,1].min()) / (img[:,:,1].max() - img[:,:,1].min())\n#     img[:,:,2] = (img[:,:,2] - img[:,:,2].min()) / (img[:,:,2].max() - img[:,:,2].min())\n#     img[:,:,3] = (img[:,:,3] - img[:,:,3].min()) / (img[:,:,3].max() - img[:,:,3].min())\n#     img = (img - img.min()) / (img.max() - img.min())\n    \n    \n    img[:,:,0]=img[:,:,0]*255\n#     img[:,:,1]=img[:,:,1]*255\n#     img[:,:,1]=img[:,:,2]*255\n#     img=img.astype(\"uint8\")\n    img = cv2.resize(img, (size, size))\n    \n\n    cv2.imwrite(save_folder + f\"{patient}_{image}.{extension}\", img)\n#     cv2.imwrite(save_folder + f\"{patient}_{image}.{extension}\", (img * 255))\n#     cv2.imwrite(save_folder + f\"{patient}_{image}.{extension}\", (img * 255).astype(np.uint8))","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:40:05.651432Z","iopub.execute_input":"2023-01-15T10:40:05.651812Z","iopub.status.idle":"2023-01-15T10:40:05.662893Z","shell.execute_reply.started":"2023-01-15T10:40:05.651779Z","shell.execute_reply":"2023-01-15T10:40:05.661716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntrain_images = glob.glob(\"/kaggle/input/rsna-breast-cancer-detection/train_images/*/*.dcm\")\n\nSAVE_FOLDER = \"output/train_images/\"\nSIZE = 1024\nEXTENSION = \"jpg\"\n\nos.makedirs(SAVE_FOLDER, exist_ok=True)\n\n_ = Parallel(n_jobs=4)(\n    delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n#     for uid in tqdm(train_images)\n    for uid in tqdm(train_images[:99])\n)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:40:05.664798Z","iopub.execute_input":"2023-01-15T10:40:05.665627Z","iopub.status.idle":"2023-01-15T10:43:23.884778Z","shell.execute_reply.started":"2023-01-15T10:40:05.665558Z","shell.execute_reply":"2023-01-15T10:43:23.883142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_images = glob.glob(\"/kaggle/input/rsna-breast-cancer-detection/test_images/*/*.dcm\")\n\nSAVE_FOLDER = \"output/test_images/\"\n\nos.makedirs(SAVE_FOLDER, exist_ok=True)\n\n_ = Parallel(n_jobs=4)(\n    delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n    for uid in tqdm(test_images)\n)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:23.887849Z","iopub.execute_input":"2023-01-15T10:43:23.888826Z","iopub.status.idle":"2023-01-15T10:43:27.256339Z","shell.execute_reply.started":"2023-01-15T10:43:23.888761Z","shell.execute_reply":"2023-01-15T10:43:27.254898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Done !","metadata":{}},{"cell_type":"markdown","source":"Test saved images","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_path='/kaggle/working/output/train_images'","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.258385Z","iopub.execute_input":"2023-01-15T10:43:27.259004Z","iopub.status.idle":"2023-01-15T10:43:27.264964Z","shell.execute_reply.started":"2023-01-15T10:43:27.25896Z","shell.execute_reply":"2023-01-15T10:43:27.263705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\noutput_files=[]\nfor dirname, _, filenames in os.walk(output_path):\n    for filename in filenames:\n        output_files.append(os.path.join(dirname, filename))\n        #print(os.path.join(dirname, filename))\noutput_files[1]","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.26812Z","iopub.execute_input":"2023-01-15T10:43:27.269066Z","iopub.status.idle":"2023-01-15T10:43:27.281079Z","shell.execute_reply.started":"2023-01-15T10:43:27.269007Z","shell.execute_reply":"2023-01-15T10:43:27.279594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(output_files)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.282888Z","iopub.execute_input":"2023-01-15T10:43:27.283351Z","iopub.status.idle":"2023-01-15T10:43:27.296893Z","shell.execute_reply.started":"2023-01-15T10:43:27.283315Z","shell.execute_reply":"2023-01-15T10:43:27.295517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = cv2.imread(output_files[0], cv2.IMREAD_UNCHANGED)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.298493Z","iopub.execute_input":"2023-01-15T10:43:27.298876Z","iopub.status.idle":"2023-01-15T10:43:27.329278Z","shell.execute_reply.started":"2023-01-15T10:43:27.298843Z","shell.execute_reply":"2023-01-15T10:43:27.328086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(image)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.330763Z","iopub.execute_input":"2023-01-15T10:43:27.331184Z","iopub.status.idle":"2023-01-15T10:43:27.763486Z","shell.execute_reply.started":"2023-01-15T10:43:27.33115Z","shell.execute_reply":"2023-01-15T10:43:27.76133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #RGB - Blue\n# cv2.imshow('B-RGB.jpg',image[:, :, 0])","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.770511Z","iopub.execute_input":"2023-01-15T10:43:27.771385Z","iopub.status.idle":"2023-01-15T10:43:27.776607Z","shell.execute_reply.started":"2023-01-15T10:43:27.771338Z","shell.execute_reply":"2023-01-15T10:43:27.77528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    (B, G, R,A) = cv2.split(image)\n    print('4channels')\n    four_channles=True\nexcept:\n    (B, G, R) = cv2.split(image)\n    print('3channels')\n    four_channles=False","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.778539Z","iopub.execute_input":"2023-01-15T10:43:27.779302Z","iopub.status.idle":"2023-01-15T10:43:27.798746Z","shell.execute_reply.started":"2023-01-15T10:43:27.779253Z","shell.execute_reply":"2023-01-15T10:43:27.797264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(B)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:27.800722Z","iopub.execute_input":"2023-01-15T10:43:27.801122Z","iopub.status.idle":"2023-01-15T10:43:28.179416Z","shell.execute_reply.started":"2023-01-15T10:43:27.801089Z","shell.execute_reply":"2023-01-15T10:43:28.177979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(G)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:28.181166Z","iopub.execute_input":"2023-01-15T10:43:28.181723Z","iopub.status.idle":"2023-01-15T10:43:28.563068Z","shell.execute_reply.started":"2023-01-15T10:43:28.181678Z","shell.execute_reply":"2023-01-15T10:43:28.561599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(R)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:28.565098Z","iopub.execute_input":"2023-01-15T10:43:28.565576Z","iopub.status.idle":"2023-01-15T10:43:28.938553Z","shell.execute_reply.started":"2023-01-15T10:43:28.565531Z","shell.execute_reply":"2023-01-15T10:43:28.937019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if four_channles==True:\n    plt.imshow(A)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:28.940047Z","iopub.execute_input":"2023-01-15T10:43:28.940434Z","iopub.status.idle":"2023-01-15T10:43:28.946635Z","shell.execute_reply.started":"2023-01-15T10:43:28.940403Z","shell.execute_reply":"2023-01-15T10:43:28.945221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpydata = np.asarray(G)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:28.948041Z","iopub.execute_input":"2023-01-15T10:43:28.948416Z","iopub.status.idle":"2023-01-15T10:43:28.959057Z","shell.execute_reply.started":"2023-01-15T10:43:28.948384Z","shell.execute_reply":"2023-01-15T10:43:28.957736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_details(numpydata)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:28.960619Z","iopub.execute_input":"2023-01-15T10:43:28.961009Z","iopub.status.idle":"2023-01-15T10:43:29.004508Z","shell.execute_reply.started":"2023-01-15T10:43:28.960974Z","shell.execute_reply":"2023-01-15T10:43:29.003501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpydata = np.asarray(R)\ndescribe_details(numpydata)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.006271Z","iopub.execute_input":"2023-01-15T10:43:29.008033Z","iopub.status.idle":"2023-01-15T10:43:29.03824Z","shell.execute_reply.started":"2023-01-15T10:43:29.007965Z","shell.execute_reply":"2023-01-15T10:43:29.036738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpydata","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.039886Z","iopub.execute_input":"2023-01-15T10:43:29.041281Z","iopub.status.idle":"2023-01-15T10:43:29.050566Z","shell.execute_reply.started":"2023-01-15T10:43:29.041231Z","shell.execute_reply":"2023-01-15T10:43:29.049237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpydata = np.asarray(B)\ndescribe_details(numpydata)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.052758Z","iopub.execute_input":"2023-01-15T10:43:29.053278Z","iopub.status.idle":"2023-01-15T10:43:29.08401Z","shell.execute_reply.started":"2023-01-15T10:43:29.053231Z","shell.execute_reply":"2023-01-15T10:43:29.082599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpydata","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.085366Z","iopub.execute_input":"2023-01-15T10:43:29.085767Z","iopub.status.idle":"2023-01-15T10:43:29.093181Z","shell.execute_reply.started":"2023-01-15T10:43:29.085731Z","shell.execute_reply":"2023-01-15T10:43:29.091858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nshutil.rmtree(\"/kaggle/working/wavetf\")","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.094558Z","iopub.execute_input":"2023-01-15T10:43:29.095218Z","iopub.status.idle":"2023-01-15T10:43:29.106204Z","shell.execute_reply.started":"2023-01-15T10:43:29.095182Z","shell.execute_reply":"2023-01-15T10:43:29.104935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.rmtree(\"/kaggle/working/examples\")","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.10735Z","iopub.execute_input":"2023-01-15T10:43:29.107806Z","iopub.status.idle":"2023-01-15T10:43:29.118192Z","shell.execute_reply.started":"2023-01-15T10:43:29.107763Z","shell.execute_reply":"2023-01-15T10:43:29.116824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.rmtree(\"/kaggle/working/docs\")","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.120003Z","iopub.execute_input":"2023-01-15T10:43:29.120402Z","iopub.status.idle":"2023-01-15T10:43:29.130105Z","shell.execute_reply.started":"2023-01-15T10:43:29.120367Z","shell.execute_reply":"2023-01-15T10:43:29.128802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.rmtree(\"/kaggle/working/tests\")","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.132385Z","iopub.execute_input":"2023-01-15T10:43:29.132906Z","iopub.status.idle":"2023-01-15T10:43:29.141222Z","shell.execute_reply.started":"2023-01-15T10:43:29.132842Z","shell.execute_reply":"2023-01-15T10:43:29.140194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"folder = '/kaggle/working'\nfor filename in os.listdir(folder):\n    file_path = os.path.join(folder, filename)\n    try:\n        if os.path.isfile(file_path) or os.path.islink(file_path):\n            os.unlink(file_path)\n        elif os.path.isdir(file_path):\n#             shutil.rmtree(file_path)\n            print('sunt bine')\n    except Exception as e:\n        print('Failed to delete %s. Reason: %s' % (file_path, e))","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.14275Z","iopub.execute_input":"2023-01-15T10:43:29.143218Z","iopub.status.idle":"2023-01-15T10:43:29.512501Z","shell.execute_reply.started":"2023-01-15T10:43:29.14317Z","shell.execute_reply":"2023-01-15T10:43:29.511563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"INP_SIZE=1024\ndef decode(path):\n        file_bytes = tf.io.read_file(path)\n        img = tf.image.decode_jpeg(file_bytes, channels = 3)\n        img = tf.reshape(img, [*[INP_SIZE]*2, 3])\n        return img","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.513498Z","iopub.execute_input":"2023-01-15T10:43:29.513854Z","iopub.status.idle":"2023-01-15T10:43:29.525045Z","shell.execute_reply.started":"2023-01-15T10:43:29.513823Z","shell.execute_reply":"2023-01-15T10:43:29.523888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imaginex=decode(output_files[0])","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.526381Z","iopub.execute_input":"2023-01-15T10:43:29.526872Z","iopub.status.idle":"2023-01-15T10:43:29.563481Z","shell.execute_reply.started":"2023-01-15T10:43:29.526835Z","shell.execute_reply":"2023-01-15T10:43:29.562108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(imaginex)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:29.565388Z","iopub.execute_input":"2023-01-15T10:43:29.565833Z","iopub.status.idle":"2023-01-15T10:43:30.28932Z","shell.execute_reply.started":"2023-01-15T10:43:29.565796Z","shell.execute_reply":"2023-01-15T10:43:30.288011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numpydata = np.asarray(imaginex)\nnumpydata.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:30.29106Z","iopub.execute_input":"2023-01-15T10:43:30.291512Z","iopub.status.idle":"2023-01-15T10:43:30.299851Z","shell.execute_reply.started":"2023-01-15T10:43:30.29147Z","shell.execute_reply":"2023-01-15T10:43:30.298515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(numpydata[:,:,2])","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:30.300974Z","iopub.execute_input":"2023-01-15T10:43:30.301298Z","iopub.status.idle":"2023-01-15T10:43:30.977412Z","shell.execute_reply.started":"2023-01-15T10:43:30.301269Z","shell.execute_reply":"2023-01-15T10:43:30.976209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(numpydata[:,:,0])","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:30.978822Z","iopub.execute_input":"2023-01-15T10:43:30.979263Z","iopub.status.idle":"2023-01-15T10:43:31.639481Z","shell.execute_reply.started":"2023-01-15T10:43:30.979231Z","shell.execute_reply":"2023-01-15T10:43:31.638314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(numpydata[:,:,1])","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:31.641214Z","iopub.execute_input":"2023-01-15T10:43:31.641919Z","iopub.status.idle":"2023-01-15T10:43:32.306874Z","shell.execute_reply.started":"2023-01-15T10:43:31.641875Z","shell.execute_reply":"2023-01-15T10:43:32.305516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figure, axis = plt.subplots(5, 3, figsize=(10, 15))\naxe1=0\nfor files in output_files[:5]:\n    plt.figure(figsize=(15, 15))\n    image = cv2.imread(files, cv2.IMREAD_UNCHANGED)\n    (B, G, R) = cv2.split(image)\n    # For Sine Function\n    axis[axe1, 0].imshow(B)\n    axis[axe1, 0].set_title(\"First Channel\")\n    axis[axe1, 1].imshow(G)\n    axis[axe1, 1].set_title(\"LH\")\n    axis[axe1, 2].imshow(R)\n    axis[axe1, 2].set_title(\"HL\")\n    axe1=axe1+1\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:43:32.308384Z","iopub.execute_input":"2023-01-15T10:43:32.308782Z","iopub.status.idle":"2023-01-15T10:43:35.527582Z","shell.execute_reply.started":"2023-01-15T10:43:32.308748Z","shell.execute_reply":"2023-01-15T10:43:35.526268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pywt\nimport pywt.data","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:47:58.075642Z","iopub.execute_input":"2023-01-15T10:47:58.076163Z","iopub.status.idle":"2023-01-15T10:47:58.152289Z","shell.execute_reply.started":"2023-01-15T10:47:58.076127Z","shell.execute_reply":"2023-01-15T10:47:58.151281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Pywavelets","metadata":{}},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'bior1.3')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T10:51:07.891325Z","iopub.execute_input":"2023-01-15T10:51:07.891901Z","iopub.status.idle":"2023-01-15T10:51:08.754177Z","shell.execute_reply.started":"2023-01-15T10:51:07.891856Z","shell.execute_reply":"2023-01-15T10:51:08.752666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"help(pywt.dwt2)","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:06:07.397481Z","iopub.execute_input":"2023-01-15T11:06:07.398432Z","iopub.status.idle":"2023-01-15T11:06:07.406291Z","shell.execute_reply.started":"2023-01-15T11:06:07.398362Z","shell.execute_reply":"2023-01-15T11:06:07.4047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"coif4","metadata":{}},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'coif4')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:07:38.112793Z","iopub.execute_input":"2023-01-15T11:07:38.113282Z","iopub.status.idle":"2023-01-15T11:07:39.075577Z","shell.execute_reply.started":"2023-01-15T11:07:38.113249Z","shell.execute_reply":"2023-01-15T11:07:39.074209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"'sym10'","metadata":{}},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'sym10')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:09:36.575884Z","iopub.execute_input":"2023-01-15T11:09:36.577033Z","iopub.status.idle":"2023-01-15T11:09:37.515607Z","shell.execute_reply.started":"2023-01-15T11:09:36.576983Z","shell.execute_reply":"2023-01-15T11:09:37.514658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pywt.wavelist(kind='discrete')","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:10:53.966946Z","iopub.execute_input":"2023-01-15T11:10:53.967518Z","iopub.status.idle":"2023-01-15T11:10:53.978247Z","shell.execute_reply.started":"2023-01-15T11:10:53.96748Z","shell.execute_reply":"2023-01-15T11:10:53.976783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"dmey","metadata":{}},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'dmey')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:11:09.310969Z","iopub.execute_input":"2023-01-15T11:11:09.311466Z","iopub.status.idle":"2023-01-15T11:11:10.680384Z","shell.execute_reply.started":"2023-01-15T11:11:09.311431Z","shell.execute_reply":"2023-01-15T11:11:10.679064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'sym2')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:12:05.254446Z","iopub.execute_input":"2023-01-15T11:12:05.25502Z","iopub.status.idle":"2023-01-15T11:12:06.08839Z","shell.execute_reply.started":"2023-01-15T11:12:05.254978Z","shell.execute_reply":"2023-01-15T11:12:06.087223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'sym10')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:12:25.879328Z","iopub.execute_input":"2023-01-15T11:12:25.880871Z","iopub.status.idle":"2023-01-15T11:12:26.683571Z","shell.execute_reply.started":"2023-01-15T11:12:25.880818Z","shell.execute_reply":"2023-01-15T11:12:26.682007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'bior6.8')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:15:03.219127Z","iopub.execute_input":"2023-01-15T11:15:03.219725Z","iopub.status.idle":"2023-01-15T11:15:04.177023Z","shell.execute_reply.started":"2023-01-15T11:15:03.21968Z","shell.execute_reply":"2023-01-15T11:15:04.175847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'haar')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.bone)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:13:35.225433Z","iopub.execute_input":"2023-01-15T11:13:35.226433Z","iopub.status.idle":"2023-01-15T11:13:35.962008Z","shell.execute_reply.started":"2023-01-15T11:13:35.226383Z","shell.execute_reply":"2023-01-15T11:13:35.960877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'db2')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.magma)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:16:17.175215Z","iopub.execute_input":"2023-01-15T11:16:17.176668Z","iopub.status.idle":"2023-01-15T11:16:17.999829Z","shell.execute_reply.started":"2023-01-15T11:16:17.176582Z","shell.execute_reply":"2023-01-15T11:16:17.99837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Wavelet transform of image, and plot approximation and details\ndicom = pydicom.dcmread(train_images[15])\nimg = dicom.pixel_array\nprint('max and min for image before normalisation',img.max(),img.min())\nimg = (img - img.min()) / (img.max() - img.min())\nprint('max and min for image',img.max(),img.min())\nif dicom.PhotometricInterpretation == \"MONOCHROME1\":\n    img = 1 - img\ntitles = ['Approximation', ' Horizontal detail',\n          'Vertical detail', 'Diagonal detail']\ncoeffs2 = pywt.dwt2(img, 'sym20')\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(15, 5))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.magma)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:16:03.166574Z","iopub.execute_input":"2023-01-15T11:16:03.168183Z","iopub.status.idle":"2023-01-15T11:16:04.330049Z","shell.execute_reply.started":"2023-01-15T11:16:03.168115Z","shell.execute_reply":"2023-01-15T11:16:04.328907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figure, axis = plt.subplots(5, 3, figsize=(10, 15))\naxe1=0\nfor files in output_files[:5]:\n    plt.figure(figsize=(15, 15))\n    image = cv2.imread(files, cv2.IMREAD_UNCHANGED)\n    (B, G, R) = cv2.split(image)\n    # For Sine Function\n    axis[axe1, 0].imshow(B)\n    axis[axe1, 0].set_title(\"First Channel\")\n    axis[axe1, 1].imshow(G)\n    axis[axe1, 1].set_title(\"LH\")\n    axis[axe1, 2].imshow(R)\n    axis[axe1, 2].set_title(\"HL\")\n    axe1=axe1+1\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-15T11:15:45.109671Z","iopub.execute_input":"2023-01-15T11:15:45.110178Z","iopub.status.idle":"2023-01-15T11:15:48.828698Z","shell.execute_reply.started":"2023-01-15T11:15:45.110141Z","shell.execute_reply":"2023-01-15T11:15:48.827277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}