how to calculate pixel value differences?
3 views (last 30 days)
Show older comments
Rezaur Rahman
on 23 Feb 2016
Commented: Rezaur Rahman
on 23 Feb 2016
let my image be
temp=
[5 10;
10 15]
if i want to calculate temp(1,1)-temp(1,2) or temp(1,1)-temp(2,1) it always shows 0. how can i store the value?? i have also tried abs(temp(1,1)-temp(1,2)); bt failed. thanx in advance
0 Comments
Accepted Answer
Guillaume
on 23 Feb 2016
In your example, it actually works the way you want. The most likely reason why it does not work with your real image is that your image is of type uint8 (or uint16). The range of uint8 is limited to [0, 255], any value below or above these values are clamped to 0 or 255.
The fix is simple, convert your image to double:
temp = uint8([5 10; 10 15]) %demo image
temp(1,1) - temp(1, 2) %output 0, since -5 is not allowed for uint8
temp = double(temp); %convert to double
temp(1,1) - temp(1, 2) %output -5 as it should
More Answers (0)
See Also
Categories
Find more on Import, Export, and Conversion 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!