Saturday, November 22, 2025
HomeLanguagesMahotas – Edges using Difference of Gaussian for binary image

Mahotas – Edges using Difference of Gaussian for binary image

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS