Analytics Vidhya
Published in

Analytics Vidhya

Traditional Image semantic segmentation for Core Samples

This my first time to write a blog in my life, so we gonna talk today about how can you segment image using the traditional ways.

In this blog we gonna use a core sample as an example, if you don’t know what core sample is, it’s a cylindrical shape sample taken from an oil well or mining area, and we use it to see how is the geology down there doing.

core sample with 2 different textures, before segmentation

so our mission here is to try to write a code which can differentiate between the dark texture in the core sample and the brighter part, this might help a geologist by saving him some time and introducing some automation to his work.

The first step:

we need to find an algorithm that can find a difference between the 2 different textures up there, if you searched over semantic segmentation using traditional ways, you gonna find a lot of ready made filters on libraries like Skimage, Scipy, and OpenCV. In our case we gonna use Skimage because I like it .

so in Skimage we can find a lot filters to do this task, but the only one that would give us a good end result, which is entropy segmentation filter.

first we need to import the essential libraries for this mission

importing libraries

we need to import Matplotlib to show our final results, Skimage for the entropy segmentation and Thresholding(2nd step), and Numpy just to complete our importing cocktail.

To open our image in python first, we gonna do this using the following line of code

How can you import an image in python

now let’s talk a little about the Entropy filter, the entropy filter can detect subtle variations in the local gray level distribution, the next picture will show you how it works

courtesy of:

to apply this filter over our core sample image, we gonna use just the following line of code.

Applying the entropy filter over the core sample,using a radius of 8

and to show the the result of this filter we gonna use Matplotlib to plot these new values, using the coming line of code.

showing a plot using matplotlib

and here we can see the result of the entropy segmentation over our core sample.

the result of entropy segmentation filter over our core sample

now we can see that entropy filter resulted yellowish green color for the darker texture in the original picture and normal green to the other texture, but from this result we can’t precisely differentiate between both textures, we need a boarder line between the darker and brighter textures, to do so we gonna use the Otsu Threshold filter, which gonna result the value which estimate the boarder line between the darker texture pixel values and the other texture pixel values, we can do so using the following line of code.

threshold value between the 2 textures

using the previous code we made a line between 2 textures, we just need to put this line in action, that’s why we gonna make a boolean mask using this threshold,using the following line of code.

Binary is an image consists of true and false values

the previous line of code constructed an image, consists of true and false value or zeros and ones, the true values are for the pixel values which are less than or equal the threshold and the false values are for the rest of the pixels

the Binary image, yellow=1 , purple = 0

now we have only 2 different textures in the output image, and we can calculate the area ratio between the 2 textures easily using the boolean mask.

to calculate the area ratio you need to use the following lines of code

boolean masking for each texture then plotting the ratio in a pie chart

and the final result gonna be this pie chart, which shows the yellow area to the purple area.

yellow and purple areas pie chart

This segmentation tutorial is inspired By Professor Jörg Benndorf and from DigitalSreeni YouTube channel




Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem

Recommended from Medium

How to design a good Load Test with Markov Chain (Part3)

The “I Miss You” Button

Best Practices For Designing REST APIs (Part 2)

DragonSB’s IDO on Terraformer Instruction

5 Components of Kubernetes You Need to Know

Microsoft Exam 70–483: Programming in C# — Objective 2.2: Consume types

Function to Sum two numbers with Python

UniLend’s Initium Alpha is Live! Ushering in a New Era of Inclusive DeFi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmed Emam

Ahmed Emam

Graduated from the European master program of Geomatics, Interested in Physics Informed Neural Networks (PINNs), and geophysical inversions.

More from Medium

Penguins from Head to Toe — How Penguins Can Help You Master Image Classification Process

Automatic Liver Segmentation — Part 4/4: Train and Test the Model

Convolutional Neural Network in TensorFlow

Using pre-trained Vision Transformer model and ResNet model as features extractors for image…