Image Compression

Contents

1 Introduction

2 The Theoretic Basis of Image Compression

2.1 The Principle of Image Storage
2.2 The Principle of the Sigular Value Decomposition

​ 2.2.1 Eigenvalues and Diagonalization

​ 2.2.2 Symmetric Matrices and Orthogonally Diagonalizable Matrix

​ 2.2.3 Sigular Value Decomposition(SVD)

2.3 The Appication of SVD in Image Compression
2.4 The Appropriate Number of Singular Values

3 Programs

4 Conclusion

5 References

1 Introduction

Image compression is extremely essential for people to store images in the computers with less memory space and load images faster in a certain web page. In fact, most of the images we come across in the Internet are compressed. For example, the formats of jpeg, png and gif are all compressed. Albeit, the image compression will deteriorate the quality of the images inevitably, but some trivial characters are not worth people’s attentions. Thus, comparing a little loss in the quality of the images with the dramatic reduction in the images’ memory space, we prefer the compressed pictures. Furthermore, an optimized compressing algorithm can reduce the image memory space as much as possible with little trivial deterioration, which can even not be discriminated by human’s eyes. As is known to all, computers store images in forms of matrices and each image matches a matrix in computers. Thus, compression can be done via operations on matrices. After some research on this topic, we intend to use the knowledge of singular value decomposition (SVD). By selecting some big singular values and the corresponding left and right singular vectors, we are able to use less data to represent an image with small deterioration.

2 The Theoretic Basis of Image Compression

2.1 The Principle of Image Storage

Computers store images in forms of matrices. For an RGB image, each image matches a three dimensional tensor which can be regarded as a combination of three matrices.

The shapes of these three matrices are the same as the original image.

In computers, there are three integers ranging from 0 to 255 corresponding to each pixel of the image. The values of these three integers represent the property of the pixel in R-channel, G-channel and B-channel respectively. Practically, the integers are normalized to be a float ranging from 0 to 1 at first and each float occupies 1 byte for computers to store.

Thus, for a RGB model picture with m×n pixels, we approximately need 3×m×n byte to store.

2.2 The Principle of the Sigular Value Decomposition

2.2.1 Eigenvalues and Diagonalization

Eigenvalues and Eigenvectors

If a vector ν\nuν is the eigenvector of the square matrix AAA, we can get the following form:
Aν=λνA\nu=\lambda\nu Aν=λν
λ\lambdaλ is called the eigenvalue, while the ν\nuν is called the eigenvector.

Diagonalization

If the n×\times×n square matrix AAA has n linearly independent eigenvectors, the matrix AAA can be diagonalized, which means that we can get the following form:
P−1AP=ΛP^{-1}AP=\Lambda P−1AP=Λ
The columns of PPP are the eigenvectors of AAA and the matrix Λ\LambdaΛ is a diagonal matrix with the diagonal entries are eigenvalues of AAA corresponding to the eigenvectors in PPP respectively.

2.2.2 Symmetric Matrices and Orthogonally Diagonalizable Matrix

If AAA is symmetric matrices(namely A=ATA=A^{T}A=AT) , it can be orthogonally diagonalized.

That is, we can get the following form:
Q−1AQ=ΛQ^{-1}AQ=\Lambda Q−1AQ=Λ
​ (where QQQ is a orthogonal matrix(Q−1=QT)(Q^{-1}=Q^{T})(Q−1=QT))

or in another form:
A=QΣQ−1A=Q\Sigma Q^{-1} A=QΣQ−1
This is a special kind of eigenvalue decomposition.

2.2.3 Sigular Value Decomposition(SVD)

The eigenvalue decomposition can only be applied to some square matrices, which means that it is limited. So, if we want to get the decomposition of a more general matrix (for example a m×nm\times nm×n matrix, m≠nm\neq nm̸​=n), we should find another method.

Firstly, we assume that the matrix A can be decomposed into the following form:
A=Um×m(σ1 ⋱  σr   0)m×nVn×nT=UΣVT(1)A=U_{m\times m} \begin{pmatrix} \sigma_{1}\\ \,&\ddots\\ \,&\,&\sigma_{r}\\ \,&\,&\,&0 \end{pmatrix}_{m\times n} V^{T}_{n\times n} =U\Sigma V^{T}\qquad(1) A=Um×m​⎝⎜⎜⎛​σ1​​⋱​σr​​0​⎠⎟⎟⎞​m×n​Vn×nT​=UΣVT(1)
​ (where Uand VU and\,VUandV are all orthonormal matrices)

To prove the existence of this decomposition, we only need to prove the existence of U,Σ and VTU ,\Sigma\,and\,V^{T}U,ΣandVT.

According to (1), we can find that:
Am×nVn×n=Um×mΣVn×nTVn×n=Um×mΣm×n(2)A_{m\times n}V_{n\times n}=U_{m\times m}\Sigma V^{T}_{n\times n}V_{n\times n}=U_{m\times m}\Sigma_{m\times n}\qquad(2) Am×n​Vn×n​=Um×m​ΣVn×nT​Vn×n​=Um×m​Σm×n​(2)

An×mT=(Um×mΣVn×nT)T=Vn×nΣn×mTUm×mT(3)A^{T}_{n\times m}=(U_{m\times m}\Sigma V^{T}_{n\times n})^{T}=V_{n\times n}\Sigma^{T}_{n\times m} U^{T}_{m\times m}\qquad(3) An×mT​=(Um×m​ΣVn×nT​)T=Vn×n​Σn×mT​Um×mT​(3)

According to (3), we can find that:
An×mTUm×m=Vn×nΣUm×mTUm×m=Vn×nΣn×mT(4)A^{T}_{n\times m}U_{m\times m}=V_{n\times n}\Sigma U^{T}_{m\times m}U_{m\times m}=V_{n\times n}\Sigma^{T}_{n\times m}\qquad(4) An×mT​Um×m​=Vn×n​ΣUm×mT​Um×m​=Vn×n​Σn×mT​(4)
Left multiply (2) by ATA^{T}AT, and left mutiply (4) by AAA, we get :
An×mTAm×nVn×n=An×mTUm×mΣm×n=Vn×nΣn×mTΣm×n=Vn×nΛn×n(5)A^{T}_{n\times m}A_{m\times n}V_{n\times n}=A^{T}_{n\times m}U_{m\times m}\Sigma_{m\times n}=V_{n\times n}\Sigma^{T}_{n\times m}\Sigma_{m\times n}=V_{n\times n}\Lambda_{n\times n}\qquad(5) An×mT​Am×n​Vn×n​=An×mT​Um×m​Σm×n​=Vn×n​Σn×mT​Σm×n​=Vn×n​Λn×n​(5)

Am×nAn×mTUm×m=Am×nVn×nΣn×mT=Um×mΣm×nΣn×mT=Um×mΛm×m(6)A_{m\times n}A^{T}_{n\times m}U_{m\times m}=A_{m\times n}V_{n\times n}\Sigma^{T}_{n\times m}=U_{m\times m}\Sigma_{m\times n}\Sigma^{T}_{n\times m}=U_{m\times m}\Lambda_{m\times m}\qquad(6) Am×n​An×mT​Um×m​=Am×n​Vn×n​Σn×mT​=Um×m​Σm×n​Σn×mT​=Um×m​Λm×m​(6)

(wheretheΛn×nandΛm×marealldiagonalmatrices)(∗)(where\ the\ \Lambda_{n\times n}\ and\ \Lambda_{m\times m}\ are\ all\ diagonal\ matrices)^{(*)} (where the Λn×n​ and Λm×m​ are all diagonal matrices)(∗)

For the (*), we can see that :
KaTeX parse error: No such environment: align* at position 8: \begin{̲a̲l̲i̲g̲n̲*̲}̲ \Lambda_{m\tim…

KaTeX parse error: No such environment: align* at position 8: \begin{̲a̲l̲i̲g̲n̲*̲}̲ \Lambda_{n\tim…

or in the following form:
An×mTAm×n=Vn×nΛn×nVn×n−1A^{T}_{n\times m}A_{m\times n}=V_{n\times n}\Lambda_{n\times n}V_{n\times n}^{-1} An×mT​Am×n​=Vn×n​Λn×n​Vn×n−1​

Am×nAn×mT=Um×mΛm×mUm×m−1A_{m\times n}A^{T}_{n\times m}=U_{m\times m}\Lambda_{m\times m}U_{m\times m}^{-1} Am×n​An×mT​=Um×m​Λm×m​Um×m−1​

So (5) is the orthogonal diagonalization of ATAA^{T}AATA, while (6) is the orthogonarof AATAA^{T}AAT, which means we can diagonalize these two matrices to obtain the matrix $U, V $. For the matrix Σ\SigmaΣ, σi\sigma_{i}σi​ is called the sigular value, which is the squareroot of the eigenvalues of ATAandAATA^{T}A\ and\ AA^{T}ATA and AAT .

Actually, they are two symmetric matrices based on the general matrix A:
ATA=(ATA)TA^{T}A=(A^{T}A)^{T} ATA=(ATA)T

AAT=(AAT)TAA^{T}=(AA^{T})^{T} AAT=(AAT)T

So, these two matrices can be orthogonally diagonalized, which means the existence of $\Sigma,U, V $is proved.

2.3 The Appication of SVD in Image Compression

From the 2.1, we have known that any RGB model image can be stored into a 3D tensor with 3 channels. So, we can compress the matrices in each channel and combine them together to get copressed image.

As we have mentioned before, any m×n matrix can be decomposed in the following form:

We can rewrite the matrix in spectral decomposed form. The singular values can be regarded as weights to different matrices. And Decomposed sub-matrix with bigger singular value has a greater impact on the result and contribute more information. So, when performing singular value decomposition, we prefer to rearrange the sequence of singular values with the bigger one at front. Thus, we just need to select the first k singular values and the corresponding vectors to represent the original image with relatively less deterioration. Suppose that we have an image with m × n pixels. Then we need 3×m×n Bytes to store it. However, after singular value decomposition and selecting the first k singular values, it will only occupy 3k(m+n+1)3k(m+n+1)3k(m+n+1) Bytes. In fact, k≪mandk≪nk\ll m\ and\ k\ll nk≪m and k≪n, so the storage space for the images is greatly reduced. We set k(m+n+1)m×n\frac{k(m+n+1)}{m\times n}m×nk(m+n+1)​ as the compression ratio.

The following images are SVD for different value of k:

2.4 The Appropriate Number of Singular Values

We have learnt that singular value of a matrix can be regarded as a weight for each decomposed matrices. Decomposed sub-matrix with bigger singular value has a greater impact on the result and contribute more information. After achieving the compression, we want to find out k (the appropriate number of singular value) which can reduce the image memory space as much as possible with trivial deterioration. To obtain the appropriate k, we firstly sketch the graph describing the relationship between singular values and their numbers.

Unfortunately, we find that the graph appears concave up and it decreases quickly at first then becomes slowly. Thus we can not find a certain point to satisfy our goal. However, after compressing several images, we find that if we choose the first k singular values whose summation occupies 70% of the total summation, the difference between compressed images and the original images can hardly be distinguished.
For this 512×512 pixels image, we have 512 singular values. By some simple calculation, we are able to figure out that the summation of the first 53 singular values occupy 70% of the total summation. Compressing the image with k=53, we can get the following result.


The original image occupy about 78.6kB, after the compressing, it only needs 3.1kB to store.

3 Programs

import numpy as np
import matplotlib.pyplot as plt
from PIL import Imagedef svd_decompose(img, s_num):  u, s, vt = np.linalg.svd(img)h, w = img.shape[:2]s1 = np.diag(s[:s_num],0)  u1 = np.zeros((h,s_num), float)vt1 = np.zeros((s_num,w), float)u1[:,:] = u[:,:s_num]vt1[:,:] = vt[:s_num,:]svd_img=u1.dot(s1).dot(vt1)return svd_imgdef RGB_decompose(img,s_num):original=plt.imread("..\\Image_Compression\\"+img)R=svd_decompose(original[:,:,0], s_num)G=svd_decompose(original[:,:,1], s_num)B=svd_decompose(original[:,:,2], s_num)return np.dstack((R,G,B)).astype(int)def main():svd_1 = RGB_decompose("lena.jpg", 1)svd_5 = RGB_decompose("lena.jpg", 5)svd_10 = RGB_decompose("lena.jpg", 10)svd_20 = RGB_decompose("lena.jpg", 20)svd_50 = RGB_decompose("lena.jpg", 50)svd_100 = RGB_decompose("lena.jpg", 100)plt.figure(num='result',figsize=(12,8),facecolor='pink')plt.subplot(2,3,1)plt.imshow(svd_1)plt.title('1 Singular Values')plt.axis('off') plt.subplot(2,3,2)plt.imshow(svd_5)plt.title('5 Singular Values')plt.axis('off') plt.subplot(2,3,3)plt.imshow(svd_10)plt.title('10 Singular Values')plt.axis('off') plt.subplot(2,3,4)plt.imshow(svd_20)plt.title('20 Singular Values')plt.axis('off') plt.subplot(2,3,5)plt.imshow(svd_50)plt.title('50 Singular Values')plt.axis('off') plt.subplot(2,3,6)plt.imshow(svd_100)plt.title('100 Singular Values')plt.axis('off') plt.show()if __name__ == '__main__':main()

4 Conclusion

In this article, we talked something like:

1.At the begining, we introduce how an image is stored in computers.

2.Then, we proved the singular value decomposition.

3.Next, we elaborated why SVD can be applied to image compression and tried to find the best number of singular values of SVD.

4.At last, we showed our programming code and some compressed images with different singular values

5 References

[1]. David C. Lay, Linear Algebra and Its Application, University of Maryland

[2]. CSDN Blog The working principle of SVD and application for Python. Link: https://blog.csdn.net/weixin_33843947/article/details/88160723

[3]. CSDN Blog SVD decomposition test for image matrix. Link: https://blog.csdn.net/index20001/article/details/73501632

[4]. CSDN Blog The Principle of image storage. Link:
https://blog.csdn.net/sscout/article/details/82314908

SVD分解图像压缩应用英语论文相关推荐

  1. SVD分解的并行实现

    在之前的文章中,我对SVD进行了大致的了解,它在互联网高端领域中有广泛的应用,至于它的一些详细应 用以后再进一步学习.现在主要的问题是如何有效地实现SVD分解,接下来我会先用两种方法来实现SVD分 解 ...

  2. 奇异值(Singular value decomposition SVD)分解

    本文摘自两篇博客,感谢博主分享 一.原文地址:http://blog.csdn.net/wangzhiqing3/article/details/7446444 SVD分解 SVD分解是LSA的数学基 ...

  3. 李宏毅线性代数笔记13:SVD分解

    1 SVD分解介绍 之前用特征值来进行对角化的时候,被对角化的矩阵一定要是方阵,但是SVD的话,非方阵也是可以的. 矩阵Σ对角线上的元素都是大于等于0的 我们可以改变U,V的一些行和列,来达到Σ对角线 ...

  4. 【线性代数】6-7:SVD分解(Singular Value Decomposition-SVD)

    原文地址1:https://www.face2ai.com/Math-Linear-Algebra-Chapter-6-7转载请标明出处 Abstract: 本文介绍SVD,奇异值分解,应该可以算是本 ...

  5. 矩阵分解 SVD分解

    在认识SVD之前,先来学习两个相关的概念:正交矩阵和酉矩阵. 如果,则阶实矩阵称为正交矩阵.而酉矩阵是正交矩阵往复数域上的推广. 判断正交矩阵和酉矩阵的充分必要条件是:.或者说正交矩阵和酉矩阵的共轭转 ...

  6. 机器学习笔记(二)矩阵和线性代数 例:用Python实现SVD分解进行图片压缩

    线性代数基本只要是理工科,都是必修的一门课.当时学习的时候总是有一个疑惑,这个东西到底是干嘛用的?为什么数学家发明出这么一套方法呢,感觉除了解方程没发现有什么大用啊!但随着学习的深入,慢慢发现矩阵的应 ...

  7. 【机器学习中的矩阵分解】LU分解、QR分解、SVD分解

    学习总结 文章目录 学习总结 一.三角分解(LU分解) 1.1 高斯消元 1.2 LU分解原理 1.3 LU分解python代码 1.4 LU分解算法 二.QR分解 2.1 Schmid 正交化 2. ...

  8. 基于R语言SVD的图像压缩方法

    图片的基本构成 假设我们有一个灰度图像(128×128,即128×128像素).我们可以使用矩阵来表示这个图像.如果我们有彩色图像,用R中的readJEPG函数读取图片就可以发现它是由一个三维数组构成 ...

  9. svd分解 复原 sklearn和numpy实现

    网上有很多分析svd分解原理的文章,例如下面的链接, svd原理解释,本文主要介绍在sklearn和numpy中,如何进行svd分解以及如何复原,可以利用到图像压缩和复原等任务中. 原理 1.pca的 ...

最新文章

  1. 轻松自动化---selenium-webdriver(python) (四)
  2. mat工具MemoryAnalyzer进行分析java内存溢出hprof文件
  3. 搞了个30天学习量化的数据资料,可以bt做全球。数据链接白送
  4. SAP License:谈对财务人的解惑
  5. 判断年月日是否正确及获取当前天的前一天或前一个月
  6. 一篇极好的Git 总结
  7. 【图像增强】基于matlab区域相似变换函数和蜻蜓算法灰度图像增强【含Matlab源码 089期】
  8. 计算机组成与设计概念总结
  9. (三)微信小程序云开发之微信支付全解
  10. oracle用户新建和授权,oracle创建用户及受权
  11. MATLAB Appdesigner开发独立桌面App全流程(三):App的简单美化、打包、安装及卸载
  12. 3d打印测温模型单塔双塔tt pro专业版测温模型stl下载
  13. 转换金额为大写人民币-Java
  14. factorybean 声明_说说 Spring 框架中的 Factory Bean
  15. Bifrost RAT 流量分析报告
  16. mybatis是否支持延迟加载?延迟加载的原理是什么
  17. 智能手环功能模块设计_智能手环设计方案
  18. h5页面文件加载不出来被浏览器当成广告屏蔽
  19. DeepLab系列学习
  20. 重量级锁的原理与实战

热门文章

  1. Python绘图一条龙--大小/坐标/标签/多图布局/配色方案等
  2. 天池大赛-心跳信号分类预测:探索性数据分析
  3. 【生产者消费者模型】
  4. 遗传算法求解TSP问题(python版)
  5. 数据、数据元素、数据项、数据对象的理解
  6. window nginx关闭后,访问代理仍成功
  7. 植物大战僵尸:学会使用人造指针
  8. HDLBits-Exams/ece241 2013 q4、Lemmings1、Lemmings2、Lemmings3、Lemmings4
  9. 计算机视觉图像算法工程师应该了解哪些知识
  10. 问题备忘: httpclient连接池异常引发的惨案