代码:
函数[BW, maskedRGBImage] = createMask (RGB)
% createMask阈值从colorThresholder应用RGB图像使用自动生成的代码。
% (BW, MASKEDRGBIMAGE] = createMask (RGB)阈值图像RGB使用
%从colorThresholder应用。色彩和自动生成的代码
%最小/最大值为每个通道中设置的色彩
%的应用和结果在一个二进制掩盖BW和maskedRGBImage复合图像,
%显示面具下BW原始图像RGB值。
%自动生成colorThresholder应用于02年- 7 - 2021
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%将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假为零。
maskedRGBImage (repmat (~ BW, [1 1 3])) = 0;
结束