How do i mask green pixels?

6 Ansichten (letzte 30 Tage)
Yoon ThiriZaw
Yoon ThiriZaw am 3 Jun. 2018
Kommentiert: Image Analyst am 2 Mai 2020
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 Kommentar
ARCHANA KUMARI
ARCHANA KUMARI am 23 Apr. 2020
Have u completed this project? I need some help in this project.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 3 Jun. 2018
Bearbeitet: KALYAN ACHARJYA am 3 Jun. 2018
 % 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 Kommentare
Sudipto Dhar
Sudipto Dhar am 2 Mai 2020
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 am 2 Mai 2020
Try the Color Thresholder app on the Apps tab of the tool ribbon. Or else see My File Exchange

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Agriculture finden Sie in Help Center und File Exchange

Produkte


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by