Background Illumination

Background Illumination

Post by Smith Kuma » Tue, 21 Jul 2009 01:36:01


hello everyone,

I am trying to subtract the background illumination from an image using the following:

Mean of each 16 16 small block constitute a coarse estimate of the background illumination.

This estimate is expanded to the same size as the normalizedimage by bicubic interpolation.

The estimated background illumination is subtracted from the Original image to compensate for a variety of lighting conditions.

Enhance the lighting corrected image by means of histogram equalization in each 32 32 region.


I am trying the following but my output is a completely dark image?????

Many thanks in advance.

I = imread('image.jpg');
backApprox = blkproc(I,[16,16 ],'mean(x(:))');
backApprox = (backApprox)/255; % Convert image to double.
figure, surf(backApprox);
set(gca,'ydir','reverse'); % Reverse the y-axis.
backApprox256 = imresize(backApprox, [64 512], 'bicubic');
figure, imshow(backApprox256) % Show resized background image.
I = im2double(I); % Convert I to storage class of double.
I2 = I - backApprox256; % Subtract the background from I.
I2 = max(min(I2,1),0); % Clip the pixel values to the valid range.
figure, imshow(I2)
 
 
 

Background Illumination

Post by ImageAnaly » Tue, 21 Jul 2009 03:16:38

Smith Kumar :
You probably forgot to put [] in your imshow() function to scale your
double to the display range. Try this:
clc;
close all;
workspace;
I = imread('C:\Program Files\MATLAB\R2008b\toolbox\images\imdemos
\rice.png');
I = uint8(I);
subplot(2,2,1);
imshow(I);
kernel = ones(16,16) / (16*16);
backApprox = imfilter(I, kernel);
subplot(2,2,2);
imshow(backApprox, []);
I = im2double(I); % Convert I to storage class of double.
backApprox = im2double(backApprox); % Convert backApprox to storage
class of double.
I2 = I - backApprox; % Subtract the background from I.
subplot(2,2,3);
imshow(I2, [])
I2(I2<0) = 0; % Clip the pixel values to the valid range.
subplot(2,2,4);
imshow(I2, [])
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.


But you really need to decide if background subtraction is what you
want to do. It usually isn't, except in radiography (e.g. digital
subtraction angiography). Most cases should use background division.
After all, if the corner of your image has 90% of the light incident
on it, wouldn't you want to divide by 0.9 at those pixels? Sure you
would. If you're not doing intensity analysis of the objects but are
just doing shape analysis then subtraction can work OK to give you the
object masks (binary image of where you objects are in your image).
Regards,
ImageAnalyst

 
 
 

Background Illumination

Post by Ashvi » Tue, 21 Jul 2009 17:30:32


Thanks ImageAnalyst ... works great....


Now the problem I am facing is that I need to save the image and
perform histtogram equaliuzation on it but I am getting an error on
saving it as (I2, [])

Also I need to perform histogram equalization on 32*32 blocks of the
image.. is this the right approach or is there a better way...

I3=histeq(I2, [32 32]);
 
 
 

Background Illumination

Post by Smith Kuma » Tue, 21 Jul 2009 18:41:01

hello everyone,

I am trying to subtract the background illumination from an image using the following:

Mean of each 16 16 small block constitute a coarse estimate of the background illumination.

This estimate is expanded to the same size as the normalizedimage by bicubic interpolation.

The estimated background illumination is subtracted from the Original image to compensate for a variety of lighting conditions.

Enhance the lighting corrected image by means of histogram equalization in each 32 32 region.

I need to save the image and perform histeq but I am getting an error on saving :

I3=(I2,[]);
I4=histeq(I3,[32,32])



Many thanks in advance.

I = imread('image.jpg');
backApprox = blkproc(I,[16,16 ],'mean(x(:))');
backApprox = (backApprox)/255; % Convert image to double.
figure, surf(backApprox);
set(gca,'ydir','reverse'); % Reverse the y-axis.
backApprox256 = imresize(backApprox, [64 512], 'bicubic');
figure, imshow(backApprox256) % Show resized background image.
I = im2double(I); % Convert I to storage class of double.
I2 = I - backApprox256; % Subtract the background from I.
I2 = max(min(I2,1),0); % Clip the pixel values to the valid range.
figure, imshow(I2)

I = imread('image.jpg');
backApprox = blkproc(I,[16,16 ],'mean(x(:))');
backApprox = (backApprox)/255; % Convert image to double.
figure, surf(backApprox);
set(gca,'ydir','reverse'); % Reverse the y-axis.
backApprox256 = imresize(backApprox, [64 512], 'bicubic');
figure, imshow(backApprox256) % Show resized background image.
I = im2double(I); % Convert I to storage class of double.
I2 = I - backApprox256; % Subtract the background from I.
I2 = max(min(I2,1),0); % Clip the pixel values to the valid range.
figure, imshow(I2,[])
 
 
 

Background Illumination

Post by Smith Kuma » Wed, 22 Jul 2009 00:11:02


I wanted to know what is the difference between

imshow(I2, []) and imshow(I2)

I checked out your post on Background Illumination and the image is dark when using only imshow(I2) while the image is great when using imshow(I2, [])

The problem I am facing now is that I want to use the good image and perform histeq on it ....

But when using

I3=(I2,[]) -----Error

I3=histeq(I2,[])---Error...

How to pass on the good image to another variable so that I can perform other operations on it...

Can you please help me... I am new to matlab....


Thanks a lot...


The code I am using:

I = imread('image.jpg');
backApprox = blkproc(I,[16,16 ],'mean(x(:))');
backApprox = (backApprox)/255; % Convert image to double.
figure, surf(backApprox);
set(gca,'ydir','reverse'); % Reverse the y-axis.
backApprox256 = imresize(backApprox, [64 512], 'bicubic');
figure, imshow(backApprox256) % Show resized background image.
I = im2double(I); % Convert I to storage class of double.
I2 = I - backApprox256; % Subtract the background from I.
I2 = max(min(I2,1),0); % Clip the pixel values to the valid range.

figure, imshow(I2,[]);-Good Image
figure, imshow(I2);-Dark Image
 
 
 

Background Illumination

Post by Smith Kuma » Wed, 22 Jul 2009 13:30:19

> figure, imshow(I2,[]);-Good Image

Basically when I use imwrite((I2,[]), '1.bmp') ----I am getting an error
 
 
 

Background Illumination

Post by ImageAnaly » Wed, 22 Jul 2009 13:42:07


--------------------------------------------
Get rid of the []. Scale your image manually or use imadjust().
And pick one thread and go with it. It's ridiculous to keep 3 threads
going on the same topic.