-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSegmentRoots.m
39 lines (33 loc) · 1.1 KB
/
SegmentRoots.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
function binaryMask = SegmentRoots(inputImage, maxIslandNumPixels, segmentPlantFirst, maxIslandNumPixelsPlant)
%SegmentRoots Computes the binary mask for roots in the image, using color
%thresholding in RGB, YCBCR, and LAB color spaces.
% After segmentation, small islands of size maxIslandNumPixels are
% removed.
if nargin < 2
maxIslandNumPixels = 100;
end
if nargin < 3
segmentPlantFirst = true;
end
if nargin < 4
maxIslandNumPixelsPlant = 50;
end
imageHist = histeq(inputImage);
if segmentPlantFirst
plantMask = SegmentPlant(inputImage, maxIslandNumPixelsPlant);
inputImage = uint8(plantMask) .* inputImage;
imageHist = uint8(plantMask) .* imageHist;
end
binaryMask = createMaskRootsLABorig(inputImage) & ...
createMaskRootsLABhist(imageHist);
binaryMask = imclearborder(binaryMask, 8);
binaryMask = bwareaopen(binaryMask, maxIslandNumPixels);
% close all
% imshow(imageHist)
% figure
% imshow(inputImage)
% figure
% imshow(imageHist)
% figure
% imshow(binaryMask)
end