0

your help is much appreciated. I am using C# and EmguCV for image processing

I have tried noise removal, but nothing happens. I also tried image median filter, and it only works on the first image, but it does not work on the second image. It only makes the second image blurry and the objects larger and more square-like.

I want to remove obviously distinct objects(green ones) in my image below so that it would turn all black because they are obviously separated and are not grouped unlike the second image below.

Image 1:

It said that i need 10 reputation to post images, so this is image 1 :(

At the same way, I want to do it in my image below, but remove only those objects -- (the black ones) -- that are not grouped/(lumped?) so that what remains on the image are the objects that are grouped/larger in scale?

Image 2:

It said that i need 10 reputation to post images, so this is image 2 :(

Thank you

Ryan Hu
  • 342
  • 3
  • 18

2 Answers2

0

You may try Gaussian Blur and then apply Threshold to the image.

Gaussian Blur is a widely used effect in graphics software, typically to reduce image noise and reduce detail, which I think matches your requirements well.


For your 1st image:

CvInvoke.GaussianBlur(srcImg, destImg, new Size(0, 0), 5);//You may need to customize Size and Sigma depends on different input image.

You will get:

enter image description here

Then

CvInvoke.Threshold(srcImg, destImg, 10, 255, Emgu.CV.CvEnum.ThresholdType.Binary);

You will get:

enter image description here


For your 2nd image:

CvInvoke.GaussianBlur(srcImg, destImg, new Size(0, 0), 5);//You may need to customize Size and Sigma depends on different input image.

You will get:

enter image description here

Then

CvInvoke.Threshold(srcImg, destImg, 240, 255, Emgu.CV.CvEnum.ThresholdType.Binary);

You will get:

enter image description here

Hope this help!

Community
  • 1
  • 1
Ryan Hu
  • 342
  • 3
  • 18
  • Sorry for the late reply, our internet connection was down for almost 2 days. On the first image, I dont want to blur it out, but the result is what i wanted. On the second image, I also dont want to blur it out because my desired output is not full green. I just want to turn the distinct little 'spots' on the image so that what remains in the image are the large spots – duwmy fang Sep 15 '16 at 04:06
0

You should first threshold the image using Otsus method. Second run connected component analysis on the threshold image. Third go over all the component that you found and for the ones that have a size that is smaller than some min size delete it from the original image.

  1. cvThreshold (with CV_THRESH_BINARY/CV_THRESH_BINARY_INV(choose according to the image) + CV_THRESH_OTSU) http://www.emgu.com/wiki/files/1.3.0.0/html/9624cb8e-921e-12a0-3c21-7821f0deb402.htm + http://www.emgu.com/wiki/files/1.3.0.0/html/bc08707a-63f5-9c73-18f4-aeab7878d7a6.htm
  2. CvInvoke.FindContours (RetrType == External,ChainApproxNone)
  3. For each contour that we found in 2 calculate CvInvoke.ContourArea
  4. If area is smaller than minArea draw on the original image(The one you want to filter) the value you want for them(0 I suppose) in the original image using CvInvoke.DrawContours with the current contour and with thickness==-1 to fill the inside of the contour.
Amitay Nachmani
  • 3,259
  • 1
  • 18
  • 21
  • I have already used binary thresholding using this code Image img_colour = new Image(new Bitmap(pBox.Image)); img_colour = img_colour.ThresholdBinary(new Gray(100), new Gray(255)); but i cant seem to work the cv thresh otsu for Emgu 3.0 and I tried to use this code i found [here][1] thanks a lot for your help, and i appreciate it very much [1]: http://stackoverflow.com/questions/25989754/what-is-the-function-to-find-otsu-threshold-in-emgu-cv – duwmy fang Sep 15 '16 at 04:25
  • So exclude step 1 – Amitay Nachmani Sep 15 '16 at 04:27
  • I accidentally clicked add comment, please check for edit, sir. thank you – duwmy fang Sep 15 '16 at 04:30
  • You need this line of code CvInvoke.cvThreshold(Img_EgdeNR_Gray.Ptr, Img_Otsu_Gray.Ptr, 0, 255, Emgu.CV.CvEnum.THRESH.CV_THRESH_OTSU | Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY); – Amitay Nachmani Sep 15 '16 at 04:33
  • I already did that like this, but there is an error. https://postimg.org/image/mydhrogzd/ – duwmy fang Sep 15 '16 at 04:41
  • Update: I have already fixed it and used Binary Thresholding then Otsu Thresholding, but I am confused. The results were the same when I only used Binary thresholding, so why still use otsu thresholding after binary thresholding? I dont know how to do step 2 - 4 :( Your guidance to me is very much appreciated, sir. thank you https://postimg.org/image/3s917dwg7/9b178f16/ – duwmy fang Sep 15 '16 at 04:55
  • First i think you can't do it one after the other. You need to use the command with both. But if the threshold image looks fine you can just use the binary thresholding. – Amitay Nachmani Sep 15 '16 at 05:12
  • For step 2 please refer to http://www.emgu.com/wiki/files/3.0.0/document/html/cb24a129-d9ce-57f3-19ad-0eaa27a77317.htm. The input image is the output of the threshold. – Amitay Nachmani Sep 15 '16 at 05:14
  • Hello, we lost our internet connection before I was able to reply to you. Last Thursday, I have found other links in stackoverflow (http://stackoverflow.com/questions/24970577/finding-contour-points-in-emgucv) about contours and have found one example in codeproject, but i really have a hard time understanding it. Tbh, I am a newbie in image processing. I am stuck with this(http://postimg.org/image/8gibmjczz/) as of this night, please elaborate further :( Thank you so much! – duwmy fang Sep 19 '16 at 17:45
  • UPDATE: I have tried doing what you instructed me, but I am not sure if what I did is correct since I hurried up my research. This is what it looks like from the first process up to the third (http://postimg.org/image/508sjsosb/) and this is what I did on the code based from combined examples from emgu forum and stackoverflow. (http://postimg.org/image/ks4evr9s5/). I dont understand the drawing part and I dont want to continue yeet if Im wrong at step 3. Please elaborate further on step 3 - 4 pls :( Hoping for your sincere reply of guidance later today, sir. THANK YOU SO MUCH!!! – duwmy fang Sep 19 '16 at 19:08
  • step 3 calculate the size of each component using counter area. Step 4 If the area is smaller than some predefined threshold you can draw it in a new image. If there is more specific question you can ask and i will try to help – Amitay Nachmani Sep 19 '16 at 20:33
  • Hello, sir. Did I do what is right on the second step? Also, I don't understand what you mean by "counter area", sir. If you have much time, can you please explain it to me much further or show it into code snippets with comments? Thank you – duwmy fang Sep 20 '16 at 03:30