-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathColorSegments.m
More file actions
57 lines (31 loc) · 1.18 KB
/
Copy pathColorSegments.m
File metadata and controls
57 lines (31 loc) · 1.18 KB
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
function [ segmentedImage, binaryImage ] = ColorSegments( regionMatrix )
%COLORSEGMENTS Summary of this function goes here
% Detailed explanation goes here
uniqueRegionLabels = unique(regionMatrix);
uniqueRegionLabelCount = numel(uniqueRegionLabels);
labelColors = [];
for ii = 1 : uniqueRegionLabelCount
rValue = randi(255);
gValue = randi(255);
bValue = randi(255);
labelColors = [labelColors; rValue gValue bValue];
end
frequentLabel = mode(mode(regionMatrix));
[rows, cols] = size(regionMatrix);
segmentedImage = uint8(zeros(rows, cols, 3));
binaryImage = uint8(zeros(rows, cols, 1));
for ii = 1 : rows
for jj = 1 : cols
regionLabel = regionMatrix(ii, jj);
colorIndex = find(uniqueRegionLabels == regionLabel);
segmentedImage(ii, jj, 1) = labelColors(colorIndex, 1);
segmentedImage(ii, jj, 2) = labelColors(colorIndex, 2);
segmentedImage(ii, jj, 3) = labelColors(colorIndex, 3);
if regionLabel == frequentLabel
binaryImage(ii, jj) = 0;
else
binaryImage(ii, jj) = 255;
end
end
end
end