1 | % DISPFEAT - Displays feature types as detected by PHASECONG. |
---|
2 | % |
---|
3 | % This function provides a visualisation of the feature types as detected |
---|
4 | % by PHASECONG. |
---|
5 | % |
---|
6 | % Usage: im = dispfeat(ft, edgeim, 'l') |
---|
7 | % |
---|
8 | % Arguments: ft - A complex valued image giving the weighted mean |
---|
9 | % phase angle at every point in the image for the |
---|
10 | % orientation having maximum energy. |
---|
11 | % edgeim - A binary edge image (typically obtained via |
---|
12 | % non-maxima suppression and thresholding). |
---|
13 | % This is used as a `mask' to specify which bits of |
---|
14 | % the phase data should be displayed. |
---|
15 | % Alternatively you can supply a phase congruency |
---|
16 | % image in which case it is used to control the |
---|
17 | % saturation of the colour coding |
---|
18 | % l - An optional parameter indicating that a line plot |
---|
19 | % encoded by line style should also be produced. If |
---|
20 | % this is the case then `edgeim' really should be an |
---|
21 | % edge image. |
---|
22 | % |
---|
23 | % Returns: im - An edge image with edges colour coded according to |
---|
24 | % feature type. |
---|
25 | % |
---|
26 | % Two or three plots are generated: |
---|
27 | % 1. An edge image with edges colour coded according to feature type. |
---|
28 | % 2. A histogram of the frequencies at which the different feature types |
---|
29 | % occur. |
---|
30 | % 3. Optionally a black/white edge image with edges coded by different line |
---|
31 | % styles. Not as pretty as the first plot, but it is something that can |
---|
32 | % be put in a paper and reproduced in black and white. |
---|
33 | |
---|
34 | % Copyright (c) 2001 Peter Kovesi |
---|
35 | % School of Computer Science & Software Engineering |
---|
36 | % The University of Western Australia |
---|
37 | % http://www.csse.uwa.edu.au/ |
---|
38 | % |
---|
39 | % Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
40 | % of this software and associated documentation files (the "Software"), to deal |
---|
41 | % in the Software without restriction, subject to the following conditions: |
---|
42 | % |
---|
43 | % The above copyright notice and this permission notice shall be included in |
---|
44 | % all copies or substantial portions of the Software. |
---|
45 | % |
---|
46 | % The Software is provided "as is", without warranty of any kind. |
---|
47 | |
---|
48 | % June 2001 |
---|
49 | |
---|
50 | function im = dispfeat(ft, edgeim) |
---|
51 | |
---|
52 | % Construct the colour coded image |
---|
53 | |
---|
54 | maxhue = 0.7; % Hues vary from 0 (red) indicating line feature to |
---|
55 | % 0.7 (blue) indicating a step feature. |
---|
56 | nhues = 50; |
---|
57 | phaseang = angle(ft); % Extract phase angles. |
---|
58 | |
---|
59 | % Map -ve phase angles to 0-pi |
---|
60 | negphase = phaseang<0; |
---|
61 | phaseang = negphase.*(-phaseang) + ~negphase.*phaseang; |
---|
62 | |
---|
63 | % Then map angles > pi/2 to 0-pi/2 |
---|
64 | x = phaseang>(pi/2); |
---|
65 | phaseang = x.*(pi-phaseang) + ~x.*phaseang; |
---|
66 | |
---|
67 | % Now set up a HSV image and convert to RGB |
---|
68 | hsvim(:,:,1) = (pi/2-phaseang)/(pi/2)*maxhue; |
---|
69 | hsvim(:,:,2) = edgeim; % saturation |
---|
70 | hsvim(:,:,3) = 1; |
---|
71 | |
---|
72 | hsvim(1,:,3) = 0; |
---|
73 | hsvim(end,:,3) = 0; |
---|
74 | hsvim(:,1,3) = 0; |
---|
75 | hsvim(:,end,3) = 0; |
---|
76 | |
---|
77 | im = hsv2rgb(hsvim); |
---|
78 | |
---|
79 | % Set up the colour key bar |
---|
80 | keybar(:,:,1) = [maxhue:-maxhue/nhues:0]'; |
---|
81 | keybar(:,:,2) = 1; |
---|
82 | keybar(:,:,3) = 1; |
---|
83 | keybar = hsv2rgb(keybar); |
---|
84 | |
---|
85 | % Plot the results |
---|
86 | figure(1), clf |
---|
87 | subplot('position',[.05 .1 .75 .8]), imshow(im) |
---|
88 | subplot('position',[.8 .1 .1 .8]), imshow(keybar) |
---|
89 | |
---|
90 | text(3,2,'step feature'); |
---|
91 | text(3,nhues/2,'step/line'); |
---|
92 | text(3,nhues,'line feature'); |
---|
93 | |
---|
94 | % Construct the histogram of feature types |
---|
95 | |
---|
96 | figure(2),clf |
---|
97 | data = phaseang(find(edgeim)); % find phase angles just at edge points |
---|
98 | |
---|
99 | Nbins = 32; |
---|
100 | bincentres = [0:pi/2/Nbins:pi/2]; |
---|
101 | |
---|
102 | hdata = histc(data(:), bincentres); |
---|
103 | bar(bincentres+pi/4/Nbins, hdata) % plot histogram |
---|
104 | |
---|
105 | ymax = max(hdata); |
---|
106 | xlabel('phase angle'); ylabel('frequency'); |
---|
107 | ypos = -.12*ymax; |
---|
108 | axis([0 pi/2 0 1.05*ymax]) |
---|
109 | |
---|
110 | if nargin == 3 |
---|
111 | |
---|
112 | % Construct the feature type image coded using different line styles |
---|
113 | |
---|
114 | % Generate a phase angle image with non-zero values only at edge |
---|
115 | % points. An offset of eps is added to differentiate points having 0 |
---|
116 | % phase from non edge points. |
---|
117 | featedge = (phaseang+eps).*double(edgeim); |
---|
118 | |
---|
119 | % Now construct feature images over specified phase ranges |
---|
120 | f1 = featedge >= eps & featedge < pi/6; |
---|
121 | f2 = featedge >= pi/6 & featedge < pi/3; |
---|
122 | f3 = featedge >= pi/3 & featedge <= pi/2; |
---|
123 | |
---|
124 | fprintf('Linking edges for plots...\n'); |
---|
125 | [f1edgelst dum] = edgelink(f1,2); |
---|
126 | [f2edgelst dum] = edgelink(f2,2); |
---|
127 | [f3edgelst dum] = edgelink(f3,2); |
---|
128 | |
---|
129 | figno = 3; |
---|
130 | figure(figno), clf |
---|
131 | |
---|
132 | % Construct a legend by first drawing some dummy, zero length, lines |
---|
133 | % with the appropriate linestyles in the right order |
---|
134 | line([0 0],[0 0],'LineStyle','-'); |
---|
135 | line([0 0],[0 0],'LineStyle','--'); |
---|
136 | line([0 0],[0 0],'LineStyle',':'); |
---|
137 | legend('step', 'step/line', 'line',3); |
---|
138 | |
---|
139 | % Now do the real plots |
---|
140 | plotedgelist(f1edgelst, figno, '-'); |
---|
141 | plotedgelist(f2edgelst, figno, '--'); |
---|
142 | plotedgelist(f3edgelst, figno, ':'); |
---|
143 | |
---|
144 | % Draw a border around the whole image |
---|
145 | [r c] = size(edgeim); |
---|
146 | line([0 c c 0 0],[0 0 r r 0]); |
---|
147 | axis([0 c 0 r]) |
---|
148 | axis equal |
---|
149 | axis ij |
---|
150 | axis off |
---|
151 | |
---|
152 | end |
---|
153 | |
---|
154 | |
---|
155 | %------------------------------------------------------------------------ |
---|
156 | % Internal function to plot an edgelist as generated by edgelink using a |
---|
157 | % specified linestyle |
---|
158 | |
---|
159 | function plotedgelist(elist, figno, linestyle) |
---|
160 | |
---|
161 | figure(figno); |
---|
162 | for e = 1:length(elist) |
---|
163 | line(elist{e}(:,2), elist{e}(:,1), 'LineStyle', linestyle, ... |
---|
164 | 'LineWidth',1); |
---|
165 | end |
---|