{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-09T13:18:28.267401Z","iopub.execute_input":"2023-01-09T13:18:28.267779Z","iopub.status.idle":"2023-01-09T13:18:28.273666Z","shell.execute_reply.started":"2023-01-09T13:18:28.267749Z","shell.execute_reply":"2023-01-09T13:18:28.272592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Load tensorflow ","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport tensorflow as tf\nprint(tf.__version__)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:18:28.714189Z","iopub.execute_input":"2023-01-09T13:18:28.714612Z","iopub.status.idle":"2023-01-09T13:18:33.702585Z","shell.execute_reply.started":"2023-01-09T13:18:28.714577Z","shell.execute_reply":"2023-01-09T13:18:33.701386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Experiment with WaveTF a DWT method for image preprocessing using tensorflow.","metadata":{}},{"cell_type":"markdown","source":"This notebook is not a solution for the competition is just an experiment for using the wavelet transform as a convolution/processing/image processing layer.\nA discrete wavelet transform (DWT) is any wavelet transform for which the wavelets are discretely sampled.A key advantage it has over Fourier transforms is temporal resolution: it captures both frequency and location information (location in time).The first DWT was invented by Hungarian mathematician Alfréd Haar.\n\nKnown examples in image processing:\nWavelets are often used to denoise two dimensional signals, such as images one use case is removing unwanted white Gaussian noise from the noisy images.\n\nOne example (https://en.wikipedia.org/wiki/Discrete_wavelet_transform)\n\nWaveTF output: in  case of a 2D image, an N level decomposition can be performed for one image channel resulting in 3N+1 different frequency bands namely, LL, LH, HL and HH:\n\n* resulted in a DWT image that is based on approximate image detail (LL), horizontal details(HL), vertical details(LH) and diagonal details(HH).\n\nLL, LH, HL and HH are also known by other names, the sub-bands may be respectively called a1 or the first average image, h1 called horizontal fluctuation, v1 called vertical fluctuation and d1 called the first diagonal fluctuation.\n\nUsually:The next level of wavelet transform is applied to the low frequency sub band image LL only.\n\n![DWT](https://upload.wikimedia.org/wikipedia/commons/4/47/Piramide-hierarchie_2d_dwt.png)#\n\n![discrete wavelet transform](https://upload.wikimedia.org/wikipedia/commons/e/e0/Jpeg2000_2-level_wavelet_transform-lichtenstein.png)#\n\n\nFor example DWT was proposed for image compression of MRI:\nhttps://www.scirp.org/journal/paperinformation.aspx?paperid=37647","metadata":{}},{"cell_type":"markdown","source":"#### Library used in notebook\n##### Author\n\n> #### WaveTF is developed by\n\n> #### Francesco Versaci, CRS4 francesco.versaci@gmail.com\n##### License\n\nWaveTF is licensed under the Apache License, Version 2.0. See LICENSE for further details.\n\n##### Author description\nWavelet transforms are a family of signal transformations They produce a mix of time/spatial and frequency data Countless applications, e.g., image compression, medical\nimaging, finance, geophysics, and astronomy\nThere is a growing number of applications in machine learning But there were no efficient 2D wavelet libraries available for\nKeras","metadata":{}},{"cell_type":"markdown","source":"> Understanding the wavelet transform is straightforward once you have a solid grasp on how the Fourier transform works. \n\n### Disclaimer \nIn this notebook the wavelet transform is not applied to a signal : it is applied to the image or to an image as an array. \n\n\nThe Haar transform is the simplest orthogonal wavelet transform. It is computed by iterating difference and averaging between odd and even samples of the signal. Since we are in 2-D, we need to compute the average and difference in the horizontal and then in the vertical direction (or in the reverse order, it does not mind).\nmore on the subject here:\nhttps://www.numerical-tours.com/matlab/wavelet_2_haar2d/\n\n\nIn mathematics, the Haar wavelet is a sequence of rescaled \"square-shaped\" functions which together form a wavelet family or basis. Wavelet analysis is similar to Fourier analysis in that it allows a target function over an interval to be represented in terms of an orthonormal basis. The Haar sequence is now recognised as the first known wavelet basis and extensively used as a teaching example.\n\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Haar_wavelet.svg/800px-Haar_wavelet.svg.png\" width=\"300\"> wikipedia: Haar wavelet\n\nApplication in similar cases( Image processing):\n* Image compression:\nhttps://www.idosi.org/mejsr/mejsr2(2)/7.pdf\n*  2-D multiresolution analysis with the Haar transform. It was introduced in 1910 by Haar:\nhttps://www.numerical-tours.com/matlab/wavelet_2_haar2d/\n* edge detection: Edge Detection In Images Using Haar Wavelets, Sobel, Gabor And Laplacian Filters:\nhttps://www.researchgate.net/publication/324911043_Edge_Detection_In_Images_Using_Haar_Wavelets_Sobel_Gabor_And_Laplacian_Filters\n\n","metadata":{}},{"cell_type":"markdown","source":"https://www.sciencedirect.com/science/article/pii/S2314728817300508","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Demo of WaveTF layer","metadata":{}},{"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-09T13:18:33.704587Z","iopub.execute_input":"2023-01-09T13:18:33.705157Z","iopub.status.idle":"2023-01-09T13:18:36.054257Z","shell.execute_reply.started":"2023-01-09T13:18:33.705125Z","shell.execute_reply":"2023-01-09T13:18:36.05285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"##### Import Package","metadata":{}},{"cell_type":"code","source":"import wavetf\nfrom wavetf import WaveTFFactory","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:18:36.055813Z","iopub.execute_input":"2023-01-09T13:18:36.056891Z","iopub.status.idle":"2023-01-09T13:18:37.136148Z","shell.execute_reply.started":"2023-01-09T13:18:36.05685Z","shell.execute_reply":"2023-01-09T13:18:37.134853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Official demo with dummy data","metadata":{}},{"cell_type":"code","source":"# input tensor\nt0 = tf. random.uniform([32, 360, 360, 3], dtype=tf.float32 )\n# transform\nw = WaveTFFactory().build('db2', dim=2)\nt1 = w.call(t0)\n# anti−transform\nw_i = WaveTFFactory().build('db2', dim=2, inverse=True)\nt2 = w_i.call(t1)\n# compute difference\n# delta = abs(t2−t0)\n# print ( f ' Precision error : { tf .math.reduce_max(delta)}\ndelta=abs(t2-t0)\n\nprint(f\"Precision error :{tf .math.reduce_max(delta)}.\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:18:37.138737Z","iopub.execute_input":"2023-01-09T13:18:37.139198Z","iopub.status.idle":"2023-01-09T13:18:39.252479Z","shell.execute_reply.started":"2023-01-09T13:18:37.139142Z","shell.execute_reply":"2023-01-09T13:18:39.251384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### View some Images","metadata":{}},{"cell_type":"code","source":"path_to_files='/kaggle/input/rsna-breast-cancer-512-pngs/'\n# list to store files\nres = []\nimages_list=[]\n# Iterate directory\n\nfor path in os.listdir(path_to_files):\n#     print(i)\n#     print(elem)\n#     print(path)\n    # check if current path is a file\n    if os.path.isfile(os.path.join(path_to_files, path)):\n#         res.append(path)\n        elem=path_to_files+path\n        images_list.append(elem)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:18:42.332927Z","iopub.execute_input":"2023-01-09T13:18:42.333293Z","iopub.status.idle":"2023-01-09T13:20:47.601797Z","shell.execute_reply.started":"2023-01-09T13:18:42.333264Z","shell.execute_reply":"2023-01-09T13:20:47.600714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(images_list)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:20:47.603692Z","iopub.execute_input":"2023-01-09T13:20:47.604278Z","iopub.status.idle":"2023-01-09T13:20:47.612723Z","shell.execute_reply.started":"2023-01-09T13:20:47.604244Z","shell.execute_reply":"2023-01-09T13:20:47.61174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:20:47.6141Z","iopub.execute_input":"2023-01-09T13:20:47.614627Z","iopub.status.idle":"2023-01-09T13:20:47.622415Z","shell.execute_reply.started":"2023-01-09T13:20:47.614594Z","shell.execute_reply":"2023-01-09T13:20:47.621577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# from IPython.display import  Image, display\n# from PIL import ImageShow\nimage = Image.open(images_list[1])\n \n# summarize some details about the image\nprint(image.format)\nprint(image.size)\nprint(image.mode)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:20:47.624557Z","iopub.execute_input":"2023-01-09T13:20:47.625067Z","iopub.status.idle":"2023-01-09T13:20:47.651506Z","shell.execute_reply.started":"2023-01-09T13:20:47.625036Z","shell.execute_reply":"2023-01-09T13:20:47.650258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(Image.open(images_list[1]))","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:20:47.655293Z","iopub.execute_input":"2023-01-09T13:20:47.655666Z","iopub.status.idle":"2023-01-09T13:20:47.686654Z","shell.execute_reply.started":"2023-01-09T13:20:47.655633Z","shell.execute_reply":"2023-01-09T13:20:47.685494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (7,7))\nim2 = plt.imshow(image, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear')\nplt.savefig('original_image.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:27:56.813635Z","iopub.execute_input":"2023-01-09T13:27:56.814021Z","iopub.status.idle":"2023-01-09T13:27:57.21902Z","shell.execute_reply.started":"2023-01-09T13:27:56.81399Z","shell.execute_reply":"2023-01-09T13:27:57.217827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:26:43.400479Z","iopub.execute_input":"2023-01-09T13:26:43.400912Z","iopub.status.idle":"2023-01-09T13:26:43.417465Z","shell.execute_reply.started":"2023-01-09T13:26:43.40088Z","shell.execute_reply":"2023-01-09T13:26:43.41638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (5,5))\nim2 = plt.imshow(image, cmap=plt.cm.magma, alpha=.9, interpolation='bilinear')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:20:48.65099Z","iopub.execute_input":"2023-01-09T13:20:48.659869Z","iopub.status.idle":"2023-01-09T13:20:49.161227Z","shell.execute_reply.started":"2023-01-09T13:20:48.659823Z","shell.execute_reply":"2023-01-09T13:20:49.160377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Image to tensor","metadata":{}},{"cell_type":"code","source":"images_list[:9]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:28:39.261092Z","iopub.execute_input":"2023-01-09T13:28:39.261523Z","iopub.status.idle":"2023-01-09T13:28:39.269793Z","shell.execute_reply.started":"2023-01-09T13:28:39.261488Z","shell.execute_reply":"2023-01-09T13:28:39.268374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfont = {'family' : 'normal',\n        'weight' : 'bold',\n        'size'   : 7}\nplt.rc('font', **font)\nplt.figure(figsize=(10, 10))\n#for images, labels in train_ds.take(1):\n# for path in images_list[:9]:  \nfor i in range(9):\n\n    ax = plt.subplot(3, 3, i + 1)\n    image_path=images_list[i]\n    image = Image.open(image_path)\n#         filename=image_path+\"imagine\"+str(i)+\".jpg\"\n    plt.imshow(image)\n#         plt.title(labels[i].numpy())\n#         £print(labels[i].numpy())\n    plt.axis(\"off\")\n#         plt.savefig(filename)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:28:40.387823Z","iopub.execute_input":"2023-01-09T13:28:40.388375Z","iopub.status.idle":"2023-01-09T13:28:41.582066Z","shell.execute_reply.started":"2023-01-09T13:28:40.388331Z","shell.execute_reply":"2023-01-09T13:28:41.581249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimage = Image.open(images_list[0])\nimage=np.asarray(image).astype(float)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:28:59.629915Z","iopub.execute_input":"2023-01-09T13:28:59.630344Z","iopub.status.idle":"2023-01-09T13:28:59.638484Z","shell.execute_reply.started":"2023-01-09T13:28:59.630296Z","shell.execute_reply":"2023-01-09T13:28:59.637476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Transform to a float 64 tensor","metadata":{}},{"cell_type":"code","source":"img_to_tensor = tf.convert_to_tensor(image,dtype=tf.float64)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:01.962778Z","iopub.execute_input":"2023-01-09T13:29:01.96398Z","iopub.status.idle":"2023-01-09T13:29:01.969804Z","shell.execute_reply.started":"2023-01-09T13:29:01.963939Z","shell.execute_reply":"2023-01-09T13:29:01.968691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Warning: it is a keras laye a batch is needed. \nthis step is necessary for using outside a model ","metadata":{}},{"cell_type":"code","source":"image = img_to_tensor[tf.newaxis, ...,]\nimage.shape.as_list()  # [batch, height, width, channels]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:03.058238Z","iopub.execute_input":"2023-01-09T13:29:03.05951Z","iopub.status.idle":"2023-01-09T13:29:03.06935Z","shell.execute_reply.started":"2023-01-09T13:29:03.059469Z","shell.execute_reply":"2023-01-09T13:29:03.068268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"for grayscale image add channel info\nhttps://stackoverflow.com/questions/65305528/add-a-dimension-to-a-tensorflow-tensor","metadata":{}},{"cell_type":"code","source":"image =tf.expand_dims(image, -1)\nimage.shape.as_list()  # [batch, height, width, channels]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:04.675246Z","iopub.execute_input":"2023-01-09T13:29:04.675675Z","iopub.status.idle":"2023-01-09T13:29:04.683468Z","shell.execute_reply.started":"2023-01-09T13:29:04.675637Z","shell.execute_reply":"2023-01-09T13:29:04.682201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Initialize a layer","metadata":{}},{"cell_type":"code","source":"w = WaveTFFactory().build('haar', dim=2)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:05.979659Z","iopub.execute_input":"2023-01-09T13:29:05.980455Z","iopub.status.idle":"2023-01-09T13:29:05.987618Z","shell.execute_reply.started":"2023-01-09T13:29:05.980406Z","shell.execute_reply":"2023-01-09T13:29:05.986284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Apply  wave transform calling the keras layer","metadata":{}},{"cell_type":"code","source":"t1 = w.call(image)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:06.82769Z","iopub.execute_input":"2023-01-09T13:29:06.828074Z","iopub.status.idle":"2023-01-09T13:29:06.870078Z","shell.execute_reply.started":"2023-01-09T13:29:06.828044Z","shell.execute_reply":"2023-01-09T13:29:06.869143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1.shape[3]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:07.475137Z","iopub.execute_input":"2023-01-09T13:29:07.475841Z","iopub.status.idle":"2023-01-09T13:29:07.483955Z","shell.execute_reply.started":"2023-01-09T13:29:07.475804Z","shell.execute_reply":"2023-01-09T13:29:07.482573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:07.850571Z","iopub.execute_input":"2023-01-09T13:29:07.850957Z","iopub.status.idle":"2023-01-09T13:29:07.860576Z","shell.execute_reply.started":"2023-01-09T13:29:07.850926Z","shell.execute_reply":"2023-01-09T13:29:07.859364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Results\n4 channels 256 image","metadata":{}},{"cell_type":"code","source":"title_list=[\"image detail (LL)\", \"horizontal details(HL)\", \"vertical details(LH)\",\"diagonal details(HH)\"]\nplt.figure(figsize=(10, 10))\nfor i in range(t1.shape[3]):\n    ax = plt.subplot(2, 2, i + 1)\n    \n    #image_path='/kaggle/working/smalltrain/'\n    plt.imshow(t1[0,:,:,i].numpy().astype(\"uint8\"))\n    plt.title(title_list[i])\n    #         £print(labels[i].numpy())\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:29:09.115493Z","iopub.execute_input":"2023-01-09T13:29:09.116432Z","iopub.status.idle":"2023-01-09T13:29:09.655993Z","shell.execute_reply.started":"2023-01-09T13:29:09.116385Z","shell.execute_reply":"2023-01-09T13:29:09.655161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Example threshholding","metadata":{}},{"cell_type":"markdown","source":"Do your own experiments if necessary ","metadata":{}},{"cell_type":"code","source":"result = tf.where(t1>15, t1,0.0)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:30:00.562422Z","iopub.execute_input":"2023-01-09T13:30:00.562846Z","iopub.status.idle":"2023-01-09T13:30:00.569694Z","shell.execute_reply.started":"2023-01-09T13:30:00.562812Z","shell.execute_reply":"2023-01-09T13:30:00.568628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"title_list=[\"image detail (LL)\", \"horizontal details(HL)\", \"vertical details(LH)\",\"diagonal details(HH)\"]\nplt.figure(figsize=(7, 7))\nfor i in range(result.shape[3]):\n    ax = plt.subplot(2, 2, i + 1)\n    #image_path='/kaggle/working/smalltrain/'\n    plt.imshow(result[0,:,:,i].numpy().astype(\"uint8\"))\n    plt.title(title_list[i])\n    #         £print(labels[i].numpy())\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:13.390166Z","iopub.execute_input":"2023-01-09T13:31:13.391235Z","iopub.status.idle":"2023-01-09T13:31:13.841922Z","shell.execute_reply.started":"2023-01-09T13:31:13.391196Z","shell.execute_reply":"2023-01-09T13:31:13.841024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Similar works:\n* https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5561084/\n* \n* https://www.ripublication.com/ijcamspl17/ijcamv12n1spl_55.pdf","metadata":{}},{"cell_type":"markdown","source":"#### Wavelet image de-noising\n* Step 1: Choice of a wavelet (e.g. Haar, Db2) and number of levels or scales for the decomposition. Computation of the forward wavelet transform of the noisy image.\n* Step 2: Estimation of a threshold.\n* Step3: Choice of a shrinkage rule and application of the threshold to the detail coefficients.\n* Step4: Application of the inverse transform (wavelet reconstruction) using the modified (threshold) coefficients.","metadata":{}},{"cell_type":"markdown","source":"### Threshold\n\nThresholds values are\n* Donoho-Johnstone method: Fixed form (default)\n* Birgé-Massart method: Penalized high, Penalized medium, Penalized low\nThe last three choices include a sparsity parameter a (a > 1). See One-Dimensional DWT and SWT De-Noising.\n\n* Empirical method: Balance sparsity-norm, default = sqrt\n\n* https://web.stanford.edu/dept/statistics/cgi-bin/donoho/wp-content/uploads/2018/08/denoiserelease3.pdf\n* http://www.ece.northwestern.edu/local-apps/matlabhelp/toolbox/wavelet/ch06_a47.html\n\n\n","metadata":{}},{"cell_type":"code","source":"t1.shape\nLL=t1[:,:,:,0]\nLH=t1[:,:,:,1]\nHL=t1[:,:,:,2]\nHH=t1[:,:,:,3]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:27.627597Z","iopub.execute_input":"2023-01-09T13:31:27.628507Z","iopub.status.idle":"2023-01-09T13:31:27.636509Z","shell.execute_reply.started":"2023-01-09T13:31:27.628469Z","shell.execute_reply":"2023-01-09T13:31:27.635392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(LL)\nmedian = np.median(LL)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:28.478909Z","iopub.execute_input":"2023-01-09T13:31:28.479279Z","iopub.status.idle":"2023-01-09T13:31:28.491605Z","shell.execute_reply.started":"2023-01-09T13:31:28.479249Z","shell.execute_reply":"2023-01-09T13:31:28.490505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"thresholded= tf.where(t1>30, t1,0.0)\n#thresholded= tf.where(tf.math.logical_or(t1<-0.00,t1>60), t1,0.0)\n#thresholded= tf.where(tf.math.logical_and(t1<-0.00,t1>60), t1,0.0)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:29.002896Z","iopub.execute_input":"2023-01-09T13:31:29.003299Z","iopub.status.idle":"2023-01-09T13:31:29.009863Z","shell.execute_reply.started":"2023-01-09T13:31:29.003264Z","shell.execute_reply":"2023-01-09T13:31:29.008747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"title_list=[\"image detail (LL)\", \"horizontal details(HL)\", \"vertical details(LH)\",\"diagonal details(HH)\"]\nplt.figure(figsize=(10, 10))\nfor i in range(thresholded.shape[3]):\n    ax = plt.subplot(2, 2, i + 1)\n    #image_path='/kaggle/working/smalltrain/'\n    plt.imshow(thresholded[0,:,:,i].numpy().astype(\"uint8\"))\n    plt.title(title_list[i])\n    #         £print(labels[i].numpy())\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:29.442334Z","iopub.execute_input":"2023-01-09T13:31:29.442721Z","iopub.status.idle":"2023-01-09T13:31:29.934682Z","shell.execute_reply.started":"2023-01-09T13:31:29.442689Z","shell.execute_reply":"2023-01-09T13:31:29.933528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nplt.imshow(thresholded[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(title_list[0])","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:30.165005Z","iopub.execute_input":"2023-01-09T13:31:30.16544Z","iopub.status.idle":"2023-01-09T13:31:30.623374Z","shell.execute_reply.started":"2023-01-09T13:31:30.165405Z","shell.execute_reply":"2023-01-09T13:31:30.622544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(LH)\nmedian = np.median(LH)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:30.624748Z","iopub.execute_input":"2023-01-09T13:31:30.625756Z","iopub.status.idle":"2023-01-09T13:31:30.631777Z","shell.execute_reply.started":"2023-01-09T13:31:30.62572Z","shell.execute_reply":"2023-01-09T13:31:30.630972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(HL)\nmedian = np.median(HL)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:31.072424Z","iopub.execute_input":"2023-01-09T13:31:31.073107Z","iopub.status.idle":"2023-01-09T13:31:31.07919Z","shell.execute_reply.started":"2023-01-09T13:31:31.07307Z","shell.execute_reply":"2023-01-09T13:31:31.0784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(HH)\nmedian = np.median(HH)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:31.600465Z","iopub.execute_input":"2023-01-09T13:31:31.600864Z","iopub.status.idle":"2023-01-09T13:31:31.608615Z","shell.execute_reply.started":"2023-01-09T13:31:31.600834Z","shell.execute_reply":"2023-01-09T13:31:31.607296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Second WaveTF convolution","metadata":{}},{"cell_type":"code","source":"t11 = w.call(t1)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:33.899463Z","iopub.execute_input":"2023-01-09T13:31:33.900471Z","iopub.status.idle":"2023-01-09T13:31:33.928057Z","shell.execute_reply.started":"2023-01-09T13:31:33.900427Z","shell.execute_reply":"2023-01-09T13:31:33.927212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t11.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:34.327389Z","iopub.execute_input":"2023-01-09T13:31:34.328145Z","iopub.status.idle":"2023-01-09T13:31:34.335135Z","shell.execute_reply.started":"2023-01-09T13:31:34.328087Z","shell.execute_reply":"2023-01-09T13:31:34.334278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t11.shape[3]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:31:34.898592Z","iopub.execute_input":"2023-01-09T13:31:34.899294Z","iopub.status.idle":"2023-01-09T13:31:34.905594Z","shell.execute_reply.started":"2023-01-09T13:31:34.899258Z","shell.execute_reply":"2023-01-09T13:31:34.904498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nfor i in range(t11.shape[3]):\n    ax = plt.subplot(4, 4, i + 1)\n    #image_path='/kaggle/working/smalltrain/'\n    plt.imshow(t11[0,:,:,i].numpy().astype(\"uint8\"))\n    plt.title(i)\n    #         £print(labels[i].numpy())\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:32:58.810307Z","iopub.execute_input":"2023-01-09T13:32:58.810781Z","iopub.status.idle":"2023-01-09T13:33:00.089853Z","shell.execute_reply.started":"2023-01-09T13:32:58.810743Z","shell.execute_reply":"2023-01-09T13:33:00.088658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Inverse WaveTF convolution from second convolution","metadata":{}},{"cell_type":"code","source":"compressed_image=t11[:,:,:,:4]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:33:06.073216Z","iopub.execute_input":"2023-01-09T13:33:06.073699Z","iopub.status.idle":"2023-01-09T13:33:06.079677Z","shell.execute_reply.started":"2023-01-09T13:33:06.073661Z","shell.execute_reply":"2023-01-09T13:33:06.078582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"compressed_image.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:33:12.142609Z","iopub.execute_input":"2023-01-09T13:33:12.143015Z","iopub.status.idle":"2023-01-09T13:33:12.150573Z","shell.execute_reply.started":"2023-01-09T13:33:12.142982Z","shell.execute_reply":"2023-01-09T13:33:12.1494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"w_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nreconstructed_image = w_i.call(compressed_image)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:33:20.388792Z","iopub.execute_input":"2023-01-09T13:33:20.389204Z","iopub.status.idle":"2023-01-09T13:33:20.407065Z","shell.execute_reply.started":"2023-01-09T13:33:20.389171Z","shell.execute_reply":"2023-01-09T13:33:20.405733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(7, 7))\nplt.imshow(reconstructed_image[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"LL Inverse Wavelet transform second convolution 512=>256\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:34:38.144838Z","iopub.execute_input":"2023-01-09T13:34:38.145264Z","iopub.status.idle":"2023-01-09T13:34:38.511264Z","shell.execute_reply.started":"2023-01-09T13:34:38.145231Z","shell.execute_reply":"2023-01-09T13:34:38.509887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"reconstructed_image.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:34:40.998884Z","iopub.execute_input":"2023-01-09T13:34:41.000069Z","iopub.status.idle":"2023-01-09T13:34:41.007186Z","shell.execute_reply.started":"2023-01-09T13:34:40.999989Z","shell.execute_reply":"2023-01-09T13:34:41.005773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### etc","metadata":{}},{"cell_type":"code","source":"t12 = w.call(t11)\ncompressed_image1=t12[:,:,:,:4]\nw_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nreconstructed_image2 = w_i.call(compressed_image1)\nplt.imshow(reconstructed_image2[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform second convolution\")","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-01-09T13:34:52.151295Z","iopub.execute_input":"2023-01-09T13:34:52.151745Z","iopub.status.idle":"2023-01-09T13:34:52.486461Z","shell.execute_reply.started":"2023-01-09T13:34:52.151709Z","shell.execute_reply":"2023-01-09T13:34:52.485391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t12 = w.call(t11)\ncompressed_image1=t12[:,:,:,4:8]\nw_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nreconstructed_image2 = w_i.call(compressed_image1)\nplt.imshow(reconstructed_image2[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform second convolution\")","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-01-09T13:34:54.379708Z","iopub.execute_input":"2023-01-09T13:34:54.380128Z","iopub.status.idle":"2023-01-09T13:34:54.708617Z","shell.execute_reply.started":"2023-01-09T13:34:54.380093Z","shell.execute_reply":"2023-01-09T13:34:54.707283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t12 = w.call(t11)\ncompressed_image1=t12[:,:,:,8:16]\nw_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nreconstructed_image2 = w_i.call(compressed_image1)\nplt.imshow(reconstructed_image2[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform second convolution\")","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-01-09T13:34:55.163624Z","iopub.execute_input":"2023-01-09T13:34:55.164017Z","iopub.status.idle":"2023-01-09T13:34:55.518985Z","shell.execute_reply.started":"2023-01-09T13:34:55.163984Z","shell.execute_reply":"2023-01-09T13:34:55.517552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t12 = w.call(t11)\ncompressed_image1=t12[:,:,:,8:32]\nw_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nreconstructed_image2 = w_i.call(compressed_image1)\nplt.imshow(reconstructed_image2[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform second convolution\")","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-01-09T13:34:56.435426Z","iopub.execute_input":"2023-01-09T13:34:56.435825Z","iopub.status.idle":"2023-01-09T13:34:56.78686Z","shell.execute_reply.started":"2023-01-09T13:34:56.435791Z","shell.execute_reply":"2023-01-09T13:34:56.785601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inverse WaveTF convolution from first convolution","metadata":{}},{"cell_type":"code","source":"w_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nt2 = w_i.call(t1)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:35:02.083262Z","iopub.execute_input":"2023-01-09T13:35:02.083708Z","iopub.status.idle":"2023-01-09T13:35:02.120611Z","shell.execute_reply.started":"2023-01-09T13:35:02.083668Z","shell.execute_reply":"2023-01-09T13:35:02.11903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t2.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:35:03.595836Z","iopub.execute_input":"2023-01-09T13:35:03.596233Z","iopub.status.idle":"2023-01-09T13:35:03.603802Z","shell.execute_reply.started":"2023-01-09T13:35:03.596202Z","shell.execute_reply":"2023-01-09T13:35:03.602493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(t2[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")\nplt.savefig('original_reconstructed_image.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:15.545292Z","iopub.execute_input":"2023-01-09T13:36:15.545688Z","iopub.status.idle":"2023-01-09T13:36:16.467921Z","shell.execute_reply.started":"2023-01-09T13:36:15.545654Z","shell.execute_reply":"2023-01-09T13:36:16.466797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Appendix","metadata":{}},{"cell_type":"markdown","source":"#### Testing the proposed method from:\n\n> Denoising and compression in wavelet domain via projection onto approximation coefficients\n> Mario Mastriani\n\n> The simulations demonstrate that the POAC technique improves the noise reduction and compression performan- ces in wavelet domain to the maximum.\n\nPOAC -the new algorithm is called Projection Onto Approximation Coefficients (POAC).\n\nUsefull for comression and decompression. The resulted image present compression artefacts. ","metadata":{}},{"cell_type":"markdown","source":"Denoising\n#https://arxiv.org/ftp/arxiv/papers/1608/1608.00265.pdf","metadata":{}},{"cell_type":"code","source":"t1.shape\nLL=t1[:,:,:,0]\nLH=t1[:,:,:,1]\nHL=t1[:,:,:,2]\nHH=t1[:,:,:,3]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:42.330639Z","iopub.execute_input":"2023-01-09T13:36:42.331037Z","iopub.status.idle":"2023-01-09T13:36:42.338947Z","shell.execute_reply.started":"2023-01-09T13:36:42.331004Z","shell.execute_reply":"2023-01-09T13:36:42.337953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numitor=tf.matmul(LL,LL,transpose_b=True)\nnumarator=tf.matmul(LL,LH,transpose_b=True)\nnumaratorhl=tf.matmul(LL,HL,transpose_b=True)\nnumaratorhl=tf.matmul(LL,HL,transpose_b=True)\nnumaratorhh=tf.matmul(LL,HH,transpose_b=True)\ns_lh=np.trace(numarator.numpy()[0])/np.trace(numitor.numpy()[0])\ns_hl=np.trace(numaratorhl.numpy()[0])/np.trace(numitor.numpy()[0])\ns_hh=np.trace(numaratorhh.numpy()[0])/np.trace(numitor.numpy()[0])","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:43.180256Z","iopub.execute_input":"2023-01-09T13:36:43.181292Z","iopub.status.idle":"2023-01-09T13:36:43.196563Z","shell.execute_reply.started":"2023-01-09T13:36:43.181257Z","shell.execute_reply":"2023-01-09T13:36:43.195601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Split tensorflow image in associated channels:","metadata":{}},{"cell_type":"code","source":"#https://www.tensorflow.org/api_docs/python/tf/unstack\n#unstack channels for denoising operation\nt1_denoised=t1\np, q, r,t  =tf.unstack(t1_denoised,axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:44.843234Z","iopub.execute_input":"2023-01-09T13:36:44.844256Z","iopub.status.idle":"2023-01-09T13:36:44.855123Z","shell.execute_reply.started":"2023-01-09T13:36:44.844218Z","shell.execute_reply":"2023-01-09T13:36:44.854192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Apply operations per channels","metadata":{}},{"cell_type":"code","source":"q=tf.math.scalar_mul(s_lh, p)\nr=tf.math.scalar_mul(s_hl, p)\nt=tf.math.scalar_mul(s_hh, p)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:46.027628Z","iopub.execute_input":"2023-01-09T13:36:46.028001Z","iopub.status.idle":"2023-01-09T13:36:46.035014Z","shell.execute_reply.started":"2023-01-09T13:36:46.02797Z","shell.execute_reply":"2023-01-09T13:36:46.033845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Stack image again","metadata":{}},{"cell_type":"code","source":"t1_denoised =tf.stack([p, q, r,t],axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:48.387122Z","iopub.execute_input":"2023-01-09T13:36:48.387512Z","iopub.status.idle":"2023-01-09T13:36:48.395148Z","shell.execute_reply.started":"2023-01-09T13:36:48.387482Z","shell.execute_reply":"2023-01-09T13:36:48.393914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lista_plot=[p[0], q[0], r[0],t[0]]\ntitle_list=[\"image detail (LL)\", \"horizontal details(HL)\", \"vertical details(LH)\",\"diagonal details(HH)\"]\nplt.figure(figsize=(10, 10))\nfor i in range(thresholded.shape[3]):\n    ax = plt.subplot(2, 2, i + 1)\n    #image_path='/kaggle/working/smalltrain/'\n    plt.imshow(lista_plot[i].numpy().astype(\"uint8\"))\n    plt.title(title_list[i])\n    #         £print(labels[i].numpy())\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:48.828017Z","iopub.execute_input":"2023-01-09T13:36:48.828408Z","iopub.status.idle":"2023-01-09T13:36:49.320418Z","shell.execute_reply.started":"2023-01-09T13:36:48.828378Z","shell.execute_reply":"2023-01-09T13:36:49.319299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Denoised image","metadata":{}},{"cell_type":"code","source":"w_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nimage_denoised = w_i.call(t1_denoised)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:36:50.48801Z","iopub.execute_input":"2023-01-09T13:36:50.488413Z","iopub.status.idle":"2023-01-09T13:36:50.519826Z","shell.execute_reply.started":"2023-01-09T13:36:50.488382Z","shell.execute_reply":"2023-01-09T13:36:50.518799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(image_denoised[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")\nplt.savefig('original_denoised_image.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:05.491437Z","iopub.execute_input":"2023-01-09T13:38:05.492543Z","iopub.status.idle":"2023-01-09T13:38:06.328349Z","shell.execute_reply.started":"2023-01-09T13:38:05.492504Z","shell.execute_reply":"2023-01-09T13:38:06.327391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Testing 1024 images","metadata":{}},{"cell_type":"code","source":"image1024='/kaggle/input/rsna-mammography-images-as-pngs/images_as_pngs_1024/train_images_processed_1024/10011/220375232.png'","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:07.107438Z","iopub.execute_input":"2023-01-09T13:38:07.108114Z","iopub.status.idle":"2023-01-09T13:38:07.112146Z","shell.execute_reply.started":"2023-01-09T13:38:07.10807Z","shell.execute_reply":"2023-01-09T13:38:07.111285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(Image.open(image1024))","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:07.748694Z","iopub.execute_input":"2023-01-09T13:38:07.74939Z","iopub.status.idle":"2023-01-09T13:38:07.825713Z","shell.execute_reply.started":"2023-01-09T13:38:07.749355Z","shell.execute_reply":"2023-01-09T13:38:07.824833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image1024 = Image.open(image1024)\nimage1024=np.asarray(image1024).astype(float)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:08.725622Z","iopub.execute_input":"2023-01-09T13:38:08.726385Z","iopub.status.idle":"2023-01-09T13:38:08.746466Z","shell.execute_reply.started":"2023-01-09T13:38:08.726345Z","shell.execute_reply":"2023-01-09T13:38:08.745392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_to_tensor = tf.convert_to_tensor(image1024,dtype=tf.float64)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:13.389642Z","iopub.execute_input":"2023-01-09T13:38:13.39004Z","iopub.status.idle":"2023-01-09T13:38:13.397507Z","shell.execute_reply.started":"2023-01-09T13:38:13.390008Z","shell.execute_reply":"2023-01-09T13:38:13.396174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = img_to_tensor[tf.newaxis, ...,]\nimage.shape.as_list()  # [batch, height, width, channels]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:14.507733Z","iopub.execute_input":"2023-01-09T13:38:14.508161Z","iopub.status.idle":"2023-01-09T13:38:14.517076Z","shell.execute_reply.started":"2023-01-09T13:38:14.508126Z","shell.execute_reply":"2023-01-09T13:38:14.515941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image =tf.expand_dims(image, -1)\nimage.shape.as_list()  # [batch, height, width, channels]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:15.724147Z","iopub.execute_input":"2023-01-09T13:38:15.724534Z","iopub.status.idle":"2023-01-09T13:38:15.73538Z","shell.execute_reply.started":"2023-01-09T13:38:15.724503Z","shell.execute_reply":"2023-01-09T13:38:15.734395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"w = WaveTFFactory().build('db2', dim=2)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:16.780137Z","iopub.execute_input":"2023-01-09T13:38:16.780578Z","iopub.status.idle":"2023-01-09T13:38:16.787541Z","shell.execute_reply.started":"2023-01-09T13:38:16.780543Z","shell.execute_reply":"2023-01-09T13:38:16.786058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1 = w.call(image)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:17.675627Z","iopub.execute_input":"2023-01-09T13:38:17.677112Z","iopub.status.idle":"2023-01-09T13:38:17.778423Z","shell.execute_reply.started":"2023-01-09T13:38:17.677051Z","shell.execute_reply":"2023-01-09T13:38:17.777556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t2 = w.call(t1)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:18.426802Z","iopub.execute_input":"2023-01-09T13:38:18.427471Z","iopub.status.idle":"2023-01-09T13:38:18.513466Z","shell.execute_reply.started":"2023-01-09T13:38:18.427437Z","shell.execute_reply":"2023-01-09T13:38:18.512329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t3 = w.call(t2)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:19.310844Z","iopub.execute_input":"2023-01-09T13:38:19.311242Z","iopub.status.idle":"2023-01-09T13:38:19.393914Z","shell.execute_reply.started":"2023-01-09T13:38:19.311209Z","shell.execute_reply":"2023-01-09T13:38:19.392562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t4 = w.call(t3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:19.78035Z","iopub.execute_input":"2023-01-09T13:38:19.780724Z","iopub.status.idle":"2023-01-09T13:38:19.863606Z","shell.execute_reply.started":"2023-01-09T13:38:19.780695Z","shell.execute_reply":"2023-01-09T13:38:19.862388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Thresholding per channel.","metadata":{}},{"cell_type":"markdown","source":"split tensorflow image in channels","metadata":{}},{"cell_type":"code","source":"#https://www.tensorflow.org/api_docs/python/tf/unstack\n#unstack channels for denoising operation\nt1_threshold=t1\np, q, r,t  =tf.unstack(t1_threshold,axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:22.461639Z","iopub.execute_input":"2023-01-09T13:38:22.462028Z","iopub.status.idle":"2023-01-09T13:38:22.469569Z","shell.execute_reply.started":"2023-01-09T13:38:22.461996Z","shell.execute_reply":"2023-01-09T13:38:22.468334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(q)\nmedian = np.median(q)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:38:23.386994Z","iopub.execute_input":"2023-01-09T13:38:23.387433Z","iopub.status.idle":"2023-01-09T13:38:23.397198Z","shell.execute_reply.started":"2023-01-09T13:38:23.387396Z","shell.execute_reply":"2023-01-09T13:38:23.396001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.imshow(q[0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")\nplt.savefig('HL_HH_LH_image.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:11.354165Z","iopub.execute_input":"2023-01-09T13:39:11.354721Z","iopub.status.idle":"2023-01-09T13:39:11.745463Z","shell.execute_reply.started":"2023-01-09T13:39:11.354677Z","shell.execute_reply":"2023-01-09T13:39:11.744339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q=tf.where(q<mean, q,0.0)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:12.522947Z","iopub.execute_input":"2023-01-09T13:39:12.523577Z","iopub.status.idle":"2023-01-09T13:39:12.532738Z","shell.execute_reply.started":"2023-01-09T13:39:12.523543Z","shell.execute_reply":"2023-01-09T13:39:12.5319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.imshow(q[0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:13.286526Z","iopub.execute_input":"2023-01-09T13:39:13.287283Z","iopub.status.idle":"2023-01-09T13:39:13.607642Z","shell.execute_reply.started":"2023-01-09T13:39:13.287246Z","shell.execute_reply":"2023-01-09T13:39:13.606381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(r)\nmedian = np.median(r)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:14.030113Z","iopub.execute_input":"2023-01-09T13:39:14.030501Z","iopub.status.idle":"2023-01-09T13:39:14.041278Z","shell.execute_reply.started":"2023-01-09T13:39:14.030469Z","shell.execute_reply":"2023-01-09T13:39:14.040162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.imshow(r[0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:15.220888Z","iopub.execute_input":"2023-01-09T13:39:15.221303Z","iopub.status.idle":"2023-01-09T13:39:15.541737Z","shell.execute_reply.started":"2023-01-09T13:39:15.221269Z","shell.execute_reply":"2023-01-09T13:39:15.540488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r=tf.where(q<mean, q,0.0)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:18.635386Z","iopub.execute_input":"2023-01-09T13:39:18.63576Z","iopub.status.idle":"2023-01-09T13:39:18.642977Z","shell.execute_reply.started":"2023-01-09T13:39:18.635731Z","shell.execute_reply":"2023-01-09T13:39:18.641979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.imshow(r[0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:19.569697Z","iopub.execute_input":"2023-01-09T13:39:19.570458Z","iopub.status.idle":"2023-01-09T13:39:19.889529Z","shell.execute_reply.started":"2023-01-09T13:39:19.570421Z","shell.execute_reply":"2023-01-09T13:39:19.888195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean = np.mean(t)\nmedian = np.median(t)\nprint(\"Mean =\", mean)\nprint(\"Median =\", median)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:20.238281Z","iopub.execute_input":"2023-01-09T13:39:20.23868Z","iopub.status.idle":"2023-01-09T13:39:20.246714Z","shell.execute_reply.started":"2023-01-09T13:39:20.238648Z","shell.execute_reply":"2023-01-09T13:39:20.245777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.imshow(t[0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:21.388404Z","iopub.execute_input":"2023-01-09T13:39:21.389022Z","iopub.status.idle":"2023-01-09T13:39:21.704958Z","shell.execute_reply.started":"2023-01-09T13:39:21.388986Z","shell.execute_reply":"2023-01-09T13:39:21.703667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t=tf.where(t<mean, q,0.0)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:22.100929Z","iopub.execute_input":"2023-01-09T13:39:22.101359Z","iopub.status.idle":"2023-01-09T13:39:22.109852Z","shell.execute_reply.started":"2023-01-09T13:39:22.101328Z","shell.execute_reply":"2023-01-09T13:39:22.108707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(5, 5))\nplt.imshow(t[0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:23.039602Z","iopub.execute_input":"2023-01-09T13:39:23.039968Z","iopub.status.idle":"2023-01-09T13:39:23.365077Z","shell.execute_reply.started":"2023-01-09T13:39:23.039937Z","shell.execute_reply":"2023-01-09T13:39:23.363954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Stack channles again","metadata":{}},{"cell_type":"code","source":"t1_thresholded =tf.stack([p, q, r,t],axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:24.660186Z","iopub.execute_input":"2023-01-09T13:39:24.66057Z","iopub.status.idle":"2023-01-09T13:39:24.669861Z","shell.execute_reply.started":"2023-01-09T13:39:24.660538Z","shell.execute_reply":"2023-01-09T13:39:24.66879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"title_list=[\"image detail (LL)\", \"horizontal details(HL)\", \"vertical details(LH)\",\"diagonal details(HH)\"]\nplt.figure(figsize=(10, 10))\nfor i in range(t1_thresholded.shape[3]):\n    ax = plt.subplot(2, 2, i + 1)\n    #image_path='/kaggle/working/smalltrain/'\n    plt.imshow(t1_thresholded[0,:,:,i].numpy().astype(\"uint8\"))\n    plt.title(title_list[i])\n    #         £print(labels[i].numpy())\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:25.779191Z","iopub.execute_input":"2023-01-09T13:39:25.780518Z","iopub.status.idle":"2023-01-09T13:39:26.68629Z","shell.execute_reply.started":"2023-01-09T13:39:25.780473Z","shell.execute_reply":"2023-01-09T13:39:26.685238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Check results","metadata":{}},{"cell_type":"code","source":"w_i = WaveTFFactory().build('haar', dim=2, inverse=True)\nimage_thresholded = w_i.call(t1_thresholded)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:28.195885Z","iopub.execute_input":"2023-01-09T13:39:28.196607Z","iopub.status.idle":"2023-01-09T13:39:28.274765Z","shell.execute_reply.started":"2023-01-09T13:39:28.196554Z","shell.execute_reply":"2023-01-09T13:39:28.273418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(image_thresholded[0,:,:,0].numpy().astype(\"uint8\"))\nplt.title(\"Inverse Wavelet transform:512=>256=>512 denoising\")\n","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:29.229452Z","iopub.execute_input":"2023-01-09T13:39:29.229828Z","iopub.status.idle":"2023-01-09T13:39:29.913971Z","shell.execute_reply.started":"2023-01-09T13:39:29.229799Z","shell.execute_reply":"2023-01-09T13:39:29.912817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Compression LL Slice","metadata":{}},{"cell_type":"code","source":"f, axarr = plt.subplots(3,2,figsize=(15, 15))\naxarr[0,0].set_title('original image ')\naxarr[0,0].imshow(image1024)\naxarr[0,1].set_title('first wavelet')\naxarr[0,1].imshow(t1[0,:,:,0].numpy().astype(\"uint8\"))\naxarr[1,0].set_title('second wavelet')\naxarr[1,0].imshow(t2[0,:,:,0].numpy().astype(\"uint8\"))\naxarr[1,1].set_title('third wavelet')\naxarr[1,1].imshow(t3[0,:,:,0].numpy().astype(\"uint8\"))\naxarr[2,0].set_title('four wavelet')\naxarr[2,0].imshow(t4[0,:,:,0].numpy().astype(\"uint8\"))\naxarr[2,1].set_title('first wavelet')\naxarr[2,1].imshow(t1[0,:,:,0].numpy().astype(\"uint8\"))\n# axarr[1,0].imshow(image, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear')\n# axarr[1,1].imshow(reconstructed_image[0,:,:,0].numpy().astype(\"uint8\"))","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:29.915942Z","iopub.execute_input":"2023-01-09T13:39:29.91627Z","iopub.status.idle":"2023-01-09T13:39:31.248231Z","shell.execute_reply.started":"2023-01-09T13:39:29.916241Z","shell.execute_reply":"2023-01-09T13:39:31.247396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Decompression ","metadata":{}},{"cell_type":"code","source":"w = WaveTFFactory().build('db2', dim=2)\nt1 = w.call(image)\nt2 = w.call(t1)\nt3 = w.call(t2)\nt4 = w.call(t3)\nw_i = WaveTFFactory().build('db2', dim=2, inverse=True)\nt4i = w_i.call(t4)\nt3i= w_i.call(t3)\nt2i= w_i.call(t2)\nt1i= w_i.call(t1)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:31.249887Z","iopub.execute_input":"2023-01-09T13:39:31.250409Z","iopub.status.idle":"2023-01-09T13:39:31.918032Z","shell.execute_reply.started":"2023-01-09T13:39:31.250376Z","shell.execute_reply":"2023-01-09T13:39:31.917034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(t3i[0,:,:,:1].numpy().astype(\"uint8\"))","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:31.919364Z","iopub.execute_input":"2023-01-09T13:39:31.919675Z","iopub.status.idle":"2023-01-09T13:39:32.199061Z","shell.execute_reply.started":"2023-01-09T13:39:31.919647Z","shell.execute_reply":"2023-01-09T13:39:32.197771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, axarr = plt.subplots(4,2,figsize=(15, 15))\naxarr[0,0].set_title('original image ')\naxarr[0,0].imshow(image1024)\naxarr[0,1].set_title('inverse first wavelet')\naxarr[0,1].imshow(t1i[0].numpy().astype(\"uint8\"))\naxarr[1,0].set_title('inverse second wavelet LL')\naxarr[1,0].imshow(t2i[0,:,:,:1].numpy().astype(\"uint8\"))\naxarr[1,1].set_title('inverse third wavelet  LL')\naxarr[1,1].imshow(t3i[0,:,:,:1].numpy().astype(\"uint8\"))\naxarr[2,0].set_title('inverse four wavelet LL')\naxarr[2,0].imshow(t4i[0,:,:,:1].numpy().astype(\"uint8\"))\naxarr[2,1].set_title('inverse second wavelet false colors details')\naxarr[2,1].imshow(t2i[0,:,:,1:4].numpy().astype(\"uint8\"))\naxarr[3,0].set_title('inverse third wavelet false colors details')\naxarr[3,0].imshow(t3i[0,:,:,3:6].numpy().astype(\"uint8\"))\naxarr[3,1].set_title('inverse third wavelet false colors details')\naxarr[3,1].imshow(t3i[0,:,:,6:9].numpy().astype(\"uint8\"))\n# axarr[1,0].imshow(image, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear')\n# axarr[1,1].imshow(reconstructed_image[0,:,:,0].numpy().astype(\"uint8\"))","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:32.325Z","iopub.execute_input":"2023-01-09T13:39:32.325421Z","iopub.status.idle":"2023-01-09T13:39:34.082908Z","shell.execute_reply.started":"2023-01-09T13:39:32.325387Z","shell.execute_reply":"2023-01-09T13:39:34.081512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Playground","metadata":{}},{"cell_type":"code","source":"#https://www.tensorflow.org/api_docs/python/tf/unstack\n#unstack channels for denoising operation\nt1_threshold=t1\np, q, r,t  =tf.unstack(t1_threshold,axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:34.085029Z","iopub.execute_input":"2023-01-09T13:39:34.085408Z","iopub.status.idle":"2023-01-09T13:39:34.093925Z","shell.execute_reply.started":"2023-01-09T13:39:34.085374Z","shell.execute_reply":"2023-01-09T13:39:34.09255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-09T13:39:34.095166Z","iopub.execute_input":"2023-01-09T13:39:34.095515Z","iopub.status.idle":"2023-01-09T13:39:34.105559Z","shell.execute_reply.started":"2023-01-09T13:39:34.095484Z","shell.execute_reply":"2023-01-09T13:39:34.104499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_details(q)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:34.707095Z","iopub.execute_input":"2023-01-09T13:39:34.707505Z","iopub.status.idle":"2023-01-09T13:39:34.720717Z","shell.execute_reply.started":"2023-01-09T13:39:34.707474Z","shell.execute_reply":"2023-01-09T13:39:34.719367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_details(r)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:34.988026Z","iopub.execute_input":"2023-01-09T13:39:34.988443Z","iopub.status.idle":"2023-01-09T13:39:35.000355Z","shell.execute_reply.started":"2023-01-09T13:39:34.988411Z","shell.execute_reply":"2023-01-09T13:39:34.999102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe_details(t)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:35.2311Z","iopub.execute_input":"2023-01-09T13:39:35.232175Z","iopub.status.idle":"2023-01-09T13:39:35.241675Z","shell.execute_reply.started":"2023-01-09T13:39:35.232113Z","shell.execute_reply":"2023-01-09T13:39:35.240568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q= tf.where(tf.math.logical_and(q>-3.00,q<3), q,0.0)\nr= tf.where(tf.math.logical_and(r>-6.00,r<6), r,0.0)\nt= tf.where(tf.math.logical_and(t>-1.2,t<1.2), t,0.0)\n# q= tf.where(tf.math.logical_and(q>-30.00,q<40), 0.0,q)\n# r= tf.where(tf.math.logical_and(r>-40.00,r<40), 0.0,r)\n# t= tf.where(tf.math.logical_and(t>-20.00,t<20), 0.0,t)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:35.496534Z","iopub.execute_input":"2023-01-09T13:39:35.497497Z","iopub.status.idle":"2023-01-09T13:39:35.510244Z","shell.execute_reply.started":"2023-01-09T13:39:35.497446Z","shell.execute_reply":"2023-01-09T13:39:35.509128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1_details=tf.stack([p,q,r,t],axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:35.956199Z","iopub.execute_input":"2023-01-09T13:39:35.957303Z","iopub.status.idle":"2023-01-09T13:39:35.968007Z","shell.execute_reply.started":"2023-01-09T13:39:35.957243Z","shell.execute_reply":"2023-01-09T13:39:35.966902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image1=t1_details.numpy()[0]\nimage1.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:36.180204Z","iopub.execute_input":"2023-01-09T13:39:36.181383Z","iopub.status.idle":"2023-01-09T13:39:36.190718Z","shell.execute_reply.started":"2023-01-09T13:39:36.181333Z","shell.execute_reply":"2023-01-09T13:39:36.189182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(image1[:,:,0])\nplt.title(\"Wavelet details fake color image\")\nplt.savefig('1024firstlevelconvolution.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:36.668121Z","iopub.execute_input":"2023-01-09T13:39:36.669196Z","iopub.status.idle":"2023-01-09T13:39:37.302912Z","shell.execute_reply.started":"2023-01-09T13:39:36.669141Z","shell.execute_reply":"2023-01-09T13:39:37.302018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 15))\nplt.imshow(image1[:,:,0:4])\nplt.title(\"Wavelet details fake color image\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:40:27.241354Z","iopub.execute_input":"2023-01-09T13:40:27.241738Z","iopub.status.idle":"2023-01-09T13:40:27.933652Z","shell.execute_reply.started":"2023-01-09T13:40:27.241699Z","shell.execute_reply":"2023-01-09T13:40:27.932597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1_details=tf.stack([q,r,t],axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:37.997231Z","iopub.execute_input":"2023-01-09T13:39:37.997574Z","iopub.status.idle":"2023-01-09T13:39:38.00629Z","shell.execute_reply.started":"2023-01-09T13:39:37.997545Z","shell.execute_reply":"2023-01-09T13:39:38.00522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image1=t1_details.numpy()[0]\nimage1.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:38.008262Z","iopub.execute_input":"2023-01-09T13:39:38.008588Z","iopub.status.idle":"2023-01-09T13:39:38.02266Z","shell.execute_reply.started":"2023-01-09T13:39:38.008559Z","shell.execute_reply":"2023-01-09T13:39:38.021302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nplt.imshow(image1[:,:,:])\nplt.title(\"Wavelet details fake color image\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:38.024277Z","iopub.execute_input":"2023-01-09T13:39:38.024614Z","iopub.status.idle":"2023-01-09T13:39:38.496124Z","shell.execute_reply.started":"2023-01-09T13:39:38.024574Z","shell.execute_reply":"2023-01-09T13:39:38.495223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nplt.imshow(image1[:,:,0])\nplt.title(\"Wavelet details fake color image\")","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:39:38.497372Z","iopub.execute_input":"2023-01-09T13:39:38.497853Z","iopub.status.idle":"2023-01-09T13:39:38.898894Z","shell.execute_reply.started":"2023-01-09T13:39:38.497821Z","shell.execute_reply":"2023-01-09T13:39:38.898087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t1_details=tf.stack([p,q,r,t],axis=3)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:44:23.678381Z","iopub.execute_input":"2023-01-09T13:44:23.678775Z","iopub.status.idle":"2023-01-09T13:44:23.68892Z","shell.execute_reply.started":"2023-01-09T13:44:23.678746Z","shell.execute_reply":"2023-01-09T13:44:23.687866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trx = w_i.call(t1_details)\nimage2=trx.numpy()[0,:,:,0]\nimage2.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:45:03.079156Z","iopub.execute_input":"2023-01-09T13:45:03.079543Z","iopub.status.idle":"2023-01-09T13:45:03.171985Z","shell.execute_reply.started":"2023-01-09T13:45:03.079511Z","shell.execute_reply":"2023-01-09T13:45:03.170825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nplt.imshow(image2)\nplt.title(\"Reconstructed gray image\")\nplt.savefig('1024reconstructedimage.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-01-09T13:48:03.790591Z","iopub.execute_input":"2023-01-09T13:48:03.790975Z","iopub.status.idle":"2023-01-09T13:48:04.392504Z","shell.execute_reply.started":"2023-01-09T13:48:03.790945Z","shell.execute_reply":"2023-01-09T13:48:04.391571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Gray-Level Co-occurrence Matrix (GLCM)\n\n","metadata":{}},{"cell_type":"markdown","source":"#### Scientific reasearch pair `review\n\nThe authors of article heve proposed a method that was evaluated with data presented in article in cross-validation and performed highly in the prediction of the benign/malignant ROIs, with a mean AUC value of 97.39±0.01%.\n\nEnsemble DiscreteWavelet Transform and Gray-Level\nCo-Occurrence Matrix for Microcalcification Cluster\nClassification in Digital Mammography\n\n> by Annarita Fanizzi 1,†ORCID, Teresa Maria Basile 2, Liliana Losurdo 1,†ORCID, Roberto Bellotti 2,3, Ubaldo Bottigli 4, Francesco Campobasso 5ORCID, Vittorio Didonna 1, Alfonso Fausto 6ORCID, Raffaella Massafra 1, Alberto Tagliafico 7, Pasquale Tamborra 1, Sabina Tangaro 3,*ORCID, Vito Lorusso 1 and Daniele La Forgia 1ORCID\n\n> I.R.C.C.S. Istituto Tumori “Giovanni Paolo II”, 70124 Bari, Italy\n\n> Dip. Interateneo di Fisica “M. Merlin”, Università degli Studi di Bari, 70125 Bari, Italy\n\n> INFN—Istituto Nazionale di Fisica Nucleare, Sezione di Bari, 70126 Bari, Italy\n\n> Dip. di Scienze Fisiche, della Terra e dell’Ambiente, Università degli Studi di Siena, 53100 Siena, Italy\n\n> Dip. di Economia e finanza, Università degli Studi di Bari, 70124 Bari, Italy\n\n> Dip. di Diagnostica per Immagini, Azienda Ospedaliera Universitaria Senese, 53100 Siena, Italy\n\n> Dip. di Scienze della Salute, Università degli Studi di Genova, 16132 Genova, Italy\n\n> Author to whom correspondence should be addressed.\n\n> These authors contributed equally to this work.\n\nThe proposed method was evaluated in cross-validation and performed highly in the prediction of the benign/malignant ROIs, with a mean AUC value of 97.39±0.01%.","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}