Quantisation for IMAGE COMPRESSION
4 次查看(过去 30 天)
显示 更早的评论
I'm doing an image compression using discrete cosine transform project....(To be implemented in hardware using Fixed Point Arithmetics)
DCT=(c)(x)(cT) c cosine coefficients... x image.... cT represent cosine transpose....
how can i check the error if i'm using 8 bits to represent the cosine matrix and the cosine transpose? eg: Also, suppose if i'm multipling two 8 bit numbers( each of them has 5 bit for decimal part and 3 bit for fractional part) then the result will be naturally 16 bits( ie. 10 bit decimal part plus 6 bit fraction part)
If i quantize the result by represending with say 12 bits....now what will be the error ............?how can i find it?Does matlab has an inbuilt function for this?
can anyone explain how this can be done.........
1 个评论
Umar
2024-7-15
编辑:Walter Roberson
2024-7-15
Hi JJ,
Multiply two 8-bit numbers with 5 bits for the decimal part and 3 bits for the fractional part which will result in a 16-bit number, quantize the result to 12 bits. The error can be calculated as the difference between the original and quantized values. Then, use function quantize in Matlab which will in quantization error analysis. For more information on this function, please refer to
By following these steps,you can effectively assess the impact of Fixed-Point Arithmetic on image compression using DCT.
回答(1 个)
Andy Bartlett
2024-7-15
Compare a fixed-point implementation vs. an "ideal math" implemenation.
Step 1: Determine some numerically rich inputs for the algorithm.
Helpful tools for picking rich inputs include
fixed.DataSpecification
fixed.DataGenerator
Step 1: Compute the fixed-point output.
Step 2: Get a reference value close to the "ideal math" output.
Most often this is done by converting inputs to double and redoing all the calculations in double.
Step 3: Determine the difference between the fixed-point value and the reference value.
Be careful to use a sufficiently high precision type to do the error calculations in, not a low precision calc type.
Traditionally, you'd cast both the fixed-point and the reference to double then do the calculations in double.
More recent releases have utilities that will compute the error in high precision for any combinations of data types.
fixed.unifiedErrorCalculator.absoluteError
fixed.unifiedErrorCalculator.relativeAbsoluteError
fixed.unifiedErrorCalculator.bitsOfError
Below is an example for the multiplication example you mentioned. For the 12 bit output, the 4 least significant bits of the full precision 16 bit product were discarded, so all of the quantization error will be due to rounding of the least significant bits. The default fixed-point fi object rounding to nearest is used, so the final output will be off by half a bit in the 12 bit output data type.
nPoints = 2^16;
ntInput1 = numerictype(1,8,3);
ntInput2 = numerictype(1,8,3);
ntOutput = numerictype(1,12,2);
inputSelectionMethod = 'BruteForceGrid';
switch inputSelectionMethod
case 'DataGenerator'
ds1 = fixed.DataSpecification(ntInput1);
ds2 = fixed.DataSpecification(ntInput2);
dataGen = fixed.DataGenerator('DataSpecifications', {ds1, ds2}, 'NumDataPointsLimit', nPoints);
[u1, u2] = dataGen.outputAllData('array');
case 'BruteForceGrid'
n1 = ceil(sqrt(nPoints));
n1 = min(n1, 2^ntInput1.WordLength);
range1 = double(range(ntInput1));
v1 = fi( linspace( range1(1), range1(2), n1), ntInput1 );
n1 = numel(v1);
n2 = ceil(nPoints/n1);
n2 = min(n2, 2^ntInput2.WordLength);
range2 = double(range(ntInput2));
v2 = fi( linspace( range2(1), range2(2), n2), ntInput1 );
[u1,u2] = meshgrid(v1,v2);
u1 = u1(:);
u2 = u2(:);
otherwise
error('Unknown case')
end
yReferenceDouble = double(u1) .* double(u2);
% Make plot prettier by sorting by product value.
[~,ii] = sort(yReferenceDouble);
productFullPrecision = u1 .* u2;
y = fi( productFullPrecision, ntOutput);
absErr = fixed.unifiedErrorCalculator.absoluteError(y,yReferenceDouble);
absBitsOfError = abs(fixed.unifiedErrorCalculator.bitsOfError(y,yReferenceDouble));
figure(1)
subplot(1,1,1)
plot(yReferenceDouble(ii),yReferenceDouble(ii),'k-',yReferenceDouble(ii),y(ii),'b-')
xlabel('Product Value Reference')
ylabel('Product')
legend({'Reference','Fixed-Point'},'Location','best')
axis tight
grid on
Absolute Error in Real World Values
figure(2)
subplot(1,1,1)
plot(yReferenceDouble(ii),absErr(ii),'r.')
xlabel('Product Value Reference')
ylabel('Abs Error')
axis tight
grid on
Absolute Error in Bits of the Final Output Type
figure(3)
subplot(1,1,1)
plot(yReferenceDouble(ii),absBitsOfError(ii),'r.')
xlabel('Product Value Reference')
ylabel('Abs Bits of Error')
axis tight
grid on
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Fixed-Point Objects in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!