Solution question 2

function [ NombrePoisBons,NombrePoisPourris] = JeCompteEnCouleur( Image, Taille )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here



ImRouge=Image(:,:,1);
ImVert=Image(:,:,2);
ImBleu=Image(:,:,3);

NbVert = 0;
NbPourris = 0;
 
SeuilVert = 127;
SeuilAutre = 50;

[Xnb,Ynb,NbPlan] =  size(Image);

for lig = 1 : Xnb
    for col = 1 : Ynb
          
        if ((ImVert(lig,col) > SeuilVert) && ((ImRouge(lig,col) < SeuilAutre) && (ImBleu(lig,col) < SeuilAutre) && ((ImRouge(lig,col)+ ImBleu(lig,col) < SeuilAutre))))
            NbVert = NbVert+1;
        end
        if ((ImRouge(lig,col) >= SeuilAutre) ||(ImBleu(lig,col) >= SeuilAutre) ||(ImRouge(lig,col)+ ImBleu(lig,col) >= SeuilAutre))
            NbPourris = NbPourris+1;
        end
    end
end
NombrePoisBons = round(NbVert/Taille);
NombrePoisPourris = round(NbPourris/Taille);


end