-
Notifications
You must be signed in to change notification settings - Fork 46
/
computeFilteredMatrices.m
62 lines (44 loc) · 1.59 KB
/
computeFilteredMatrices.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
function [rows, cols, data, m, n, bFiltered] = computeFilteredMatrices(sideLength, A, b)
if (nargin > 2)
assert(size(A, 1) == size(b, 1), 'Size of A and b are incompatible!');
end
numPixels = size(A, 1);
imageSize = sqrt(numPixels);
filteredSize = sideLength; %round(scale * imageSize);
if (nargin > 2)
% Filter b
bFiltered = full(reshape(b, [imageSize, imageSize]));
bFiltered = imresize(bFiltered, [filteredSize filteredSize]);
bFiltered = bFiltered(:);
end
% Filter A
m = filteredSize * filteredSize;
n = size(A, 2);
%[X, Y] = meshgrid(1 : filteredSize, 0 : filteredSize - 1);
%figure;
%hold on;
edgeImage = zeros(imageSize, imageSize);
rows = zeros(0,1);
cols = rows;
data = rows;
for i = 1 : n
edgeImage = 0 * edgeImage;
[j, k, v] = find(A(:, i));
edgeImage(j) = v;
edgeImage = edgeImage';
filteredEdgeImage = imresize(edgeImage, [filteredSize filteredSize], 'box');
[j, k, v] = find(filteredEdgeImage);
%imshow(edgeImage);
%imshow(filteredEdgeImage);
numElems = size(j, 1);
rowNumbers = (j - 1) * filteredSize + k;
colNumbers = repmat(i, numElems, 1);
filteredData = v;
%Update data
rows = [rows' rowNumbers']';
cols = [cols' colNumbers']';
data = [data' filteredData']';
fprintf('Iteration %d of %d\n', i, n);
end
%AFiltered = sparse(rows, cols, data, m, n);
end