-
Notifications
You must be signed in to change notification settings - Fork 10
/
cvRoberts.m
80 lines (76 loc) · 2.22 KB
/
cvRoberts.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function O = cvRoberts(I, thresh, direction)
% cvRoberts - Roberts Edge Detection
%
% Synopsis
% O = cvRoberts(I, [thresh], [direction])
%
% Description
% Roberts Edge Detection
%
% Inputs ([]s are optional)
% (matrix) I N x M x C matrix representing the input image
% (scalar) [thresh = []]
% The sensitivity threshold. Ignores all edges
% that are not stronger than thresh.
% If empty([]) is given, no thresholding.
% Can be a 1 x C vector for a color image.
% (string) [direction = '45']
% '45' or '135'. Default is '45'.
%
% Outputs ([]s are optional)
% (matrix) O N x M x C matrix representing the output.
%
% Examples
% I = cvuImgread('image/lena.png');
% O = cvRoberts(I, 32, '45');
% figure; imshow(I);
% figure; imshow(O);
% O = cvRoberts(I, [], '45');
% figure; imshow(uint8(cvuNormalize(O, [0, 255])));
%
% See also
% edge (edge.m does thining lines too)
%
% Requirements
% cvConv2 (requires conv2)
% Authors
% Naotoshi Seo <sonots(at)sonots.com>
%
% License
% The program is free to use for non-commercial academic purposes,
% but for course works, you must understand what is going inside to use.
% The program can be used, modified, or re-distributed for any purposes
% if you or one of your group understand codes (the one must come to
% court if court cases occur.) Please contact the authors if you are
% interested in using the program without meeting the above conditions.
%
% Changes
% 02/01/2007 First Edition
if ~exist('direction', 'var') || isempty(direction)
direction = '45';
end
if ~exist('thresh', 'var') || isempty(thresh)
thresh = [];
end
if ~isa(I, 'double')
I = double(I);
end
if strcmp(direction, '45')
mask = [-1 0;
0 1];
elseif strcmp(direction, '135')
mask = [0 -1
1 0];
end
[N, M, C] = size(I);
O = zeros(N, M, C);
for c = 1:C
O(:,:,c) = cvConv2(I(:,:,c), mask, 'reflect');
end
if ~isempty(thresh)
if isscalar(thresh), thresh = repmat(thresh, 1, C); end;
for c = 1:C
O(:,:,c) = (abs(O(:,:,c)) > thresh(c));
end
end
end