Computes threshold for binarization by using a edge or unsharp mask
thr = maskthresh(x)
thr = maskthresh(x,f)
A matrix representing a gray scale image.
A matrix representing a 2D edge or unsharm mask.
A scalar value representing a threshold value for binarizing the gray scale image.
It computes a threshold value automatically using an edge or unsharp mask. It takes two inputs, gray scale image x and a filter mask f. The image is filtered with the given mask. If the mask is not given, it uses a default mask. Threshold value is then computed by dividing the sum of the product of the filtered image and original image by the sum of the filtered image. The threshold value of a symmetric edge mask is less than threshold value of an unsharp mask.
x=imread('lena.png'); x=double(rgb2gray(x)); // gray scale image matrix // threshold estimation using edge mask f=[-2 1 -2; 1 4 1; -2 1 -2]; // edge mask e_thr=maskthresh(x,f); // computing threshold y=x>=e_thr; // binarization imshow(y) // displaying the binarized image y // threshold estimation using unsharp mask f=[-1 1 -1; 1 1 1; -1 1 -1]; // unsharp mask u_thr=maskthresh(x,f); // computing threshold y=x>=u_thr; // binarization imshow(y) // displaying the binarized image y // average threshold thr=(e_thresh + u_thresh)/2; imshow(x>=thr) // displaying binarized image at average threshold | ![]() | ![]() |