-
Notifications
You must be signed in to change notification settings - Fork 1
/
Binning.m
58 lines (38 loc) · 1.45 KB
/
Binning.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
function [BinImages,NUM_BIN_IMAGES,MAX_DISTANCE] = Binning( image,BinSizes)
%% This function Bins the images based on BinSizes and returns a set of Binary Images(:BinSizes) ,the number of such Images(:BUM_BIN_IMAGES)
% And the maximum value of a pixel(for grey scale it's 255)
%CODE
image = histeq(image);
MAX_DISTANCE = 255;
NUM_BIN_IMAGES = calculateNumBins_2Level(BinSizes,MAX_DISTANCE);
[row,col,~] = size(image);
BinImages = false(row,col,NUM_BIN_IMAGES);
q_offset = 0;
DistanceMatrix = zeros(row,col);
for r = 1:row
for c = 1:col
if size(image,3) == 1
DistanceMatrix(r,c) = image(r,c); %%ASSUMED GRAY SCALE IMAGE,OTHERWISE VALUE ARE RGB Euclidean distance
else
DistanceMatrix(r,c) = image(r,c);
end
end
end
for i = 1:numel(BinSizes)
main_offset = ceil(MAX_DISTANCE/BinSizes(i));
k = ceil((BinSizes(i)/2)) -1;
% fprintf("\nMapping Image to Bin Size: %d",BinSizes(i));
for r = 1:row
for c = 1:col
value = DistanceMatrix(r,c);
x = q_offset+floor(value/BinSizes(i))+1;
BinImages(r,c,x) = 1;
if value>k && value<(((main_offset-1)*BinSizes(i))+k) %%CHANGES IN MAX DISTANCE MADE
y = q_offset+main_offset+ceil((value-k)/BinSizes(i));
BinImages(r,c,y) = 1;
end
end
end
q_offset = q_offset+2*main_offset-1;
end
end