Hi, i want to correct the non uniform background noise form the image to remove the dependency of the background.I tried the code which is attach but it does not work.Please help me

6 次查看(过去 30 天)
Hi, i want to correct the non uniform background noise form the image to remove the dependency of the background.I tried the code which is attach but it does not work.Please help me

回答(1 个)

DGM
DGM 2022-2-9
编辑:DGM 2022-2-9
That looks like one of IA's demos that's been tinkered with. Since whoever messed with it has left a bunch of obvious typos in it and the OP is long gone, I'm not going to bother fixing that.
To answer the general question, there are various ways depending on the image and the goals.
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/168296/image.jpeg');
A = rgb2gray(A);
A = imresize(A,0.5); % not going to bother with giant images for a demo
% use grayscale bottomhat filter to estimate BG, subtract
B = imcomplement(imbothat(A,strel('disk',50)));
imshow(B)
%% use imflatfield
C = imflatfield(A,100);
imshow(C)
%% use basic blurring and division
% this is fundamentally the same as imflatfield()
sg = 100;
fk = fspecial('gaussian',[1 1]*2*ceil(3*sg-0.5)+1,sg);
Ad = im2double(A);
m = imfilter(Ad,fk,'replicate');
D = mean(m(:))*Ad./m;
imshow(D)
Once at that point, the image levels can be adjusted with imadjust() or the image can be binarized and cleaned up with basic morphological operations.
ImageAnalyst's demo and his own answer can be found here:
See also:
The lesson that nobody seems to learn from these exercises is to take every chance you can to make sure your photographic staging gives you uniform lighting and good subject-background contrast in the first place. You can either spend an hour trying to make a precarious stack of filters in an attempt to accurately and repeatably extract a white object from a white background ... or you can spend 30 seconds to use a black piece of paper instead.
  1 个评论
Image Analyst
Image Analyst 2022-2-16
That last paragraph cannot be emphasized enough! So true!
Even if you do have uniform lighting, your lens will introduce lens shading so you still need to do background correction.
Another nice trick if you have shine, glare, or specular reflection problems is to have a polarizer in front of your lights, and another rotatable one in front of your camera lens. Rotate the polarizer on the lens to reduce or eliminate the specular reflections.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by