Automatic approach for removing colord object shadow on white background?
image-processing, opencv
Solution
I don't use opencv, instead I was trying to use matlab image processing toolbox to extract the leaf. Hopefully opencv has all the processing functions for you. Please see my result below. I did all the operations in your original image channel 3 and channel 1.
First I used your channel 3, threshold it with 100 (left top). Then I remove the regions on the border and regions with the pixel size smaller than 100, filling in the hole in the leaf, the result is shown in right top.
Next I used your channel 1, did the same thing as I did in channel 3, the result is shown in left bottom. Then I found out the connected regions (there are only two as you can see in the left bottom figure), remove the one with smaller area (shown in right bottom).
Suppose the right top image is I1, and the right bottom image is I, the leaf is extracted by implement `~I && I1`. The leaf is:
Hope it helps. Thanks
Problem
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: 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: 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: 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.