-
Notifications
You must be signed in to change notification settings - Fork 7
/
mst.asv
154 lines (124 loc) · 2.94 KB
/
mst.asv
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
clc
clear all
close all
% pn = 'C:\accv\SIXray\20\Image\';
pn = 'C:\accv\SIXray\1\1\';
% pn = 'C:\OPIXray-master\DOAM\OPIXray_Dataset\test\test_image\';
% pn = 'C:\GDXray\';
% pn = 'C:\Users\Windows\Downloads\COMPASS-XP\Colour\';
% pn2 = 'C:\OPIXray-master\DOAM\OPIXray_Dataset\test\test_annotation\';
ext_img = [pn '*.jpg'];
a = dir(ext_img);
nfile = length(a);
proposals = {};
obj = [];
for i=1:nfile
fn = a(i).name;
img = imread([pn fn]);
if ismatrix(img) == false
img = rgb2gray(img);
end
img = imadjust(img);
% tensors=structureTensor(img,4);
% [s1,s3] = getCoherentOne(tensors);
if isempty(s3)
img = mat2gray(s1);
else
imagesc(s1+s3);
img = 1*mat2gray((s1+s3));
end
imagesc(img);
c = getframe
c = c.cdata;
c = imresize(c,[576 768],'bilinear');
fn=replace(fn,'.jpg','.png');
imwrite(c,['scans\SIXray_dataset\negatives\' fn],'PNG');
end
function [cTensor,cTensor2] = getCoherentOne(tensors)
cTensor = [];
cTensor2 = [];
[r,c] = size(tensors);
m = -100000000000000000;
index1 = -1;
index2 = -1;
for i = 1:r
for j = 1:c
if isempty(tensors{i,j})
continue;
end
t = tensors{i,j};
[u s v] = svd(t);
if m < max(max(s))
cTensor2 = cTensor;
cTensor = t;
m = max(max(s));
end
end
end
% figure,imagesc(cTensor)
end
function [Sxx, Sxy, Syy] = stOld(I,si,so)
I = double(I);
[m n] = size(I);
Sxx = NaN(m,n);
Sxy = NaN(m,n);
Syy = NaN(m,n);
x = -2*si:2*si;
g = exp(-0.5*(x/si).^2);
g = g/sum(g);
gd = -x.*g/(si^2);
Ix = conv2( conv2(I,gd,'same'),g','same' );
Iy = conv2( conv2(I,gd','same'),g,'same' );
Ixx = Ix.^2;
Ixy = Ix.*Iy;
Iyy = Iy.^2;
x = -2*so:2*so;
g = exp(-0.5*(x/so).^2);
Sxx = conv2( conv2(Ixx,g,'same'),g','same' );
Sxy = conv2( conv2(Ixy,g,'same'),g','same' );
Syy = conv2( conv2(Iyy,g,'same'),g','same' );
end
%%
function [tensors] = structureTensor(I,N)
I = double(I);
[m n] = size(I);
si = 1;
so = 1;
tensors = {};
Sxx = NaN(m,n);
Sxy = NaN(m,n);
Syy = NaN(m,n);
x = -2*si:2*si;
g = exp(-0.5*(x/si).^2);
g = g/sum(g);
gd = -x.*g/(si^2);
a = zeros(5,5);
a(3,:) = gd;
b = zeros(5,5);
b(:,3) = g;
an = a;
index = 1;
gradients = {};
index = 1;
for i = 0:N-1
angle = (2*180*i)/N;
a = imrotate(an,angle,'bilinear','crop');
Ig = conv2( conv2(I,a,'same'),b','same' );
gradients{index} = Ig;
index = index + 1;
end
nGradients = length(gradients);
for i = 1:nGradients
I1 = gradients{i};
for j = 1:nGradients
I2 = gradients{j};
Ixy = I1.*I2;
Sxy = imdiffusefilt(Ixy);
x = -2*so:2*so;
g = exp(-0.5*(x/so).^2);
% Sxy = conv2( conv2(Ixy,g,'same'),g','same' );
tensors{i,j} = Sxy;
% imagesc(Sxy)
end
end
end