Thread Subject: Background Illumination

Subject: Background Illumination

From: Smith Kumar

Date: 19 Jul, 2009 16:36:01

Message: 1 of 6

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)

Subject: Background Illumination

From: ImageAnalyst

Date: 19 Jul, 2009 18:16:38

Message: 2 of 6

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

Subject: Background Illumination

From: Ashvin

Date: 20 Jul, 2009 08:30:32

Message: 3 of 6

On Jul 20, 4:16 am, ImageAnalyst <imageanal...@mailinator.com> wrote:
> 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

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]);

Subject: Background Illumination

From: Smith Kumar

Date: 20 Jul, 2009 15:11:02

Message: 4 of 6


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

Subject: Background Illumination

From: Smith Kumar

Date: 21 Jul, 2009 04:30:19

Message: 5 of 6

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

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

Subject: Background Illumination

From: ImageAnalyst

Date: 21 Jul, 2009 04:42:07

Message: 6 of 6

On Jul 21, 12:30 am, "Smith Kumar " <nkm...@gmail.com> wrote:
> > figure, imshow(I2,[]);-Good Image
> > figure, imshow(I2);-Dark Image
>
> Basically when I use imwrite((I2,[]), '1.bmp')  ----I am getting an error

--------------------------------------------
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.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com