how to calculate pixel value differences?

3 visualizaciones (últimos 30 días)
Rezaur Rahman
Rezaur Rahman el 23 de Feb. de 2016
Comentada: Rezaur Rahman el 23 de Feb. de 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

Respuesta aceptada

Guillaume
Guillaume el 23 de Feb. de 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

Más respuestas (0)

Categorías

Más información sobre Import, Export, and Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by