필터 지우기
필터 지우기

How do i mask green pixels?

조회 수: 6 (최근 30일)
Yoon ThiriZaw
Yoon ThiriZaw 2018년 6월 3일
댓글: Image Analyst 2020년 5월 2일
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