How to subtract a 16 bit image from 8 bit image?
Show older comments
How to subtract a 16 bit image from 8 bit image?
4 Comments
Geoff Hayes
on 28 Aug 2014
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?
Image Analyst
on 28 Aug 2014
Edited: Image Analyst
on 28 Aug 2014
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?
kumar Saurav
on 28 Aug 2014
kumar Saurav
on 28 Aug 2014
Answers (2)
Image Analyst
on 28 Aug 2014
0 votes
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
on 28 Aug 2014
Edited: kumar Saurav
on 28 Aug 2014
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));
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.
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!