-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyImageSegmentation3.m
More file actions
136 lines (85 loc) · 2.72 KB
/
MyImageSegmentation3.m
File metadata and controls
136 lines (85 loc) · 2.72 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
close all; clear all; clc;
nF = 100;
%Load data from my SIFT matcher and F estimator
%Unary = textscan('FWeights', 'f');
fileID = fopen('FWeights');
[A,countF] = fscanf(fileID, '%f');
fclose(fileID);
fileID = fopen('neighbours');
[B,countN] = fscanf(fileID, '%d');
fclose(fileID);
fileID = fopen('neighbourCost');
[C,countNC] = fscanf(fileID, '%f');
fclose(fileID);
fileID = fopen('points1');
[D,countP] = fscanf(fileID, '%f');
fclose(fileID);
nPoints = countP/2;
nNeighbours = countN/nPoints;
unary = reshape(A', nPoints, nF);
neighbourhood = reshape(B', nPoints, nNeighbours); neighbourhood = neighbourhood';
neighbourCost = reshape(C', nPoints, nNeighbours); neighbourCost = neighbourCost';
currentLabel = zeros(1, nPoints);
costOfModelApp = ones(1, nF) * 0.5; costOfModelApp = costOfModelApp';
outlier = 15.0;
points = reshape(D', nPoints, 2);
%neighbourhoodZero = neighbourhood == 0;
neighbourCostMax = max(neighbourCost(:));
%unaryMax = max(unary(:));
%unary = unary * (1/unaryMax);
%unary = unary .* unary;
%unary = unary * 20;
%neighbourhood = neighbourhood + ones(size(neighbourhood)) - neighbourhoodZero;
%neighbourCost = ones(size(neighbourCost))*0.1;
neighbourCost = ones(size(neighbourCost))*2;
%max is around 5k
max_d = 5000;
for i = 1:nPoints
for j = 1:nNeighbours
%neighbourCost(j,i) = neighbourCost(j,i);
if neighbourhood(j,i) == i
neighbourhood(j, i) = 0;
end
end
end
%figure;
%plot(neighbourCost(:,1), '.r');
rng(10);
cols = rand(nF, 3);
%cols = hsv(nF);
figure;
%img = imread('2_1m.jpg');
%img = rgb2gray(imread('6_1m.png'));
img = rgb2gray(imread('blend_2.png'));
%img = imread('myD1m.jpg');
imshow(img);
nDrawn = 0;
for j = 1:1
[models internal]= expand(unary, neighbourhood, neighbourCost, currentLabel, costOfModelApp, outlier);
hold on;
for i = 1:nPoints
%plot(points(i,1),points(i,2),'r.','MarkerSize',20)
if(internal(i,1) ~= 0)
%nDrawn = nDrawn ;
plot(points(i,1),points(i,2),'r.', 'Color', cols(internal(i, 1), :),'MarkerSize',20);
end
end
hold off;
end
%lets check that the neighbours are indeed the neighbours
figure;
imshow(img);
for i = 1:nPoints
imshow(img);
hold on;
for j = 1:nNeighbours
index = neighbourhood(j,i);
if index ~=0
x = points(neighbourhood(j,i), 1);
y = points(neighbourhood(j,i), 2);
plot(x, y,'r.', 'Color', cols(internal(i, 1), :),'MarkerSize',20);
end
end
hold off;
pause;
end