问题描述
我使用MATLAB生成了此图像(使用bwareaopen
).在中间,我有一个2D椭圆形.如何清除周围的所有噪音"并获得清晰的椭圆形?
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?
原始图片
推荐答案
看看这个解决方案.如评论中所述,我使用了 DoG-高斯差分
Have a look at this solution. As mentioned in the comments I used DoG - Difference of Gaussians
DoG是什么意思?
首先,您必须对图像使用两个独立的高斯,并使用两个独立的内核. (根据高斯,我的意思是应用高斯模糊).两种结果的差异称为 DoG .
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.
这就是我所做的:
- 将给定的量转换为灰度:
- 然后我应用了双边过滤来保留边缘并平滑非边缘:
- Then I applied bilateral filtering to preserve edges and smoothen non-edges:
(如果您专心看的话,您会发现其中的区别).
(If you look intently you can see the difference).
- 高斯模糊应用于上图:
- Applied Gaussian blur to the above image:
- 现在对上面的两个图像执行 DoG 来获得此图像:(我只减去了上面的两个图像)
- Now performed DoG with the above two images to obtain this: (I merely subtracted the two images above)
- 然后,我使用椭圆核进行了形态学操作,以增强单元格的边缘:
- Then I performed Morphological operation using the ellipse kernel to enhance the edge of the cell:
- 要去除图像周围不必要的斑点,我执行了中值滤波,并最终获得了此结果:
- To remove the unwanted speckles around the image I performed median filtering and finally obtained this:
您可以优化此过程以获得增强的图像.
You can refine this process to get an enhance image .
这是我使用的代码:
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()
这篇关于消除黑白图像中的噪点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!