I'm trying to subtract the background of an image with two images.
Image A
is the background and image B
is an image with things over the background.
I'm normalizing the images but I don't get the expected result. Here's the code:
a = rgb2gray(im);
b = rgb2gray(im2);
resA = ((a - min(a(:)))./(max(a(:))-min(a(:))));
resB = ((b - min(b(:)))./(max(b(:))-min(b(:))));
resAbs = abs(resB-resA);
imshow(resAbs);
The resulting image is a completely dark image. Thanks to the answer of the user saeed masoomi, I realized that was because of the data type, so now, I have the following code:
a = rgb2gray(im);
b = rgb2gray(im2);
resA = im2double(a);
resB = im2double(b);
resAbs = imsubtract(resB,resA);
imshow(resAbs,[]);
The resulting image is not well filtered and there are parts of image B
that don't appear but they should.
If I try doing this without normalizing, I still have the same problem.
The only difference between image A
and B
are the arms that only appears in image B
, so they should appear without any cut.
Can you see something wrong? Maybe I should filter with a threshold?