adaptivethresholdcv

Applies adaptive threshold to the image, handle.

Syntax

R = adaptivethresholdcv(handle, max, method, type, blocksize, cvalue)

Inputs

handle
Handle of a single channel (grayscale) image or a 2D, real matrix.
Type: integer | mat
max
Non-zero max value applied to the affected pixels of handle.
Type: scalar
method
Adaptive threshold method. Valid values are:
0
Type cv::ADAPTIVE_THRESH_MEAN_C.
1
Type cv::ADAPTIVE_THRESH_GAUSSIAN_C
Type: integer
type
Threshold type. Valid values are:
0
Type cv::THRESH_BINARY.
1
Type cv::THRESH_BINARY_INV
Type: integer
blocksize
Size of pixel neighborhood.
Type: integer
cvalue
Constant subtracted from mean or weighted mean.
Type: scalar

Outputs

R
Handle of the output image.
Type: integer

Example

Apply adaptive threshold to the given image:
src = imreadcv('bird1.jpg', 0);
m = 100;
method = 1;
ttype = 0;
blocksize = 3;
constantval = 5;
R = adaptivethresholdcv(src, m, method, ttype, blocksize, constantval);
Figure 1. Input image


Figure 2. Output image


Apply adaptive threshold to remove the shadow on a book page:
imgoriginal = imreadcv('adaptivethresholdcv_fig3.png',1);
figure(1);
imshowcv(imgoriginal);

%Conver the image to gray scale
img = cvtcolorcv(imgoriginal, 6);
   
%Apply thresholding technique
thresh = adaptivethresholdcv(img, 255, 0,0, 199, 5)

figure(2);
imshowcv(thresh);
Figure 3. Input image


Figure 4. Output image