# 解决Image Compression using imfinfo function in Matlab

itPublisher 分享于

Matlab Codes：  function JPEG_Compressor (filename,quant_multiple)% JPEG image compression program for graylevel image only% This program compress

I am trying to calculate the compression ratio of a given image. My matlab code is as follows:

temp = imfinfo('flowers.jpg'); comperssion_ratio = (temp.Width * temp.Height * temp.BitDepth) / temp.FileSize;

The imfinfo displays the following:

``````       FileSize: 11569
Format: 'jpg'
FormatVersion: ''
Width: 430
Height: 430
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: ''
NumberOfSamples: 1
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
``````

Running the above code gives me a compression ratio of about 120 which is huge and does not seem right. Is there something that I'm doing wrong? I went through a document from MIT and they showed that the Width and Height and BitDepth should be divided by 8 and then divided by the FileSize. Why divide by 8?

matlab image-compression
|
this question
asked Jul 21 '14 at 4:45 David Norman 193 1 5 16

|

The division by factor of 8 is to convert bits to bytes.

According to the Matlab documentation for imfinfo

the FileSize parameter is the size of the compressed file, in bytes.

The compression ratio is defined as:

uncompressed size of image in bytes/compressed size of file in bytes

imfinfo gives you the pixel width, height, and bits per pixel (bit depth). From that you can compute the uncompressed size in bits, and divide by 8 to get bytes.

For the uncompressed image , you have 430*430*8/8 = 184,900 bytes.

The size of the compressed image is 11569 bytes.

So the compression ratio is actually 184,900/11569 or 15.98, not an unreasonable value for JPEG.

|
answered Jul 21 '14 at 5:05 paisanco 2,708 6 15 28      +1 - Solid explanation –  rayryeng Jul 21 '14 at 5:28

|

## 推荐：Convert a wave image to x-y function matlab[x,y]=imwtoxy(signal,V,T,px) function [x,y]=imwtoxy(signal,V,T,px)%This function can be used to convert an image of a wave captured %from an oscillo  ×
• 登录
• 注册

×

### 请激活账号  