-
Notifications
You must be signed in to change notification settings - Fork 39
/
adaptiveThresh.m
42 lines (32 loc) · 1.32 KB
/
adaptiveThresh.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function imBW = adaptiveThresh(im, sigma)
%% Adaptive threshold an image using Gaussian filter with a given stdv.
%% License
% ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY
% Copyright (c) 2018 Bingyao Huang
% All rights reserved.
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
% If you publish results obtained using this software, please cite our paper.
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.
%%
if(nargin < 2)
sigma = 0.5;
end
imSize = size(im);
% convert to gray scale image
if(numel(imSize)>2 && imSize(3) == 3)
imGray = rgb2gray(im);
else
imGray = im;
end
imGaussianMean = imgaussfilt(imGray, sigma);
imBW = imGray > imGaussianMean;
end