Comparing images

2 ビュー (過去 30 日間)
Muhammad
Muhammad 2012 年 5 月 25 日
I want to compare images by taking a difference of their images but those values are just limited to 0 and 255. if i subtract 0-255 it gives me a 0 and if its 255-0 the answer is 255. how do i make them subtract like normal numbers so i can calculate the difference and get negative values too?

採用された回答

Image Analyst
Image Analyst 2012 年 5 月 25 日
Cast them to double before you add or subtract uint8 or uint16 images.
diffImage = double(uint8Image1) - double(uint8Image2);

その他の回答 (2 件)

Wayne King
Wayne King 2012 年 5 月 25 日
You could do
diffim = double(X)-double(Y);

Alex Taylor
Alex Taylor 2012 年 5 月 25 日
The results you are getting indicate that you are working with 8-bit unsigned integer data.
a = uint8(10*rand(3,3))
b = uint8(10*rand(3,3))
class(a)
If you want to do signed arithmetic on your data, you will need to work in a signed datatype. In the following example, I'll cast my matrices to double precision floating point.
c = double(a)-double(b);
If you want to work with integer datatypes, you'll need a signed integer datatype big enough to represent the dynamic range of your data:
c = int16(c)
Hope that helps,
Alex.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by