代码:
函数[BW, maskedRGBImage] = createMask (RGB)
%createMask阈值RGB图像使用自动生成的代码从colorThresholder应用程序。
% [BW,MASKEDRGBIMAGE] = createMask(RGB)阈值图像RGB使用
%从colorThresholder应用程序自动生成的代码
中设置的每个颜色空间通道的最小/最大值
% App,得到二进制掩码BW和合成图像maskedRGBImage,
%表示掩码BW下的原始RGB图像值。
%由colorThresholder应用程序在2021年7月2日自动生成
%------------------------------------------------------
%转换RGB图像到选择的颜色空间
I = rgb2ycbcr (RGB);
%根据直方图设置为通道1定义阈值
channel1Min = 73.000;
channel1Max = 144.000;
%根据直方图设置定义通道2的阈值
channel2Min = 100.000;
channel2Max = 133.000;
%根据直方图设置定义通道3的阈值
channel3Min = 137.000;
channel3Max = 153.000;
%根据选择的直方图阈值创建掩码
sliderBW =(我(::1)> = channel1Min) &(我(:,:1)< = channel1Max) &...
(我(::2)> = channel2Min) &(我(:,:2)< = channel2Max) &...
(我(::3)> = channel3Min) &(我(:,:,3)< = channel3Max);
BW = sliderBW;
基于输入图像初始化输出屏蔽图像。
maskedRGBImage = RGB;
将BW为假的背景像素设置为0。
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
结束