Hi all,
I am new to Matlab. I need to know how to use a filter to eliminate non-uniformity in an image.

11 件のコメント

Ank
Ank 2014 年 8 月 28 日
I can help you get started.
close all;
I = imread('11.png');
I = rgb2gray(I);
H = fspecial('disk',8);
background = imopen(I,strel('disk',40) );
background = imfilter(background,H,'replicate');
I2 = I - background;
background = imopen(I2,strel('disk',50) );
background = imfilter(background,H,'replicate');
I3 = I2 - background;
I4 = imadjust(I3);
figure;imshow(I4);
Ank
Ank 2014 年 8 月 28 日
More hint
close all;
I = imread('11.png');
I = rgb2gray(I);
H = fspecial('disk',10);
background = imopen(I,strel('disk',77) );
background = imfilter(background,H,'replicate');
I2 = I - background;
background = imopen(I2,strel('disk',77) );
background = imfilter(background,H,'replicate');
I3 = I2 - background;
I4 = imadjust(I3);
I5 = medfilt2(I4,[30 30]);
I5 = I5-I4;
I5 = imcomplement(imadjust(I5));
figure;imshow(I5,[]);
Ank
Ank 2014 年 8 月 28 日
Ok i am virtually telling u the answer replace the med filter with some low pass.
close all;
I = imread('11.png');
I = rgb2gray(I);
I2 = medfilt2(I,[20 20]);
I3 = I2-I;
I3 = imcomplement(imadjust(I3));
figure;imshow(I3,[]);
Siam
Siam 2014 年 8 月 28 日
編集済み: Siam 2014 年 9 月 2 日
I am really impressed for your great suggestion. However; the resultant image of your code does not appear similar to the actual resultant image.
Ank
Ank 2014 年 8 月 28 日
Yes. I has posted the first 2 just as some hints. The 3rd one is the closes to the answer. Your approach is correct but u can see from the result that median filter works better. Median filter is also a kind of low pass filter it is not linear that all. I guess after the results of the 3rd answer you need to process your image further like using local thresholding etc depends on what you want to do with it.
Ank
Ank 2014 年 8 月 28 日
close all;
I = imread('11.png');
I = rgb2gray(I);
h = fspecial('gaussian',20,3);
I2 = imfilter(I,h);
%I2 = medfilt2(I,[20 20]);
I3 = I2-I;
I3 = imcomplement(imadjust(I3));
figure;imshow(I3,[]);
I = imread('11.png');
I = rgb2gray(I);
I2 = medfilt2(I,[20 20]);
I3 = I2-I;
I3 = imcomplement(imadjust(I3));
I4 = bradley(I3);
I3 = bradley(I);
I3 = I3+I4;
figure;imshow(I3,[]);
so thing something in similar lines
Ank
Ank 2014 年 8 月 28 日
編集済み: Ank 2014 年 8 月 28 日
imcomplement is is used as i am subtracting. check the alternative i posted for color. should be the same for color if you process it on V. I guess u cannot threshold on the V there.
close all;
OI = imread('1.JPG');
OI = rgb2hsv(OI);
I = OI(:,:,3);
h = fspecial('gaussian',20,30);
I2 = imfilter(I,h);
I3 = -I2+I;
I3 = I3-min(min(I3));
OII= OI;
OII(:,:,3) = I3;
figure;imshow(hsv2rgb(OII));
I = OI(:,:,3);
I2 = medfilt2(I,[20 20]);
I3 = -I2+I;
I3 = I3-min(min(I3));
II = I3;
I4 = bradley(I3);
I3 = bradley(I);
I3 = I3+I4;
OI(:,:,3) = II;
figure;imshow(hsv2rgb(OI));
Siam
Siam 2014 年 9 月 4 日
I have fixed the issue I was having.
Siam
Siam 2014 年 9 月 4 日
Thank you very much.
Siam
Siam 2014 年 9 月 7 日
How to measure window size?
Image Analyst
Image Analyst 2014 年 9 月 8 日
Use trial and error until you get some output that you're happy with.

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2014 年 8 月 28 日

1 投票

Siam, you really need to understand what process gave rise to the non-uniform background. This will help you decide what algorithm to use. But there are rules of thumb. For most situations finding the background and then dividing the image by the background is the proper way to go. For certain other instances (radiology, fluorescence microscopy, etc.) background subtraction is the best way. The best way to get a background is to snap a "blank shot" of just the background with no sample(s) in there are all. If you have samples in there, you can try to get rid of them by morphology (opening or closing) or just a global fitting. Morphology can follow local variations better than regression but can introduce undesirable artifacts. What I do is to fit the image of a uniform background to a 2D polynomial and then divide - that's what works best in my situation. You can do a local regression with a Savitzky-Golay filter but I find that in most cases where you're illuminating something with a lamp, the uneven light pattern is very broad and smooth and does not vary on a rapid basis, so a process that scans the image with a small local window just ends up giving you noise. A global fit will totally and effectively remove all video noise. See my attached demo where I use John D'Errico's polyfitn (which you need to get from the File Exchange here - be sure to check out John's other useful utilities while you're there.
For color images, usually you want to convert to HSV and correct only the V channel. This will avoid color artifacts that you might get if you correct the red, green, and blue channels independently.
I also attach a Savitky-Golay filter but it just does it in each direction and is not what you'd get if you did a true 2D fit at every window location, which you can again use John's polyfitn() for if you want/need to follow background non-uniformities more closely.

8 件のコメント

Ank
Ank 2014 年 8 月 28 日
For your case the light variation can somewhat be approximated well by a polynomial thus using Image Analyst's method would the best (mine is more general case but would have artifacts that might require more morphological techniques).
Image Analyst
Image Analyst 2014 年 8 月 28 日
Regarding the astronomical image, just call rgb2hsv, then v=hsv(:,:,v), then use the polyfitn code and see how it goes. But I did not see your microscope images attached. By the way, there is a whole body of work on haze removal - you can find papers at Vision Bib http://www.visionbib.com/bibliography/contents.html and those methods might be better for the astronomy images than background removal methods.
Siam
Siam 2014 年 8 月 28 日
編集済み: Siam 2014 年 8 月 29 日
Here is an image. Please have a look and suggest me with a code if possible. Thank you.
Image Analyst
Image Analyst 2014 年 8 月 28 日
You might convert to hsv then run adapthisteq() on the v channel.
Siam
Siam 2014 年 8 月 28 日
Thank you for the suggestion however; adapthisteq will fix the contrast issues not the illumination. Please do correct me if I am wrong because equalization does enhances contrast right? Thank you.
Image Analyst
Image Analyst 2014 年 8 月 28 日
It will also "flatten" the background. Not sure what you consider to be the background here so that's why I suggested that. Not even sure how to get an estimate of the background because there is so much clutter in the image. If it's a transmitted microscope image, why can't you just snap a blank shot to get the background?
Image Analyst
Image Analyst 2014 年 8 月 28 日
Remove your slide with your sample on it (the cells or whatever). Just put in a totally clean slide and take a picture of the light coming through.
Image Analyst
Image Analyst 2014 年 8 月 29 日
Why do you think you need to correct for background anyway? What do you actually want to measure?

サインインしてコメントする。

その他の回答 (1 件)

Spandan Tiwari
Spandan Tiwari 2014 年 8 月 28 日

0 投票

The classical homomorphic filtering might be able to help here. See the following blog post on the blog Steve on Image Processing for details.

3 件のコメント

Siam
Siam 2014 年 8 月 29 日
Thank you Spandan. I have seen that and if I am not wrong that is based on high-pass filter.
Image Analyst
Image Analyst 2014 年 8 月 29 日
Yes, Basically it assumes that the really, really blurred version of the image is the background or illumination pattern.
Siam
Siam 2014 年 8 月 29 日
Thank you for your suggestion.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2014 年 8 月 28 日

コメント済み:

2014 年 9 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by