Skip to content
Related Articles

Related Articles

Improve Article

Mahotas – Edges using Difference of Gaussian for binary image

  • Last Updated : 10 Jul, 2020

In this article we will see how we can edges of the binary image in mahotas with the help of DoG algorithm. In imaging science, difference of Gaussians (DoG) is a feature enhancement algorithm that involves the subtraction of one blurred version of an original image from another, less blurred version of the original.

In order to do this we will use mahotas.dog method

Syntax : mahotas.dog(img)

Argument : It takes binary image object as argument

Return : It returns image object



Below is the implementation




# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
    
# creating region
# numpy.ndarray
regions = np.zeros((10, 10), bool)
    
# setting 1 value to the region
regions[:3, :3] = 1
regions[6:, 6:] = 1
    
# getting labeled function
labeled, nr_objects = mh.label(regions)
    
# showing the image with interpolation = 'nearest'
print("Binary Image")
imshow(labeled, interpolation ='nearest')
show()
   
# getting edges using dog algo
dog = mahotas.dog(labeled)
   
# showing image
print("Edges using DoG algo")
imshow(dog)
show()

Output :

Binary Image

Edges using DoG algo

Another example




# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
    
# creating region
# numpy.ndarray
regions = np.zeros((10, 10), bool)
    
# setting 1 value to the region
regions[1, :2] = 1
regions[5:8, 6: 8] = 1
regions[8, 0] = 1
    
# getting labeled function
labeled, nr_objects = mh.label(regions)
    
# showing the image with interpolation = 'nearest'
print("Image")
imshow(labeled, interpolation ='nearest')
show()
   
# getting edges
dog = mahotas.dog(labeled)
   
# showing image
print("Edges using DoG algo")
imshow(dog)
show()

Output :

Binary Image

Edges using DoG algo

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :