How to subtract a 16 bit image from 8 bit image?

How to subtract a 16 bit image from 8 bit image?

4 Comments

kumar - please provide more details on what you are trying to accomplish. Why would you want to subtract a 16-bit image from an 8-bit one? What problem are you trying to solve, and have you written (or made an attempt at writing) any code?
What is the range of values that the 16-bit image takes on? Are they in the 0-255 range, or are they greater than that?
I am attaching two images. One of them is 8 bit and other one is 16 bit. Background_subtract image is an 8bit image which I get as background from an infrared camera and after my experiment I get another image named L3_cavity_emission. I would like to remove the background but I couldn't succeed as I saved both image in different bits. Can you help me with it please?
16-bit image range is from 0 to 2^16-1. 0-255 is range for 8 bit image.

Sign in to comment.

Answers (2)

Then, if the 16 bit image takes up the whole range, just read in the 16 bit image and divide by 256. Then subtract the 8 bit image from that, or vice versa. Cast to double if you want to get both positive and negative numbers.

2 Comments

I did this but then maximum of converted image if not 255 anymore. It's close to 60. Here is the code that I am using
a = imread('background_subtract.png');
b = imread('L3_cavity_emmison.png');
b8 = round(double(b)/255);
a8=a(:,:,1);
newimage=uint8(b8-double(a8));
image(newimage)
colormap 'gray'
To scale each image to between 0 and 255, try this:
a8 = uint8(255*mat2gray(a));
b8 = uint8(255*mat2gray(b));
differenceImage = b8-a8;
imshow(differenceImage, []);
colormap(gray(256));

Sign in to comment.

a = imread('background_subtract.png');
b = imread('L3_cavity_emmison.png');
a = double( a(:,:,1) ) * 255;
diff = double(b) - a;
That seems to remove the background as expected when I tried it just now. Going the other way down to 8-bit size should work equally well so long as you cast to doubles in the right place and don't do maths as integer before the cast.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 28 Aug 2014

Commented:

on 28 Aug 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!