MATLAB: How to use VPA (variable precision arithmetic) in calculating HH band via dwt on an image
dwt2hh bandvpa
I have the following code:
img = imread('cameraman.tif');
[LL,LH,HL,HH] = dwt2(img, 'db1');
I have to calculate HH band using vpa (32 digits), instead of double precision.
Plz help in this regard.
Best Answer
You can not do this. dwt2 accepts only double as input and outputs double. vpa works on symbolic variables and returns a symbolic variable:
>> vpa(pi)
ans =
3.1415926535897932384626433832795
>> whos ans
Name SizeBytesClassAttributes
ans 1x1 8 sym
So you will either get an error if you try to pass a symbolic variable to dwt2 or you will have to cast it to double, which also does not help you. What you can do is show 32 digits of the result calculated as double:
In this case you are going to have to sacrifice something, if you use VPA the matrices become symbolic, therefore all the operations you do with them are going to slow down, GPU does not support these matrices so it would not give you anything.
On the other hand if you stay with "normal" matrices you will have a maximum of 15 digits after the decimal point, and using the GPU could give you something depending on the operations you are doing
If you really need too much precision you can search about Pari / GP that you could integrate with Matlab, or also Accelerating MATLAB Code Using Codegen and Mex Files
Mathworks technical support have diagnosed the problem. Don't know what caused it originally but the 'FloatingPointOutput' setting in the symbolic preferences was set to 1.
Best Answer