Monday, October 6, 2025
HomeLanguagesMahotas – Checking if two images represent same labeling

Mahotas – Checking if two images represent same labeling

In this article, we will see how we can check if the two images represent the same labeling in mahotas. For this, we are going to use the fluorescent microscopy image from a nuclear segmentation benchmark. We can get the image with the help of command given below 

mahotas.demos.nuclear_image()

Below is the nuclear_image 

In order to do this we will use mahotas.labeled.is_same_labeling method  

Syntax : mahotas.labeled.is_same_labeling(label1. labeled2)
Argument : It takes two labelled image as argument
Return : It returns bool 
 

Note: The input of this should be the filtered image object which is labeled 

In order to filter the image we will take the image object which is numpy.ndarray and filter it with the help of indexing, below is the command to do this  

image = image[:, :, 0]

Example 1 : 

Python3




# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
# loading nuclear image
f1 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f1 = f1[:, :, 0]
 
 
# setting gaussian filter
f1 = mahotas.gaussian_filter(f1, 4)
 
# setting threshold value
f1 = (f1> f1.mean())
 
# creating a labeled image
labeled1, n_nucleus1 = mahotas.label(f1)
 
# showing the labeled image
print("Labelled 1 Image")
imshow(labeled1)
show()
 
# loading nuclear image
f2 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f2 = f2[:, :, 0]
 
# setting gaussian filter
f2 = mahotas.gaussian_filter(f2, 4)
 
# setting threshold value
f2 = (f2> f2.mean())
 
# creating a labeled image
labeled2, n_nucleus2 = mahotas.label(f2)
 
 
# showing the labeled image
print("Labelled 2 Image")
imshow(labeled2)
show()
 
# checking if both the labeled images are same
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
 
# printing check
print("Same Labelling : "+ str(check))


Output : 

Same Labelling : True

Example 2 :  

Python3




# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
 
# loading nuclear image
f1 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f1 = f1[:, :, 0]
 
 
# setting gaussian filter
f1 = mahotas.gaussian_filter(f1, 4)
 
# setting threshold value
f1 = (f1> f1.mean())
 
# creating a labeled image
labeled1, n_nucleus1 = mahotas.label(f1)
 
# showing the labeled image
print("Labelled 1 Image")
imshow(labeled1)
show()
 
# loading nuclear image
f2 = mahotas.demos.load('nuclear')
 
# setting filter to the image
f2 = f2[:, :, 0]
 
# setting gaussian filter
f2 = mahotas.gaussian_filter(f2, 4)
 
# setting threshold value
f2 = (f2> f2.mean())
 
# creating a labeled image
labeled2, n_nucleus2 = mahotas.label(f2)
 
# removing border
labeled2 = mahotas.labeled.remove_bordering(labeled2)
 
 
# showing the labeled image
print("Labelled 2 Image")
imshow(labeled2)
show()
 
# checking if both the labeled images are same
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
 
# printing check
print("Same Labelling : "+ str(check))


Output : 

Same Labelling : False

 

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

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6782 POSTS0 COMMENTS