|
a |
|
b/Image Segmentation/Image Utility Functions/extraction/removeDisjointStructures.m |
|
|
1 |
function [ image ] = removeDisjointStructures( image ) |
|
|
2 |
%removeDisjointStructures |
|
|
3 |
%Otsu thresholding may not always provide a single structure that would |
|
|
4 |
%represent a nodule, this function will attempt to remove additional |
|
|
5 |
%structures. |
|
|
6 |
% |
|
|
7 |
% param Image |
|
|
8 |
% Must be an image that has had otsu segmentation done on it. |
|
|
9 |
% return fixedImage |
|
|
10 |
% an image with a single class to be used for segmentation |
|
|
11 |
|
|
|
12 |
%find all connected components |
|
|
13 |
CC = bwconncomp(image); |
|
|
14 |
|
|
|
15 |
%Count the number of pixels belonging to each component |
|
|
16 |
numPixels = cellfun(@numel,CC.PixelIdxList); |
|
|
17 |
|
|
|
18 |
%find the maximum area connected component, provides index and count |
|
|
19 |
[biggest,idx] = max(numPixels); |
|
|
20 |
|
|
|
21 |
|
|
|
22 |
%remove all other connected components that are not the largest |
|
|
23 |
%component |
|
|
24 |
for i=1:CC.NumObjects |
|
|
25 |
if(i == idx) |
|
|
26 |
continue; |
|
|
27 |
end |
|
|
28 |
%erase smaller components |
|
|
29 |
image(CC.PixelIdxList{i}) = 0; |
|
|
30 |
end |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
end |
|
|
36 |
|