我如何在Matlab中使用颜色阈值应用程序掩盖绿色像素?

时间:2018-07-04 08:50:22

标签: matlab image-processing matlab-figure image-segmentation feature-extraction

我正在进行植物病害的检测和分类。首先,我要进行预处理,然后进行图像分割。在分割中,我使用Matlab中的color thresholder应用程序对RGB图像进行背景去除。然后,我将遮罩绿色像素, 通过应用遮罩识别并除去绿色水平高于红色和蓝色的像素。这是基于以下事实:这些绿色像素最有可能代表叶子中的健康区域。因此,在删除背景像素和绿色像素之后,图像中剩下的区域就是我们感兴趣的区域。 **

  

如何遮罩绿色像素以及如何使用阈值   使用Matlab中的颜色阈值应用程序删除背景?

请回答我!这是我的主要代码:

a = imread('LB.jpg');
subplot(2,3,1);
imshow(a);title('Input Image');

b = rgb2gray(a);
subplot(2,3,2);
imshow(b);title('Grey Image');

c = medfilt2(b,[3 3]);
subplot(2,3,3);
imshow(c);title('Filtered Image using 3*3 window');

[bw,rgb] = background_removal(a);
subplot(2,3,4);
imshow(bw);title('Binary Image');
subplot(2,3,5);
imshow(rgb);title('Background Removed');

而且,此代码是在matlab中使用颜色阈值消除背景:     %由colorThresholder应用程序于2018年3月26日自动生成     %------------------------------------------------- ------

function [BW,maskedRGBImage] = createMask(RGB)

% Convert RGB image to chosen color space
RGB = im2double(RGB);
cform = makecform('srgb2lab', 'AdaptedWhitePoint', whitepoint('D65'));
I = applycform(RGB,cform);

% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.408;
channel1Max = 99.533;

% Define thresholds for channel 2 based on histogram settings
channel2Min = -27.701;
channel2Max = 14.325;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 5.282;
channel3Max = 50.539;

% Create mask based on chosen histogram thresholds
BW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
    (I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
    (I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);

% Initialize output masked image based on input image.
maskedRGBImage = RGB;

% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;

0 个答案:

没有答案