|
a |
|
b/Image Segmentation/generateSegmentations.m |
|
|
1 |
%% generateSegmentations.m |
|
|
2 |
%Patrick Stein 8/20/2013 |
|
|
3 |
%This will run both otsu and region growing segmentations and create the |
|
|
4 |
%appropriate masks for both otsu and RG. |
|
|
5 |
% |
|
|
6 |
% Before you run this script make sure to |
|
|
7 |
|
|
|
8 |
%% Clear workspace |
|
|
9 |
|
|
|
10 |
clear all; |
|
|
11 |
close all; |
|
|
12 |
clc; |
|
|
13 |
%% Setup workspace for image segmentation |
|
|
14 |
%The folder with all of your DICOM images you wish to segment |
|
|
15 |
folderWithImages = '\\ailab03\WeakSegmentation\2k largest slice crops'; |
|
|
16 |
%The number of classes you want for Otsu |
|
|
17 |
otsuClassNumber = 5; |
|
|
18 |
%Start threshold for RG |
|
|
19 |
rgStart = 0.0005; |
|
|
20 |
%Ending threshold |
|
|
21 |
rgEnd = 0.0021; |
|
|
22 |
%In what increments should the threshold be increased. |
|
|
23 |
rgInc = 0.0003; |
|
|
24 |
|
|
|
25 |
%add paths to utility functions and segmentations |
|
|
26 |
addpath(genpath('..\Image Segmentation')); |
|
|
27 |
|
|
|
28 |
%Open Matlab pool for multi-threading |
|
|
29 |
if(matlabpool('size') == 0) %checking to see if my pool is already open |
|
|
30 |
matlabpool open 4 |
|
|
31 |
end |
|
|
32 |
%start timer |
|
|
33 |
tic |
|
|
34 |
%Turn off warnings briefly because parfor loop will get very angry at |
|
|
35 |
%variables being declared even though they are temporary |
|
|
36 |
warning('off','all'); |
|
|
37 |
%% Generate segmentations |
|
|
38 |
disp('Beginning Otsu...'); |
|
|
39 |
[otsuImages] = runOtsu(folderWithImages,otsuClassNumber); |
|
|
40 |
disp('Otsu complete! Beginning Region Growing...'); |
|
|
41 |
[rgImages] = runRegionGrowing(folderWithImages,rgStart,rgEnd,rgInc); |
|
|
42 |
disp('Region Growing Complete!'); |
|
|
43 |
|
|
|
44 |
%% Wrap up after segmentation |
|
|
45 |
%close matlab pool |
|
|
46 |
matlabpool close; |
|
|
47 |
%turn warnings back on |
|
|
48 |
warning('on','all'); |
|
|
49 |
|
|
|
50 |
%% Generate masks |
|
|
51 |
disp('Generating masks...'); |
|
|
52 |
otsuImages = createMasks(otsuImages); |
|
|
53 |
rgImages = createMasks(rgImages); |
|
|
54 |
disp('Mask generation complete!'); |
|
|
55 |
%% Wrap up |
|
|
56 |
toc |
|
|
57 |
|
|
|
58 |
%send a message out |
|
|
59 |
matlabMail('Pinkjello92@gmail.com','Segmentation Complete'); |
|
|
60 |
|