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

3 views (last 30 days)
How to subtract a 16 bit image from 8 bit image?
  4 Comments
kumar Saurav
kumar Saurav on 28 Aug 2014
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?
kumar Saurav
kumar Saurav on 28 Aug 2014
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)

Image Analyst
Image Analyst on 28 Aug 2014
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
kumar Saurav
kumar Saurav on 28 Aug 2014
Edited: kumar Saurav on 28 Aug 2014
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'
Image Analyst
Image Analyst on 28 Aug 2014
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.


Adam
Adam on 28 Aug 2014
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.

Community Treasure Hunt

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

Start Hunting!