フィルターのクリア

Weird Calculation difference using uint16 and double for an image

11 ビュー (過去 30 日間)
Jason
Jason 2019 年 10 月 30 日
コメント済み: Steven Lord 2019 年 10 月 30 日
Hello, I have a function that calculates the "contrast" of a greyscale image
function FM=CalculateBrenner(Image)
[M N] = size(Image);
DH = Image;
DV = Image;
DH(1:M-2,:) = diff(Image,2,1);
DV(:,1:N-2) = diff(Image,2,2); % second order difference between
% columns, i.e., along x-direction.
FM = max(DH, DV);
FM = FM.^2;
FM = mean2(FM);
end
when my image is a uint16, I get
FM= 100.39
max=438
min=22
But when my image is cast as a double
I get:
FM = 204.14
max=438.00
min= 22.00
So why is the calculation FM different for both cases, yet the values its using are the same (indicated by the max & min)

採用された回答

Steven Lord
Steven Lord 2019 年 10 月 30 日
d = [1 2 1];
u = uint16(d);
dd = diff(d)
du = diff(u)
The smallest value you can store in an unsigned 16-bit integer is 0. In double 1 - 2 is -1 but in uint16 it is 0.
  2 件のコメント
Jason
Jason 2019 年 10 月 30 日
編集済み: Jason 2019 年 10 月 30 日
OK, so I should use a double as it doesn't ignore negative values.
Steven Lord
Steven Lord 2019 年 10 月 30 日
You could use imabsdiff if you have Image Processing Toolbox, or just take the max of A-B and B-A (one will be zero, one may not be) for appopriate pieces A and B of your Image variable.
d = [1 2 1];
u = uint16(d);
max(u([3 2])-u([2 1]), u([2 3])-u([1 2]))
I'll leave that last line for you to generalize.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by