Mahotas – Removing Region at given position
Last Updated :
21 Apr, 2021
In this article we will see how we can remove the region at given position in mahotas. Labelled images are integer images where the values correspond to different regions. I.e., region 1 is all of the pixels which have value 1, region two is the pixels with value 2, and so on. By convention, region 0 is the background and often handled differently. We can create a labelled region with the help of mahotas.label method.
In order to do this we will use mahotas.labelled.remove_regions method
Syntax : mahotas.labelled.remove_regions(labeled_img, i, j)
Argument : It takes labelled image and two integer representing the region
Return : It returns numpy.ndarray i.e image object
Example 1:
Python3
import mahotas
import numpy as np
from pylab import imshow, show
import os
img = mahotas.imread( 'dog_image.png' )
img = img[:, :, 0 ]
img = mahotas.gaussian_filter(img, 15 )
img = (img> img.mean())
labeled1, n_nucleus1 = mahotas.label(img)
print ( "Labelled Image" )
imshow(labelled1)
show()
labelled2 = mahotas.labelled.remove_regions(labelled1, 1 , 1 )
print ( "Labelled Image with removed region" )
imshow(labelled2)
show()
|
Output :
Example 2:
Python3
import mahotas
import numpy as np
from pylab import imshow, show
regions = np.zeros(( 10 , 10 ), bool )
regions[: 3 , : 3 ] = 1
regions[ 6 :, 6 :] = 1
labelled, nr_objects = mahotas.label(regions)
print ( "Labelled Image" )
imshow(labelled, interpolation = 'nearest' )
show()
labelled2 = mahotas.labelled.remove_regions(labelled, 1 , 1 )
print ( "Labelled Image with removed region" )
imshow(labelled2)
show()
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...