33% Load one slice from ISBI
44load(" data/slice_ISBI_1_1_75.mat" );
55
6- % Create input set
6+ % Load Unet
7+ onnx = importNetworkFromONNX(" models/model64.onnx" );
8+ % analyzeNetwork(onnx)
9+ net = matlab2nnv(onnx );
10+ windowSize = 64 ; % from trained model
11+
12+ % Bias Field
13+ order = 3 ;
14+ coeff = 0.01 ;
15+ img_bf = BiasField(flair , order , coeff );
16+
17+ % Crop background before patches (for all data)
18+ flair = flair(31 : 158 , 31 : 158 );
19+ img_bf = img_bf(31 : 158 , 31 : 158 );
20+ mask = mask(31 : 158 , 31 : 158 );
21+
22+ % From here, to verify slice, we need to verify 4 patches
23+
24+ % Define verification parameters (reach method)
25+ reachOptions.reachMethod = " relax-star-area-reduceMem" ;
26+ reachOptions.relaxFactor = 1 ;
27+ reachOptions.lp_solver = " gurobi" ; % (optional)
28+
29+ % Create bounds of input set
730lb = flair ;
831ub = img_bf ;
932
10- windowSize = 64 ;
1133
12- % Crop background before patches
13- flair = flair(35 : 158 , 30 : 153 );
1434
15- % From here, to verify slice, we need to verify 4 patches
35+ % Patch 1: Left-top corner
36+ InputSet1 = ImageStar(lb(1 : 64 ,1 : 64 ), ub(1 : 64 ,1 : 64 ));
37+
38+ % Compute reachability
39+ tic ;
40+ OutputSet1 = net .reach(InputSet1 , reachOptions );
41+ toc ;
42+
43+ % Verified output
44+ verOut1 = verify_output(OutputSet1 );
45+
46+
47+
48+ % Patch 2: Right-top corner
49+ InputSet2 = ImageStar(lb(1 : 64 ,65 : 128 ), ub(1 : 64 ,65 : 128 ));
50+
51+ % Compute reachability
52+ tic ;
53+ OutputSet2 = net .reach(InputSet2 , reachOptions );
54+ toc ;
55+
56+ % Verified output
57+ verOut2 = verify_output(OutputSet2 );
58+
59+
60+
61+ % Patch 3: Right-bottom corner
62+ InputSet3 = ImageStar(lb(65 : 128 ,65 : 128 ), ub(65 : 128 ,65 : 128 ));
63+
64+ % Compute reachability
65+ tic ;
66+ OutputSet3 = net .reach(InputSet3 , reachOptions );
67+ toc ;
68+
69+ % Verified output
70+ verOut3 = verify_output(OutputSet3 );
71+
72+
73+
74+ % Patch 4: Lft-bottom corner
75+ InputSet4 = ImageStar(lb(65 : 128 ,1 : 64 ), ub(65 : 128 ,1 : 64 ));
76+
77+ % Compute reachability
78+ tic ;
79+ OutputSet4 = net .reach(InputSet4 , reachOptions );
80+ toc ;
81+
82+ % Verified reachability
83+ verOut4 = verify_output(OutputSet4 );
84+
85+ % Output reachability
86+ outputSlice = [verOut1 verOut2 ; verOut3 verOut4 ];
87+ save(" results/biasfield_output.mat" ," outputSlice" )
88+
89+ imshow(outputSlice , [0 ,2 ], colormap= hsv(3 ))
90+ colorbar(' XTickLabel' , {' Background' , ' Lesion' , ' Unknown' }, ' XTick' ,[0 ,1 ,2 ])
91+
92+ % Verified output
93+ verifiedSlice = output_vs_mask(outputSlice , mask );
94+ imshow(verifiedSlice , [-2 ,2 ], colormap= hsv(5 ))
95+ colorbar(' XTickLabel' , {' False Negative' , ' False Positive' , ' Background' , ' Lesion' , ' Unknown' }, ' XTick' ,[-2 ,-1 ,0 ,1 ,2 ])
96+
97+ % Verified lesion
98+ overlay = labeloverlay(flair ,verifiedSlice ,' transparency' ,0.3 );
99+ imshow(overlay ,[-2 2 ]);
100+
101+ figure ;
102+ subplot(1 ,4 ,1 );
103+ mi_f = min(flair , [], ' all' );
104+ ma_f = max(flair ,[], ' all' );
105+ overlay = labeloverlay(flair ,mask ,' transparency' ,0.3 );
106+ imshow(overlay ,[mi_f , ma_f ]);
107+ title(" Label mask" )
108+
109+ subplot(1 ,4 ,2 );
110+ overlay = labeloverlay(flair ,verifiedSlice== 1 ,' transparency' ,0.3 );
111+ imshow(overlay ,[mi_f , ma_f ]);
112+ title(' Verified lession' )
113+
114+ subplot(1 ,4 ,3 );
115+ overlay = labeloverlay(flair ,verifiedSlice== 2 ,' transparency' ,0.3 );
116+ imshow(overlay ,[mi_f , ma_f ]);
117+ title(" Unknown" )
16118
17- % Left-top corner
119+ subplot(1 ,4 ,4 );
120+ overlay = labeloverlay(flair ,verifiedSlice==-1 ,' transparency' ,0.3 );
121+ imshow(overlay ,[mi_f , ma_f ]);
122+ title(" False positives" )
0 commit comments