-
Notifications
You must be signed in to change notification settings - Fork 5
/
inforgbedge.m
119 lines (104 loc) · 4.14 KB
/
inforgbedge.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
%% INFORGBEDGE - Visualization of edge magnitude and orientation of color images.
%
%% Description
% Provide edge magnitude and orientation of multispectral images based on
% their derivatives, using multichannel approach (gradient structure
% tensor), and reduced (RGB or LAB) approach (gradient). Used for simple
% visual comparison of both approaches.
%
%% Syntax
% [E, M, O, rE, rM, rO] = INFORGBEDGE(I, 'disp', true);
% [E, M, O, rE, rM, rO] = INFORGBEDGE(I, reduce, rho, sig, der, int);
%
%% Inputs
% *|I|* : an input image with size |(X,Y,C)|, where |C=3| when |I| is multichannel.
%
% *|reduce|* : optional string setting the method used for reducing the input
% image into a scalar (graylevel) one; it is either |'rgb'| for calling
% |RGB2GRAY| or |'lab'| for calling |RGB2LAB|; default: |reduce='rgb'|.
%
% *|rho|* : optional integration scale (see |GTSMOOTH|); default: |rho=0|,
% ie. in order to compare both multichannel and reduced approaches, we
% skip in principle the spatial averaging of the tensor.
%
% *|sig|* : optional differentiation scale (see |GTSMOOTH|); default: |sig=1|,
% i.e. Gaussian regularisation is used for estimating the derivatives.
%
% *|der|* : optional string for pre-smoothing/differentiation (see |GRDSMOOTH|):
% |'matlab'|, |'vista'|, |'fast'|, |'conv'|, |'fleck'|, |'tap5'|, |'tap7'|,
% |'sob'|, |'opt'| or |'ana'|; default: |der='matlab'|.
%
% *|int|* : optional string for post-smoothing (see |GRD2GST|): |'matlab'|,
% |'conv'| or |'fast'|; default: |int='fast'|.
%
%% Outputs
% *|E, rE|* : edge maps obtained through multichannel and reduced approaches.
%
% *|M, O|* : magnitude and orientation using the multichannel approach.
%
% *|rM, rO|* : ibid reducing the image first.
%
% Displays the overlapped gradient magnitudes and edge maps of a color
% image using both multispectral and reduced approaches.
%
%% See also
% Related:
% <EDGECORNER.html |EDGECORNER|>,
% <KOETHEDGE.html |KOETHEDGE|>,
% <CANNYEDGE.html |CANNYEDGE|>.
% Called:
% <INFORGBEDGE_BASE.html |INFORGBEDGE_BASE|>.
%% Function implementation
function [E, M, O, rE, rM, rO] = inforgbedge(I, varargin)
%%
% parsing parameters
error(nargchk(1, 19, nargin, 'struct'));
error(nargoutchk(0, 4, nargout, 'struct'));
% mandatory parameter
if ~isnumeric(I)
error('gstsmooth:inputerror','a matrix is required in input');
end
% optional parameters
p = createParser('GSTSMOOTH');
% principal optional parameters
p.addOptional('reduce', 'rgb', @(x)ischar(x) && any(strcmpi(x,{'rgb','lab'})));
p.addOptional('rho', 0, @(x)isscalar(x) && isfloat(x) && x>=0);
p.addOptional('sigma', 1, @(x)isscalar(x) && isfloat(x) && x>=0);
p.addOptional('der', 'matlab', @(x)islogical(x) || (ischar(x) && ...
any(strcmpi(x,{'matlab','vista','fast','conv','fleck', ...
'tap5','tap7','sob','opt','ana'}))));
p.addOptional('int', 'fast', @(x)islogical(x) || (ischar(x) && ...
any(strcmpi(x,{'matlab','conv','fast'})))); % 'ani' not allowed here
% parse and validate all input arguments
p.parse(varargin{:});
p = getvarParser(p);
%%
% checking/setting variables
if size(I,3)~=3
error('inforgbedge:inputerror', 'matrix (m x n x 3) required in input');
end
I = rescale(I,0,1);
if strcmpi(p.reduce,'rgb')
R = rgb2gray(I);
elseif strcmpi(p.reduce,'lab')
C = makecform('srgb2lab');
R = applycform(I,C);
R = R(:,:,1);
% R = rgb2lab(I);
end
%%
% main calculations
[E, M, O, rE, rM, rO] = inforgbedge_base(I, R, p.rho, p.sigma, p.der, p.int);
%%
% display
if p.disp
% figure, colormap gray
% subplot(1,2,1), imagesc(mag), axis image off, title('multichannel')
% subplot(1,2,2), imagesc(rmag), axis image off, title('reduced')
figure,
subplot(1,2,1), imagesc(rescale(cat(3, M, rM, rM),0,1))
title('magnitude: R multichannel - GB reduced'), axis image off
subplot(1,2,2), imagesc(rescale(cat(3, E, rE, rE),0,1))
title('edge map: R multichannel - GB reduced'), axis image off
end
end % end of inforgbedge