MATLAB: How to correct inhomogeneous intensity in image

background correctioncorrectign inhomogeneous intensityflat fieldImage Processing Toolbox

Dear,
I am new to MATLAB, i need some help from you guys.The below image has inhomogeneous intensity distribution, the intensity is max at the top and it is decreasing linearly as it is going down.
  • Idea was to consider the small portion of the images top corner and bottom corner and to loop through those pixels, get the intensity difference and set it to the max intensity value.
  • for example if the intensity is getting reduced in step of 5 after reaching center of the image than see the difference and correct it by adding that difference
Thank you in advance
The image:

Best Answer

I = im2double(imread('blob.bmp'));
y = mean(I(:, 1:100), 2);
sigma = 30; % choosen by visual inspection
G = fspecial('gaussian', 3*sigma+1, sigma);
yb = imfilter(y, G, 'replicate');
Ic = bsxfun(@plus, I, yb(1) - yb);
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(Ic)