ITKeyword,专注技术干货聚合推荐

注册 | 登录

解决Image Compression using imfinfo function in Matlab

itPublisher 分享于

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
地址https://www.aliyun.com/minisite/goods

推荐:MATLAB Codes of JPEG Image Compression for Gray-level Image

 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

 | 

1 Answers
1

解决方法

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.


|
  this answer
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


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。