0

im trying to identify a specific shade of green leaves (e.g. navy green) from the attached image. how do i do that in the most efficient way? So far, i'm converting the RGB to HSV and then thresholding the image based on some specific range of saturation and value that will isolate my desired shade. it's working on some images and it's just all over the place on others. i want something that can isolate a specific shade of green in any different image that has slightly different saturation and value (e.g. if the picture was taken with too much light) Image link

pic=imread('image.jpg');
q=rgb2hsv(pic);
H=q(:,:,1);
S=q(:,:,2);
V=q(:,:,3);
thresh=S>0.6111 & S<0.6666 & V>0.3888 & V<0.4583;
st=strel('diamond',20);
w=imdilate(thresh,st);
comps=bwconncomp(w,8);
num=comps.NumObjects;
fprintf('The number of leaves is %i',num)

% then i try to have some pointers on the image to show me where matlab has identified the the shade. m = regionprops(w,'centroid');

boxes = cat(1, m.Centroid); 

imshow(pic) 

hold on
plot(boxes(:,1),boxes(:,2), 'b*') 
hold off

Your help will be highly appreciated.

1 Answers1

0

Either the HSV color space (hey, S is saturation and V value), where H will give you the hue,or CIE-Lab color space, where euclidean distance will give you how close 2 specific pixel are to each other in color.

This answer explains how to do it for HSV: Segment pixels in an image based on colour (Matlab)

Using combined with CIE-LAB may help if the colors are very close together (like the greens in each leaf), but you should give HSV a shot

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Thank you @ander. I'm trying to use HSV, but its so tricky because every image has a different hue value. some target images have a hue that falls outside the range and if i change the range to accomodate them i end up thresholding non-target materials as well. slippery slope. – user3020881 Nov 21 '18 at 16:06
  • 1
    @user3020881 yup, you may need to use other object detection techniques together with color information, such as level sets or watershed ot even playing with canny – Ander Biguri Nov 21 '18 at 17:34