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 librariesimport mahotasimport numpy as npfrom pylab import imshow, showimport os# loading nuclear imagef1 = mahotas.demos.load('nuclear')# setting filter to the imagef1 = f1[:, :, 0]# setting gaussian filterf1 = mahotas.gaussian_filter(f1, 4)# setting threshold valuef1 = (f1> f1.mean())# creating a labeled imagelabeled1, n_nucleus1 = mahotas.label(f1)# showing the labeled imageprint("Labelled 1 Image")imshow(labeled1)show()# loading nuclear imagef2 = mahotas.demos.load('nuclear')# setting filter to the imagef2 = f2[:, :, 0]# setting gaussian filterf2 = mahotas.gaussian_filter(f2, 4)# setting threshold valuef2 = (f2> f2.mean())# creating a labeled imagelabeled2, n_nucleus2 = mahotas.label(f2)# showing the labeled imageprint("Labelled 2 Image")imshow(labeled2)show()# checking if both the labeled images are samecheck = mahotas.labeled.is_same_labeling(labeled1, labeled2)# printing checkprint("Same Labelling : "+ str(check)) |
Output :
Same Labelling : True
Example 2 :
Python3
# importing required librariesimport mahotasimport numpy as npfrom pylab import imshow, showimport os# loading nuclear imagef1 = mahotas.demos.load('nuclear')# setting filter to the imagef1 = f1[:, :, 0]# setting gaussian filterf1 = mahotas.gaussian_filter(f1, 4)# setting threshold valuef1 = (f1> f1.mean())# creating a labeled imagelabeled1, n_nucleus1 = mahotas.label(f1)# showing the labeled imageprint("Labelled 1 Image")imshow(labeled1)show()# loading nuclear imagef2 = mahotas.demos.load('nuclear')# setting filter to the imagef2 = f2[:, :, 0]# setting gaussian filterf2 = mahotas.gaussian_filter(f2, 4)# setting threshold valuef2 = (f2> f2.mean())# creating a labeled imagelabeled2, n_nucleus2 = mahotas.label(f2)# removing borderlabeled2 = mahotas.labeled.remove_bordering(labeled2)# showing the labeled imageprint("Labelled 2 Image")imshow(labeled2)show()# checking if both the labeled images are samecheck = mahotas.labeled.is_same_labeling(labeled1, labeled2)# printing checkprint("Same Labelling : "+ str(check)) |
Output :
Same Labelling : False




