How do i mask green pixels?

6 次查看(过去 30 天)
i am doing plant disease detection and classification. i do preprocessing step, then image segmentation. In segmentation, i do background removal in RGB image using color thresholder app in matlab. Then, i will do masking green pixels, the pixels where the level of green is higher than red and blue are identified and removed by application of the mask. This is based on the fact that these green pixels most probably represent healthy areas in the leaves. Thus, after removing the background and green pixels, the region left in an image is the region of our interest. How do i mask green pixels? Please, answer me! This is my main code:
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');
And, this code is background removing using color thresholder in matlab:
% Auto-generated by colorThresholder app on 26-Mar-2018
%-------------------------------------------------------
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;
Thanks!
  1 个评论
ARCHANA KUMARI
ARCHANA KUMARI 2020-4-23
Have u completed this project? I need some help in this project.

请先登录,再进行评论。

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2018-6-3
编辑:KALYAN ACHARJYA 2018-6-3
 % code
%Concept Learned from Image Analyst Sir
k=imread('flower.jpg');
mask=(k(:,:,2)>k(:,:,1)) & (k(:,:,2)>k(:,:,3));
threshold_image=bsxfun(@times, k, cast(imcomplement(mask), 'like', k));
subplot(121),imshow(k);
subplot(122),imshow(threshold_image);
  5 个评论
Sudipto Dhar
Sudipto Dhar 2020-5-2
dear yoon, could you find the way of masking? can you share your code with me? I need to get some basic idea from it. thank you.
Image Analyst
Image Analyst 2020-5-2
Try the Color Thresholder app on the Apps tab of the tool ribbon. Or else see My File Exchange

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Agriculture 的更多信息

产品


版本

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by