Why does ISWT2 (R2017a) fail for coefficients in single precision?

1 回表示 (過去 30 日間)
Shogo Muramatsu
Shogo Muramatsu 2017 年 5 月 14 日
コメント済み: Walter Roberson 2017 年 5 月 17 日
ISWT2 (R2017a) seems not to work properly for coefficients in single precision. The code below fails only for the single precision case.
nLevels = 1;
%%For image in double
X = im2double(imread('cameraman.tif'));
C = swt2(X,nLevels,'haar');
Y = iswt2(C,'haar');
psnr(Y,X)
%%For image in single
X = im2single(imread('cameraman.tif'));
C = swt2(X,nLevels,'haar');
Y = iswt2(C,'haar'); % <- error
psnr(Y,X)
Why does this phenomenon happen?

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 16 日
It is a bug in the code. If you look near line 110 of iswt2 you will see
% Ambiguity:
% (level=3 and indexed BW image) or (level=1 and truecolor image)
% To suppress this Ambiguity, the function SWT2 in case of a true
% color image and a level 1 analysis, produce single for approximation
% coefficients !!
So the swt2 code is encoding information about BW vs truecolor in the datatype (!) and then iswt2 flubs the reconstruction.
The work-around is to use
[A,H,V,D] = swt2(X,nLevels,'haar');
Y = iswt2(A, H, V, D);
  3 件のコメント
Shogo Muramatsu
Shogo Muramatsu 2017 年 5 月 16 日
I understood the cause clearly. Thank you very much!
Walter Roberson
Walter Roberson 2017 年 5 月 17 日
The problem occurs for any grayscale data that is not of type double

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

その他の回答 (1 件)

Ankit Bhatnagar
Ankit Bhatnagar 2017 年 5 月 16 日
Hi,
The ISWT2 works only with double precision as it uses functionality which expects the value to be double. Kindly use the double precision for this function.
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 16 日
No, it's just a bug. Have a look at my Answer.

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

カテゴリ

Help Center および File Exchangeイメージ についてさらに検索

Community Treasure Hunt

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

Start Hunting!