Mahotas – Checking if two images represent same labeling
Last Updated :
15 Sep, 2022
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
import mahotas
import numpy as np
from pylab import imshow, show
import os
f1 = mahotas.demos.load( 'nuclear' )
f1 = f1[:, :, 0 ]
f1 = mahotas.gaussian_filter(f1, 4 )
f1 = (f1> f1.mean())
labeled1, n_nucleus1 = mahotas.label(f1)
print ( "Labelled 1 Image" )
imshow(labeled1)
show()
f2 = mahotas.demos.load( 'nuclear' )
f2 = f2[:, :, 0 ]
f2 = mahotas.gaussian_filter(f2, 4 )
f2 = (f2> f2.mean())
labeled2, n_nucleus2 = mahotas.label(f2)
print ( "Labelled 2 Image" )
imshow(labeled2)
show()
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
print ( "Same Labelling : " + str (check))
|
Output :
Same Labelling : True
Example 2 :
Python3
import mahotas
import numpy as np
from pylab import imshow, show
import os
f1 = mahotas.demos.load( 'nuclear' )
f1 = f1[:, :, 0 ]
f1 = mahotas.gaussian_filter(f1, 4 )
f1 = (f1> f1.mean())
labeled1, n_nucleus1 = mahotas.label(f1)
print ( "Labelled 1 Image" )
imshow(labeled1)
show()
f2 = mahotas.demos.load( 'nuclear' )
f2 = f2[:, :, 0 ]
f2 = mahotas.gaussian_filter(f2, 4 )
f2 = (f2> f2.mean())
labeled2, n_nucleus2 = mahotas.label(f2)
labeled2 = mahotas.labeled.remove_bordering(labeled2)
print ( "Labelled 2 Image" )
imshow(labeled2)
show()
check = mahotas.labeled.is_same_labeling(labeled1, labeled2)
print ( "Same Labelling : " + str (check))
|
Output :
Same Labelling : False
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...