Ask Your Question

Image Segmentation - Cleaning up

asked 2017-11-07 16:23:40 -0500

warkan gravatar image

updated 2017-11-09 03:12:29 -0500

LBerger gravatar image

Hey Guys! I was just trying to segment the following image:


I tried using a median filter to clean up the noise but I am not able to get a clear distinct segmented image. The objective is to be able to segment the crops from the soil.

This is the best I could get after using a median filter:


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-11-08 02:45:59 -0500

VxW gravatar image

updated 2017-11-09 03:07:16 -0500


Why do you convert the image into grayscale? I think the most information is in the RGB image.

I have tried the following

1) use ony red channel

image description

2) apply median

image description

3) edge detection

image description

4) now you can apply maybe some morphological operations, machine learning, pattern matching, and more...

######################## Update

so the new images are looking a little bit different in color. So be careful that the setting is always the same. Otherwise you will need more sophisticated techniques like deep learning.

1) For the new image I have used the blue channel (use the color which is the lowest one):

image description

2) then median filter with size 11:

image description

3) a minimum filter with size 21:

image description

4) Threshold the image with thresh e.g. 33

image description

based on this you can calculate blob size and more.

The main problem is not to get this for one image but to design an algorithm which generalize for many.

edit flag offensive delete link more


Hey! So I tried converting it to grayscale originally because I wanted to perform 'Image segmentation' which is easier done on a grayscale image. But, from the looks of it maybe segmentation is not required. I tried running through your steps with the following image:


I tried two different filters: Median and Gaussian C:\fakepath\median_Canny_edge.JPGC:\fakepath\Gaussian_edge_canny.JPG

I want to be able to clearly differentiate between the larger and smaller crops seen in the image(There is one small crop found in the image.) Also, the crops in the right and left are not being detected fully. Any idea how to get around this? Thanks in advance :)

warkan gravatar imagewarkan ( 2017-11-09 00:24:05 -0500 )edit

Yeah, you are right! I need to be able to use this algorithm for about 500 images. I am also starting to think about deep learning now.. And your algorithm works well for bigger crops. How about the smaller one which I have circled in the same image? It is really important that I need to differentiate them both.


warkan gravatar imagewarkan ( 2017-11-09 03:22:32 -0500 )edit

for the small plants I would say it's a challenging task with standard methods but possible using deep learning. The most important step in deep learning is to generate a reliable image database and this could be the problem because you will need ten thousand and more image with and without plants. If you have this take the rgb image, crop some small patches e.g. 80x80 pixels and use a e.g. UNET for semantic segmentation.

VxW gravatar imageVxW ( 2017-11-09 03:49:02 -0500 )edit

If you haven't so much images a solution could be to use as a first machine learning attempt a pattern matching algorithm

VxW gravatar imageVxW ( 2017-11-09 03:55:46 -0500 )edit

When you say crop small patches of 80 by 80 pixels, do you mean crop the individual plants to that size and use that an input to a CNN? Also, if we were to use a CNN. won't the image size be 80 by 80 by 3(channels)?

I certainly do not have that many images. I could perhaps get around 1000 reliable images though. Do you reckon deep learning using CNN will help solve this image segmentation problem? I am a little new to this field of AI and Machine/Deep Learning.

warkan gravatar imagewarkan ( 2017-11-10 19:18:02 -0500 )edit

the size of the patches was only an example size. In the end the size depends on the model you have, that means, take a pretrained model and scale/crop the images to the inputsize of the model. A pretrained model can be found e.g. here

You can also take a ready to use dataset e.g.:

There is no minimum of images you need, but the more the better

VxW gravatar imageVxW ( 2017-11-13 04:16:01 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-11-07 16:21:57 -0500

Seen: 462 times

Last updated: Nov 09 '17