MATLAB: Removing background by dividing

background removalimdivideMATLABpixel division

Hi,
I am trying to follow the example with background removal on this page, but obviously I am missing something. Here is what I have:
Image:
son1.gif
Background:
son2.gif
What I did in Matlab:
img = imread('son1.gif');
bg = imread('son2.gif');
img_d = im2double(img);
bg_d = im2double(bg);
imshow(uint8(imdivide(img_d, bg_d)))
which results to this:
res.png
or, after histogram equalisation, to this:
res_histeq.png
What am I doing wrong?

Best Answer

Okay, got it:
first I did not import the color profile (see this SO answer)
[img, cm] = imread('son1.gif');
img = ind2rgb(img, cm);
Then, I had to scale the result to get in the representable range:
imshow(uint8(imdivide(img_d, bg_d) * 100))
which shows the correct output:
res_correct.png