/
purpleMask.m
35 lines (27 loc) · 1.33 KB
/
purpleMask.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
function [BW,prob] = purpleMask(I)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder App. The colorspace and
% minimum/maximum values for each channel of the colorspace were set in the
% App and result in a binary mask BW and a composite image maskedRGBImage,
% which shows the original RGB image values under the mask BW.
% Auto-generated by colorThresholder app on 27-Nov-2017
%------------------------------------------------------
% Convert RGB image to chosen color space
% Define thresholds for channel 1 based on histogram settings
channel1Min = min([13.162,15.243]);
channel1Max = max([28.251,30.751]);
channel2Min = min([14.151,19.302]);
channel2Max = max([20.885,27.720]);
channel3Min = min([7.426,3.131]);
channel3Max = max([14.724,21.810]);
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = I;
% Set background pixels where BW is false to zero.
prob = mean2(BW);
end