Computer Vision Feature Extraction 101 on Medical Images — Part 3: Difference of Gaussian, and Laplacian of Gaussian
This is another post of me trying to remember what I learned in Computer Vision. And since it is Final Exam season I don’t really want to do something crazy, hence DoG and LoG filters.
Click here if you wish to see part 1, or click here if you wish to see part 2.
Also, here is the list of publicly available data that we are going to use.
1. Breast Cancer Cell from UCSB Bio-Segmentation Benchmark data set
2. Cellular 2D from UCSB Bio-Segmentation Benchmark data set
3. DRIVE: Digital Retinal Images for Vessel Extraction
4. Ultrasound Nerve Segmentation from kaggle Data set
5. Brain MRI from pixabay
6. Brain MRI from pixabay
7. Natural Image from pixabay
Please note that this post is for my future self to look back and review the materials.
2D Convolution
“convolution is a mathematical operation on two functions (f and g) to produce a third function, that is typically viewed as a modified version of one of the original functions, giving the integral of the pointwise multiplication of the two functions as a function of the amount that one of the original functions is translated” — Wiki Page
2D convolution operation is in the heart of computer vision, and since this is the main operation that we are going to use for this post, please make sure you understand the concept. If you need help please click here to check out a step by step example of 2D Convolution operation by Song Ho Ahn.
Original Images
Top Left → Breast Cancer Cell from UCSB Bio-Segmentation Benchmark
Top Middle → Cellular 2D from UCSB Bio-Segmentation Benchmark data set
Top Right → DRIVE: Digital Retinal Images for Vessel Extraction
Bottom Left → Ultrasound Nerve Segmentation from kaggle Data set
Bottom Middle → Brain MRI from pixabay
Bottom Right → Brain MRI from pixabay
Before we do anything to these images, lets actually take a look at what each image looks like, finally below is how our natural image looks like.
Difference of Gaussian
Red Box → Convolution Operation with the original image with Gaussian 1
Green Box → Convolution Operation with the original image with Gaussian 2
Blue Box → Subtracting the images resulted in above two section, and setting a threshold value.
** Please note ** we actually need to find the zero-crossings rather than setting a hard threshold value. But for simplicity I have uses a threshold value.
Despite of its name, Difference of Gaussian is super simple. Just convolve the image with different Gaussian kernels, in the above case we choose to use two different Gaussian filters with different window sizes. Than subtract one from another, and have a threshold to filter out the pixels with weaker intensity.
Red Box → Convolution Operation with the original image with Gaussian 1
Green Box → Convolution Operation with the original image with Gaussian 2
Blue Box → Subtracting the images resulted in above two section
Except for the threshold, above image does an excellent job explaining the step by step tutorial.
Difference of Gaussian v2
Red Box → Choosing a Gaussian Kernel with sigma value of 100
Green Box → Choosing a Gaussian Kernel with sigma value of 1
As seen above, choosing radically different sigma values for Gaussian kernels gives ghostly results. ( I just wanted to try these out for fun. )
Laplacian of Gaussian (With Smoothing)
Red Box → Smoothing the Image using Gaussian Filter
Green Box → Creating the Laplacian Filter for convolution operation.
“ The Laplacian of an image highlights regions of rapid intensity change and is therefore often used for edge detection (see zero crossing edge detectors). The Laplacian is often applied to an image that has first been smoothed with something approximating a Gaussian smoothing filter in order to reduce its sensitivity to noise.” — Quote from this website
From the statement above, we can already tell that we need to first smooth the image before doing anything. Lets just assume that we already have smoothen the image and see what should we do next.
So now we know that we just need to perform convolution using one of those kernels, I will use the left one.
Laplacian of Gaussian (Without Smoothing)
Now I heard that Laplacian of Gaussian is sensitive to noise and we smoothen the image before doing anything. For fun, lets just apply the Laplacian filter without smoothing the image. The images looks sharper to me, but it does seem to have strange artifacts here and there.
Interactive Code
For Google Colab, 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!
Please note, I didn’t wanted to abuse any data policy. So for Google Colab I found the below image, which is labeled for reuse. To access the online code please click here.
Final Words
It’s mesmerizing to think that before deep learning, researchers were creating advanced features (such as HOG, SIFT) just from convolution and complex mathematical operations.
If any errors are found, please email me at jae.duk.seo@gmail.com, 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.
Reference
- scipy, G. (2018). Gaussian filter in scipy. Stackoverflow.com. Retrieved 13 April 2018, from https://stackoverflow.com/questions/25216382/gaussian-filter-in-scipy
- Blob detection. (2018). En.wikipedia.org. Retrieved 13 April 2018, from https://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian
- Bio-Segmentation | Center for Bio-Image Informatics | UC Santa Barbara. (2018). Bioimage.ucsb.edu. Retrieved 9 April 2018, from https://bioimage.ucsb.edu/research/bio-segmentation
- DRIVE: Download. (2018). Isi.uu.nl. Retrieved 9 April 2018, from http://www.isi.uu.nl/Research/Databases/DRIVE/download.php
- Ultrasound Nerve Segmentation | Kaggle. (2018). Kaggle.com. Retrieved 9 April 2018, from https://www.kaggle.com/c/ultrasound-nerve-segmentation
- Free Image on Pixabay — Mri, Magnetic, X Ray, Skull, Head. (2018). Pixabay.com. Retrieved 9 April 2018, from https://pixabay.com/en/mri-magnetic-x-ray-skull-head-782457/
- Free Image on Pixabay — Sunset, Lighthouse, Dawn, Dusk, Sun. (2018). Pixabay.com. Retrieved 9 April 2018, from https://pixabay.com/en/sunset-lighthouse-dawn-dusk-sun-3120484/
- Free Image on Pixabay — Mri, Magnetic, X Ray, Skull, Head. (2018). Pixabay.com. Retrieved 9 April 2018, from https://pixabay.com/en/mri-magnetic-x-ray-skull-head-782459/
- Spatial Filters — Laplacian/Laplacian of Gaussian. (2018). Homepages.inf.ed.ac.uk. Retrieved 13 April 2018, from https://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm
- (2018). Cse.psu.edu. Retrieved 13 April 2018, from http://www.cse.psu.edu/~rtc12/CSE486/lecture11_6pp.pdf
- Ahn, S. (2018). Example of 2D Convolution. Songho.ca. Retrieved 13 April 2018, from http://www.songho.ca/dsp/convolution/convolution2d_example.html