Python Soft-Threshold using Mahotas














































Python Soft-Threshold using Mahotas



Description
In this article I will tell how we can implement soft threshold in mahotas. 
The soft thresholding is also called wavelet shrinkage, as values for both positive and negative coefficients are being %u201Cshrinked%u201D towards zero, in contradiction to hard thresholding which either keeps or removes values of coefficients.

Syntax : mahotas.thresholding.soft_threshold(image, t_value)
Argument : It takes image object and unit8 value as argument
Return : Returns image object 


CODE :
# importing requires modules
import mahotas
import numpy as np
from pylab import imread, gray, show, imshow

# loading image
photo = mahotas.imread('HarryPotter.jpg')

# showing the original image
print("Before Thresholding : ")
imshow(photo)
show()

t = np.uint8(200)

# setting filter to the image
img = photo[:, :, 0]

img = mahotas.thresholding.soft_threshold(img, t)

# showing image after thresholding
print("After Thresholding : ")
imshow(img)
show()

Output :




Comments