how to remove speckles from image?

Hi All
i have an image . its a pupil image of an optical system. If i use a large aperture in front of my source ( 200 um-so a finite source), then my image at pupil looks uniform and i can easily see defects/contamination in the image. however if i use a much smaller apertur right in front of my source ( 6um), then in my pupil I see lots of laser speckle shape features . The algorithm I use for detecting defects works based on intensity drop, so the problem i have is that now algorithm gets confused and also takes speckles too as defects. i have example images ( please look at attached images, i have circled what i mean by defects and i want to only detect those). I think this phenomenan happens due to diffraction and nature of light. since small aperture makes my light source work light somewhat coherent light and causes diffraction so all features in the lens system can be seen. I hve averaged several images too but didnt work.
i have asked suport in matlab that what they told me but i am still not successful. I am not that good at matlab and am struggling. I would appreciate any help
"After reviewing the images, it seems that a a lot of the specks you mention can be handled by using morphological operations:
In addition, you can get a full list of all types of morphological filters available here:
The exact sequence of commands needed is hard to predict and it's something you will have to experiment with.
As a recommendation thresholding along with "imerode" and "imdilate" could help in the process.
With that being said, here is a page with a list of all available feature extractors that you can use:
"
thanks very much

11 Comments

Attach the original images, rather than screenshots.
attached are raw images of small and medium source aperture.pupil image is the same size.
"i have circled what i mean by defects and i want to only detect those" <== where are these circles? I see the circular field of view, and three gray circles between the lower images but I'm not sure what you want to detect and what you want to ignore. Do you just want to locate the dark spots on the light field of view? Have you tried flattening the image with adapthisteq() and then doing a global threshold?
in the first images i had ( image2) i have circled them. i have used 3*3 matrix to do a convlution but problem is that if i do this method it will sometimes also depending on intensity of defects, smoothen the defects which sometimes is ok if they are not too big particles/defects.but no i have not used adapthisteq
i have asked around some of my colleagues and they have suggested i use edge detection algorithm for the particles/defects instead of intensity threshold. do you think it makes sense?
so one update :
i used sobel in Matlab and just used it on my original image and this is what I got . seems promissing. i thought intensity drop wont help me much so i used edge detection instead.
now i have to find a total area of these defects ( not just one circle). also looks like lots of salt and pepper noise too that i have to get rid of.
So, I guess you now see why I suggested adapthisteq() followed by thresholding rather than the edge detection like your colleagues. Are your colleagues very experienced in image processing? Because saying to do edge detection is often the first thing novices suggest. There are several problems with edge detection that make it not suitable for this situation that a more experienced image analyst would have foreseen. So try it my way now and let me know how it goes.
unfortunately it got worse. I am not sure how to play with variables in " J = adapthisteq(I,Name,Value)"
see attached image. left one is after i used adapthisteq and then used same algo for thresholding.
image is right is thresholding without adapthisteq
Well the filtering you want to achieve is to keep structures with smaller spatial scales that have some magnitude above the speckle-level while reduce the speckles. That is kind-of the strength of the Lee's sigma-filter, wiener2 in matlab. At first I didn't think that would be the way forward considering the size of the speckles. However, if you force wiener2 to work with a set level for the noise it seems to work OK:
Im = double(imread('small.png'));
subplot(2,2,1)
imagesc(Im)
subplot(2,2,2)
D = wiener2(Im,[55,55],10000000/6);
imagesc(D)
subplot(2,2,3)
D = wiener2(wiener2(Im,[35,35],10000000/6),[35 35],1000000);
imagesc(D)
subplot(2,2,4)
D = wiener2(wiener2(Im,[35,35],10000000/6),[25 25],1000000);
imagesc(D)
So as you can see it is well possible to reduce/supress the speckles.
HTH
thanks very much Bjorn. It works great. I am not sure how to vote it as accepted answer but thanks a lot!
Ok, then I move it to an answer. Great that it worked. Obviously you'll have to tweak the filter-settings and check that it behaves as you want it to...

Sign in to comment.

 Accepted Answer

Well the filtering you want to achieve is to keep structures with smaller spatial scales that have some magnitude above the speckle-level while reduce the speckles. That is kind-of the strength of the Lee's sigma-filter, wiener2 in matlab. At first I didn't think that would be the way forward considering the size of the speckles. However, if you force wiener2 to work with a set level for the noise it seems to work OK:
Im = double(imread('small.png'));
subplot(2,2,1)
imagesc(Im)
subplot(2,2,2)
D = wiener2(Im,[55,55],10000000/6);
imagesc(D)
subplot(2,2,3)
D = wiener2(wiener2(Im,[35,35],10000000/6),[35 35],1000000);
imagesc(D)
subplot(2,2,4)
D = wiener2(wiener2(Im,[35,35],10000000/6),[25 25],1000000);
imagesc(D)
So as you can see it is well possible to reduce/supress the speckles.
HTH

More Answers (1)

If your solution is not to use a large apperture (Why? The example you've shown us seems to work for the large apperture.) then you might get something out of trying to remove the speckles in the Fourier-domain, this might work or not. You might want to window your image giving it a smooth transition from image to black background before doing the fft. Then you might have to suppress the frequency components corresponding to the speckles - this will be tricky since your objects-of-interest have very sharp edges and therefore a wide Fourier-spectrum. But I would give it a try.
HTH

1 Comment

Well, then you might find the attached function usefull, it is an implementation the interference-removal filter in chapter 5.7 of Gonzalez and Woods Digital Image Processing (1993). It should have a decent help-information. It might work for this case but I cannot guarantee a success.

Sign in to comment.

Products

Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!