-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.m
76 lines (61 loc) · 1.67 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
clear; clc; close all;
addpath('src');
addpath('src\EM');
addpath('src\GC');
lambda1 = 0.9;
lambda2 = 0.9;
reso = 1; % image resolution
%% preprocessing
[img1,map1] = imread('E:\data\GAMMA_fil\fil1.bmp','bmp');
[img2,map2] = imread('E:\data\GAMMA_fil\fil4.bmp','bmp');
img1 = double(round(img1));
img2 = double(round(img2));
[M,N,H] = size(img1);
%% radiation correction
% img1 = rad_corr(img1);
% img2 = rad_corr(img2);
% figure;
% imshow(uint8(img1));
% figure;
% imshow(uint8(img2));
%% add MBI and calculate difference image
% load ..\cosegmentation_data\MBI;
MBI1 = cal_MBI(img1);
MBI2 = cal_MBI(img2);
img1 = cat(3,img1,MBI1);
img2 = cat(3,img2,MBI2);
Ic = img_diff(img1,img2);
figure;
imshow(Ic,[]);
Ic_hist = imhist16(Ic);
figure;
stem(Ic_hist)
%% calulate threshold using Bayes theory
[T_theory,T_experiment,gamma] = cal_threshold(Ic);
T = T_theory;
%% build graph and calculate edge weights
[termWeights_1, edgeWeights_1] = cal_weight(img1,Ic,lambda1,T);
[termWeights_2, edgeWeights_2] = cal_weight(img2,Ic,lambda2,T);
%% graph-cut algorithm for cosegmentation
[cut_1, labels_1] = graphCutMex(termWeights_1, edgeWeights_1);
[cut_2, labels_2] = graphCutMex(termWeights_2, edgeWeights_2);
%% fragmentation Removal
seg1 = reshape(labels_1, [M,N]);
seg2 = reshape(labels_2, [M,N]);
seg1 = frag_remove(seg1,reso);
seg2 = frag_remove(seg2,reso);
figure;
imshow(seg1);
title('seg1 after frag remove')
figure;
imshow(seg2);
title('seg2 after frag remove')
%% Correspondence Establishment
[seg1_oa,seg2_oa] = overlay_analysis(seg1,seg2);
[seg1_show,seg2_show] = assign_label(seg1_oa,seg2_oa);
figure;
imshow(seg1_show);
title('1 and 4')
% figure;
% imshow(seg2_show);
% title('seg2')