Only Numpy Medical: Denosing Lung CT Scans using Neural Networks with Interactive Code — Part 2…

Only Numpy Medical: Denosing Lung CT Scans using Neural Networks with Interactive Code — Part 2, Convolutional Neural Network (Low-dose CT denoising with convolutional neural network)

image from pixel bay

So today, I will continue on the image denoising series, and fortunately I found this paper “Low-dose CT denoising with convolutional neural network. In Biomedical Imagin” by Hu Chen. So lets take a dive into their implementation and see what results we get. Finally, for fun let’s use different type of back propagation to compare what gives us the best results. The different types of back propagation that we are going to use are….

a. Google Brain’s Gradient Noise
b. Dilated Back Propagation
c. Dilated Back Propagation + Google Brain’s Gradient Noise

If you are not aware of the difference between each of them please read the blog post that I have linked to.

Network Architecture (Mathematical Equation Form)

The first two layers of our convolutional NN
The final Layer of Convolutional NN

Now the paper is bit strangely written when it comes to notations sometimes they use X for Y and vice versa for the other wise. So in my best of abilities, I think we are building a Convolutional NN with three layers. The activation function for two layers are ReLU() activation function, and the final layer does not have any activation function.

Network Architecture (OOP Form)

The OOP form of the network is very straight forward, except for one part. we have 4 cases, remember that we are going to use different type of back propagation to see which gives us best results, well here they are.

Now one very important thing to note here is the fact that each of the networks DOES NOT start with the same weights! This may not be the most fair comparison. However I decided to do this to see how each back propagation method will perform in the long term effect. Meaning, if they are truly superior to another, no matter how the starting weights are initialized the network will perform better.

Training / Test Data

As seen above in the paper, the authors divided one image into separate image patches. Now we are not going to follow the exact same number of patches as presented in the paper, however we are going to divide our training and test image into patches. And one training image can be seen below.

First Row Image → Original Image and divided patches
Second Row Images → Added Noise Image and divided patches

So the original image have dimension of (512*512) and we are going to divide that image up to 4 patches. More specifically, each patch of image will have (256*256) dimension. So with that in mind, below are example of other training and test data examples. (Also, I forgot to take screen shot of the divided original image, so that is why you can’t seen them below.)

Cost Function / Back Propagation

Now lets take a look at the cost function that we are going to use. Since this equation set the value for us to optimize it is very important.

Now again, please keep in mind the notation for this paper is mixed up LOL. But I can safely say the cost function we are going to use is L2 Norm divided by the number of batch size, rather then 0.5. This can be achieved by the code below.

And since we have batch size of 4, (we divided the image into 4 different spaces) we are going to use 0.25. Also, there is one very important thing I wish to note here.

If we follow the strict rules of back propagation we should be actually multiplying 0.5 in the Red Box Region, however for stability I decided to make ONLY the first gradient more smaller. (This decision was made after a lot of different trial and errors.)

Case 1: Training and Results

Case 1 was normal stochastic gradient descent, as seen above, the overall shape of the CT Scan can be seen. However it is very hard to see. Right image is one of original image for comparison.

Case 2: Training and Results

For gradient noise, you can kinda? see something in the middle. However there is no way to tell that this was a Lung CT Scan image. Right image is one of original image for comparison.

Case 3: Training and Results

Now with Dilated Back Propagation, we can see that the resulted denoised images look very similar to the case 1 results. However, again very hard to tell exactly which is the lung part of the CT Scan. Right image is one of original image for comparison.

Case 4: Training and Results

Now we can clearly see what we are looking at. However it lacks details, and I mean A LOT of details. If you compare the GIF with the right image, you can barely make out the details. Right image is one of original image for comparison.

Interactive Code

I moved to Google Colab for Interactive codes! So you would need a google account to view the codes, also you can’t run read only scripts in Google Colab so make a copy on your play ground. Finally, I will never ask for permission to access your files on Google Drive, just FYI. Happy Coding!

Now running this code is bit complicated since I used my own data set. However don’t worry I uploaded all of the DICOMs that I used to my public Github (Gitlab was having troubles), to access it please follow this link. To access the main page of the repository please click here. Now please follow the step by step tutorial.

  1. Download the ‘’ file from the link above.

2. Copy the Code in Google Colab, into your own play ground. Upon running the code, a small button will pop up as seen above. (Green Box). Click Choose Files and choose the recently Downloaded ‘’ file.

3. The program will finish uploading the data into Google Colab and it will continue running.

So with the above short tutorial in mind, please click here to access the interactive code. Finally, please take note, the training process is very unstable so the results may vary every time.

Final Words

So we tried two different methods, Auto Encoders and now Convolutional Neural Networks. However, none of them gave us a result where a medical professional can use in real life setting. So the saga continues…….

If any errors are found, please email me at, if you wish to see the list of all of my writing please view my website here.

Meanwhile follow me on my twitter here, and visit my website, or my Youtube channel for more content. I also did comparison of Decoupled Neural Network here if you are interested.


  1. Patient CD/DVD DICOM Viewer. (n.d.). Retrieved February 16, 2018, from
  2. Scipy.ndimage.imread¶. (n.d.). Retrieved February 16, 2018, from
  3. Chen, H., Zhang, Y., Zhang, W., Liao, P., Li, K., Zhou, J., & Wang, G. (2017, April). Low-dose CT denoising with convolutional neural network. In Biomedical Imaging (ISBI 2017), 2017 IEEE 14th International Symposium on (pp. 143–146). IEEE.
  4. How to read text files in a zipped folder in Python. (n.d.). Retrieved February 16, 2018, from
  5. Seo, J. D. (2018, January 18). Only Numpy: Implementing “ADDING GRADIENT NOISE IMPROVES LEARNING FOR VERY DEEP NETWORKS” from… Retrieved February 17, 2018, from
  6. Seo, J. D. (2018, February 15). Only Numpy: Dilated Back Propagation and Google Brain’s Gradient Noise with Interactive Code. Retrieved February 17, 2018, from
  7. Seo, J. D. (2018, February 13). Only Numpy Medical: Denosing Lung CT Scans using Neural Networks with Interactive Code — Part 1… Retrieved February 17, 2018, from

Source: Deep Learning on Medium