-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspecxture.m
73 lines (63 loc) · 2.57 KB
/
specxture.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
function [srad, sang, S] = specxture(f);
%SPECXTURE Computes spectral texture of an image.
% [SRAD, SANG, S] = SPECXTURE(F) computes SRAD, the spectral energy
% distribution as a function of radius from the center of the
% spectrum, SANG, the spectral energy distribution as a function of
% angle for 0 to 180 degrees in increments of 1 degree, and S =
% log(1 + spectrum of f), normalized to the range [0, 1]. The
% maximum value of radius is min(M,N), where M and N are the number
% of rows and columns of image (region) f. Thus, SRAD is a row
% vector of length = (min(M, N)/2) - 1; and SANG is a row vector of
% length 180.
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.7 $ $Date: 2003/11/21 14:48:47 $
% Obtain the centered spectrum, S, of f. The variables of S are
% (u, v), running from 1:M and 1:N, with the center (zero frequency)
% at [M/2 + 1, N/2 + 1] (see Chapter 4).
S = fftshift(fft2(f));
S = abs(S);
[M, N] = size(S);
x0 = M/2 + 1;
y0 = N/2 + 1;
% Maximum radius that guarantees a circle centered at (x0, y0) that
% does not exceed the boundaries of S.
rmax = min(M, N)/2 - 1;
% Compute srad.
srad = zeros(1, rmax);
srad(1) = S(x0, y0);
for r = 2:rmax
[xc, yc] = halfcircle(r, x0, y0);
srad(r) = sum(S(sub2ind(size(S), xc, yc)));
end
% Compute sang.
[xc, yc] = halfcircle(rmax, x0, y0);
sang = zeros(1, length(xc));
for a = 1:length(xc)
[xr, yr] = radial(x0, y0, xc(a), yc(a));
sang(a) = sum(S(sub2ind(size(S), xr, yr)));
end
% Output the log of the spectrum for easier viewing, scaled to the
% range [0, 1].
S = mat2gray(log(1 + S));
%-------------------------------------------------------------------%
function [xc, yc] = halfcircle(r, x0, y0)
% Computes the integer coordinates of a half circle of radius r and
% center at (x0,y0) using one degree increments.
%
% Goes from 91 to 270 because we want the half circle to be in the
% region defined by top right and top left quadrants, in the
% standard image coordinates.
theta=91:270;
theta = theta*pi/180;
[xc, yc] = pol2cart(theta, r);
xc = round(xc)' + x0; % Column vector.
yc = round(yc)' + y0;
%-------------------------------------------------------------------%
function [xr, yr] = radial(x0, y0, x, y);
% Computes the coordinates of a straight line segment extending
% from (x0, y0) to (x, y).
%
% Based on function intline.m. xr and yr are returned as column
% vectors.
[xr, yr] = intline(x0, x, y0, y);