Automatic approach for removing colord object shadow on white background?

Viewed 5128

I am working on some leaf images using OpenCV (Java). The leaves are captured on a white paper and some has shadows like this one:

enter image description here

Of course, it's somehow the extreme case (there are milder shadows).

Now, I want to threshold the leaf and also remove the shadow (while reserving the leaf's details).


My current flow is this:

1) Converting to HSV and extracting the Saturation channel:

Imgproc.cvtColor(colorMat, colorMat, Imgproc.COLOR_RGB2HSV);
ArrayList<Mat> channels = new ArrayList<Mat>();
Core.split(colorMat, channels);
satImg = channels.get(1);

2) De-noising (median) and applying adaptiveThreshold:

Imgproc.medianBlur(satImg , satImg , 11);
Imgproc.adaptiveThreshold(satImg , satImg , 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 401, -10);

And the result is this:

enter image description here

It looks OK, but the shadow is causing some anomalies along the left boundary. Also, I have this feeling that I am not using the white background to my benefit.

Now, I have 2 questions:
1) How can I improve the result and get rid of the shadow?

2) Can I get good results without working on saturation channel?. The reason I ask is that on most of my images, working on L channel (from HLS) gives way better results (apart from the shadow, of course).


Update: Using the Hue channel makes threshdolding better, but makes the shadow situation worse:

enter image description here


Update2: In some cases, the assumption that the shadow is darker than the leaf doesn't always hold. So, working on intensities won't help. I'm looking more toward a color channels approach.

3 Answers
Related