1

I used MATLAB to generate this image (using bwareaopen). In the middle I have a 2D ellipsoid. How can I clear all the "noise" surrounding of it and get a clear ellipsoid?

enter image description here

original image

enter image description here

elyraz
  • 473
  • 5
  • 18

1 Answers1

3

Have a look at this solution. As mentioned in the comments I used DoG - Difference of Gaussians

What does DoG mean ?

First you have to take two separate Gaussians of an image with two separate kernels. (By Gaussian I mean apply ing gaussian blur). The difference of the two resultants is called the DoG.

This is what I did:

  • Converted the given umage to gray scale:

enter image description here

  • Then I applied bilateral filtering to preserve edges and smoothen non-edges:

enter image description here

(If you look intently you can see the difference).

  • Applied Gaussian blur to the above image:

enter image description here

  • Now performed DoG with the above two images to obtain this: (I merely subtracted the two images above)

enter image description here

  • Then I performed Morphological operation using the ellipse kernel to enhance the edge of the cell:

enter image description here

  • To remove the unwanted speckles around the image I performed median filtering and finally obtained this:

enter image description here

You can refine this process to get an enhance image .

EDIT:

Here is the code I used:

import cv2

filename = 'Cell.jpg'
img = cv2.imread(filename)
cv2.imwrite('img.jpg',img)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imwrite('gray.jpg',gray)

bi = cv2.bilateralFilter(gray,7,75,75)
cv2.imwrite('bi.jpg',bi)
blur = cv2.GaussianBlur(bi,(3,3),0)
cv2.imwrite('blur.jpg',blur)
blur1 = cv2.GaussianBlur(bi,(17,17),0)
dog = blur1 - bi
cv2.imwrite('DoG.jpg',dog)

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
close = cv2.morphologyEx(dog, cv2.MORPH_CLOSE, kernel, 13)
cv2.imwrite('close.jpg',close)

median = cv2.medianBlur(close,3)
cv2.imwrite('median.jpg',median)

cv2.waitKey(0)
cv2.destroyAllWindows()   
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
  • Very impressive. I will appreciate a lot if you can share the code – elyraz Jan 21 '17 at 18:54
  • Unfortunately I do not work with MATLAB. But just follow the steps as mentioned in the answer. You have built-in functions for all the above steps. – Jeru Luke Jan 22 '17 at 04:55
  • Is there a way to close the object in python-openCV so I can have the ellipsoid outlines? Thanks – elyraz Jan 24 '17 at 10:42
  • I actually tried out **morphological close operation** but was not successful. You can check out [THIS PAGE](http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html#morphological-ops) for other options. – Jeru Luke Jan 24 '17 at 11:50
  • @user2788464 I woud also suggest doing some pre-processing to the image before trying the above code. Try *equalization* and *local adaptive histogram equalization* – Jeru Luke Jan 24 '17 at 12:01
  • Thanks. I will examine these options but the thresholding options in Matlab were not successful. In general, I try to avoid morphological operation as I need the dimension of the cell. – elyraz Jan 24 '17 at 12:44
  • @user2788464 Sure, give it a try and do post your results as well. :) – Jeru Luke Jan 24 '17 at 12:45
  • Jeru Luke I was looking again on the code and I noticed that you have blur and blur1, why? – elyraz Jan 24 '17 at 18:22
  • Initially I thought of doing DoG using `blur` which had a kernel size of 3; the result was not so prominent. Then I used `blur1` which had a kernel size of 17; hence I was able to obtain better result. Try doing DoG for both `blur1 - bi` and `blur - bi`; you will notice the difference – Jeru Luke Jan 24 '17 at 18:26