-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageToVectors.m
42 lines (30 loc) · 1.18 KB
/
imageToVectors.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
function [vectorList, originalImageSize] = imageToVectors(Image, blockSize)
[numLines, numColumns] = size(Image);
originalImageSize = [numLines, numColumns];
numBlockLines = ceil(numLines / blockSize);
numBlockColumns = ceil(numColumns / blockSize);
numVectors = numBlockLines * numBlockColumns;
vectorSize = blockSize^2;
vectorList = zeros(numVectors, vectorSize);
vectorListIndex = 1;
for i = 1:blockSize:numLines
for j = 1:blockSize:numColumns
vectorIndex = 1;
for blockLine = 1:blockSize
for blockColumn = 1:blockSize
blockLineInImage = i + blockLine - 1;
blockColumnInImage = j + blockColumn - 1;
if blockLineInImage > numLines || ...
blockColumnInImage > numColumns
value = 0;
else
value = Image(blockLineInImage, blockColumnInImage);
end
vectorList(vectorListIndex, vectorIndex) = value;
vectorIndex = vectorIndex + 1;
end
end
vectorListIndex = vectorListIndex + 1;
end
end
end