-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextureFilter.m
More file actions
119 lines (95 loc) · 2.94 KB
/
Copy pathtextureFilter.m
File metadata and controls
119 lines (95 loc) · 2.94 KB
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
function [I,clrmp,gx,gy,lambdaMaxMin]=textureFilter(ma,Ras)
% textureFilter finds local orientation
%
% SYNOPSIS [clrmp,J11,J12,J22,gx,gy,gxy,lambdaMaxMin]=textureFilter(ma,Ras)
%
% INPUT ma : size of the mask for finding local orientation
% Ras : for plotting vectors overlaid the colormap not all points
% are used but every Ras-th (Raster)
%
% OUTPUT I : image
% clrmp : wrapped around colormap of I
% gx : gradient of I in X
% gy : gradient of I in Y
% lambdaMaxMin : ratio of eigenvalues
% lambdaMax gives the magnitude of the local gradient
% lambdaMin gives the magnitude of the local direction
%
% DEPENDENCES textureFilter uses { Gauss2D1 }
% textureFilter is used by { }
%
% Alexandre Matov, February 20th, 2003
if nargin == 0
DEBUG=1;
Ras=20;
ma=19; % mask size
end
% choose an image
[fileName,dirName] = uigetfile('*.tif','Choose an image');
I=imread([dirName,filesep,fileName]);
I=I(:,:,1);
I=double(I);
%I=nrm(I,8);
I=Gauss2D1(I,1);
% convolution mask
mask=ones(ma);
% gradient
[gx,gy] = gradient(I);
gx2=gx.*gx;
gy2=gy.*gy;
gxy=gx.*gy;
J11=conv2(gx2,mask,'same');
J12=conv2(gxy,mask,'same');
J22=conv2(gy2,mask,'same');
[p,q]=size(I);
n=p*q;
h=waitbar(0,'Please wait...');
for i=1:n
col=fix(i/p)+1;
row=mod(i,p);
if row==0
row=p;
col=col-1;
end
J=[J11(row,col), J12(row,col); J12(row,col), J22(row,col)];
[v,e]=eig(J);
if e(1,1)<e(2,2)
j=1;
else
j=2;
end
if min(e(1,1),e(2,2))~=0
lambdaMaxMin(row,col)=max(e(1,1),e(2,2))/(min(e(1,1),e(2,2)));
else
lambdaMaxMin(row,col)=NaN;
end
% vertical movement => moving UP is 0 degrees (blue)
if v(2,j)~=0 & (max(e(1,1),e(2,2))/min(e(1,1),e(2,2)))>1.1 % only if the Y component is Not 0
angle=atan(v(1,j)/v(2,j));
clrmp(row,col)=angle;
else
clrmp(row,col)=NaN; % if the Y component is 0 => the angle is 90 degrees (moving on X)
end % end ATAN
% Wait bar
waitbar(i/n,h);
end
close(h);
% Debug figures
if DEBUG==1
Xmax=size(clrmp,2)-mod(size(clrmp,2),Ras)-Ras;
Ymax=size(clrmp,1)-mod(size(clrmp,1),Ras)-Ras;
clrmpS=clrmp(20:20:Ymax,20:20:Xmax);
[X,Y]=meshgrid(20:20:Xmax,20:20:Ymax);
% colormap
figure,imshow(clrmp,[]) % accumulated over all images in the folder
colormap('hsv')
colorbar
hold on
h = quiver(X(:),Y(:),sin(clrmpS(:)),cos(clrmpS(:)),'wo','filled');
set(h(1),'LineWidth',2.5)
hold off
figure,imshow(lambdaMaxMin,[1 6])
xlabel('Lambda Max/Min');
figure,imshow(I,[]) % original image
xlabel('Image');
end