This example shows how to test image quality usingssim
. The example creates images at various compression levels and then plots the quality metrics. To run this example, you must have write permission in your current folder.
Read an image into the workspace.
I = imread('cameraman.tif');
Write the image to a file using various quality values. The JPEG format supports the'quality'
parameter. Use thessim
function to check the quality of each written image.
ssimValues = zeros(1,10); qualityFactor = 10:10:100;fori = 1:10 imwrite(I,'compressedImage.jpg','jpg','quality',qualityFactor(i)); ssimValues(i) = ssim(imread('compressedImage.jpg'),I);end
Plot the results. Note how the image quality score improves as you increase the quality value specified withimwrite
.
plot(qualityFactor,ssimValues,'b-o'); xlabel('Compression Quality Factor'); ylabel('SSIM Value');