Znn3bq.jpeg
²é¿´: 1290  |  »Ø¸´: 9
µ±Ç°Ö÷ÌâÒѾ­´æµµ¡£

Сľͷ5898

Òø³æ (СÓÐÃûÆø)

[½»Á÷] ¡¾ÇóÖú¡¿JPEGµÄMatlabʵÏÖ

ÏÂÃæÊÇÎÒ×Ô¼ºÊµÏÖµÄJPEG³ÌÐò¡¡Á¿»¯ºó±àÂëÊÇÓõÄRLC¡¡Ã»ÓÐʹÓÃHuffman£¨Ã»·¢ÏÖºÏÊʵģ©¡¡µ«Êǹý³ÌÖÐJPEGÖ®ºóµÄͼÏñÓкÜÃ÷ÏԵĿéЧӦ¡¡Öؽ¨Ö®ºóPSNR²»ÀíÏë
¶øÇÒûÓÐʵÏÖÂëÂÊbppµÄ¿É¿ØÖÆ¡¡
¾´Çë¸÷λ³æÓÑÖ¸µ¼¡¡ÌÖÂÛ
Èç¹ûÓиüºÃµÄJPEGʵÏÖ³ÌÐò¡¡Ï£ÍûÄÜÌù³öÀ´»ò·¢¸øÐ¡µÜ¡¡yan_li19850430@yahoo.com   ¼±Åλظ´


////////////////////////////////////////////////////////////
% My_JPEG main function
function My_JPEG

clear all;
clc

%load image
I_Ori=imread('lena.bmp');
I=double(I_Ori);
figure(1)
imshow(I_Ori)




% DCT_8*8 Transform  and  Quantification
%dct_transformed_image = Classic_DCT( I );
dct_transformed_image = image_8x8_block_flowgraph_forward_dct( I );
figure(2)
II=uint8(dct_transformed_image);
imshow(II)


Q_8x8=[16 11 10 16 24  40  51  61; 12 12 14 19 26  58  60 55;
          14 13 16 24 40  57  69  56; 14 17 22 29 51  87  80 62;
          18 22 37 56 68  109 103 77; 24 35 55 64 81  104 113 92;
          49 64 78 87 103 121 120 101;72 92 95 98 112 100 103 99];
quantization_matrix_128x128 = repmat(Q_8x8,64,64); %for coarse quantization
%quantization_matrix_128x128 = repmat((ceil(double(Q_8x8)./40)),64,64 );   %for fine quantization

quantized_image_128x128 =  round(dct_transformed_image ./quantization_matrix_128x128); %round operation should be done here for lossy quantization


figure(3)
imshow(uint8(quantized_image_128x128))





% Entropy Coding
    %This suitable Zigzag order is formed from the  JPEG standard
    ZigZag_Order = uint8([
            1  9  2  3  10 17 25 18
            11 4  5  12 19 26 33 41
            34 27 20 13 6  7  14 21
            28 35 42 49 57 50 43 36
            29 22 15 8  16 23 30 37
            44 51 58 59 52 45 38 31
            24 32 39 46 53 60 61 54
            47 40 48 55 62 63 56 64]);

    % Finding the reverse zigzag order (8x8 matrix)
    reverse_zigzag_order_8x8 = zeros(8,8);
    for k = 1size(ZigZag_Order,1) *size(ZigZag_Order,2))
        reverse_zigzag_order_8x8(k) = find(ZigZag_Order== k);
    end;
   
     % Break 8x8 block into columns
    Single_column_quantized_image=im2col(quantized_image_128x128, [8 8],'distinct');

   
    %--------------------------- zigzag ----------------------------------
    % using the MatLab Matrix indexing power (specially the ':' operator) rather than any function
    ZigZaged_Single_Column_Image=Single_column_quantized_image(ZigZag_Order,;   
    %---------------------------------------------------------------------


    %---------------------- Run Level Coding -----------------------------
    % construct Run Level Pair from ZigZaged_Single_Column_Image
    run_level_pairs=uint8([]);
    for block_index=1:4096    %block by block - total 256 blocks (8x8) in the 128x128 image
        single_block_image_vector_64(1:64)=0;
        for Temp_Vector_Index=1:64
            single_block_image_vector_64(Temp_Vector_Index) = ZigZaged_Single_Column_Image(Temp_Vector_Index, block_index);  %select 1 block sequentially from the ZigZaged_Single_Column_Image
        end
        non_zero_value_index_array = find(single_block_image_vector_64~=0); % index array of next non-zero entry in a block
        number_of_non_zero_entries = length(non_zero_value_index_array);  % # of non-zero entries in a block

    % Case 1: if first ac coefficient has no leading zeros then encode first coefficient
        if non_zero_value_index_array(1)==1,  
           run=0;   % no leading zero
            run_level_pairs=cat(1,run_level_pairs, run, single_block_image_vector_64(non_zero_value_index_array(1)));
        end

    % Case 2: loop through each non-zero entry   
        for n=2:number_of_non_zero_entries,
            % check # of leading zeros (run)
            run=non_zero_value_index_array(n)-non_zero_value_index_array(n-1)-1;
            run_level_pairs=cat(1, run_level_pairs, run, single_block_image_vector_64(non_zero_value_index_array(n)));
        end
        
    % Case 3: "End of Block" mark insertion
        run_level_pairs=cat(1, run_level_pairs, 255, 255);
    end
  Compressed_image_size = size(run_level_pairs);        % file size after compression
  Compression_Ratio = 262144/Compressed_image_size(1,1);
  Rate=8/ Compression_Ratio



% Entropy Decoding
% % %  -------------------------------------------------------------------
% % %  -------------------------------------------------------------------
% % %                DECODING
% % %  -------------------------------------------------------------------
% % %  -------------------------------------------------------------------

   

    %---------------------- Run Level Decoding ---------------------------
    % construct  ZigZaged_Single_Column_Image from Run Level Pair
    c=[];
    for n=1:2:size(run_level_pairs), % loop through run_level_pairs
        % Case 1 & Cae 2
        % concatenate zeros according to 'run' value
        if run_level_pairs(n)<255 % only end of block should have 255 value
            zero_count=0;
            zero_count=run_level_pairs(n);
            for l=1:zero_count    % concatenation of zeros accouring to zero_count
                c=cat(1,c,0);   % single zero concatenation
            end
            c=cat(1,c,run_level_pairs(n+1)); % concatenate single'level' i.e., a non zero value
      
        % Case 3: End of Block decoding
        else
            number_of_trailing_zeros= 64-mod(size(c),64);
            for l= 1:number_of_trailing_zeros    % concatenate as much zeros as needed to fill a block
                c=cat(1,c,0);
            end
        end
    end
    %---------------------------------------------------------------------
   

    %---------------------------------------------------------------------
    %    prepare the ZigZaged_Single_Column_Image vector (each column represents 1 block) from the
    %    intermediate concatenated vector "c"
    for i=1:4096
        for j=1:64
            ZigZaged_Single_Column_Image(j,i)=c(64*(i-1)+j);
        end
    end
    %---------------------------------------------------------------------
     
   
    %--------------------------- reverse zigzag --------------------------
    %reverse zigzag procedure using the matrix indexing capability of MatLab (specially the ':' operator)
    Single_column_quantized_image = ZigZaged_Single_Column_Image(reverse_zigzag_order_8x8,;
    %---------------------------------------------------------------------
   

   %image matrix construction from image column
    quantized_image_128x128 = col2im(Single_column_quantized_image,   [8 8],   [512 512],   'distinct');




% Inverse_DCT_8*8 Transform  and  Inverse Quantification

dct_transformed_image_IQ =  quantized_image_128x128 .*quantization_matrix_128x128;


%restored_image = image_8x8_block_inv_dct(dct_transformed_image_IQ );
restored_image = image_8x8_block_flowgraph_inverse_dct( dct_transformed_image_IQ );


III=uint8(restored_image);
figure(4)
imshow(III)
% Reconstruct image



%SNR
PSNR=psnr(restored_image, I);


end

[ Last edited by gjliu on 2009-5-11 at 13:29 ]
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

Ifyoufailtoplan,youplantofail!
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

bslt

½ð³æ (ÖøÃûдÊÖ)

--<-<-<@

¿éЧӦ ÊDz»ÊÇÒç³öÁË
±ðÃÔÁµ¸ç£¬¸ç²»Ö»ÊǸö´«Ëµ...
2Â¥2009-04-09 15:55:05
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

Сľͷ5898

Òø³æ (СÓÐÃûÆø)

¡ï
2007ÆïÖí¹ä½Ö(½ð±Ò+1,VIP+0):лл²ÎÓë½»Á÷ 4-20 03:31
ÎÒ¾õµÃÊDz»ÊÇÁ¿»¯¹ý³ÌÊ§ÕæÌ«´ó  »¹Ò»¸ö¾ÍÊÇÁ¿»¯ºóµÄ±àÂëÊDz»ÊÇÓ¦¸ÃÓÃHuffman¸üºÃµã
Ifyoufailtoplan,youplantofail!
3Â¥2009-04-09 16:58:17
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

bslt

½ð³æ (ÖøÃûдÊÖ)

--<-<-<@

¡ï
2007ÆïÖí¹ä½Ö(½ð±Ò+1,VIP+0):лл²ÎÓë½»Á÷ 4-20 03:31
ÊÔÊÔ »ô·òÂü°É
matlab´úÂëgoogleËѲ»µ½ºÃµÄô£¿È¥CSDN ×ÊÔ´ ÀïËÑËÑ¿´¿´
ÎÒ¸ÕÉÏÁ˼¸ÌÃͼÏñ´¦ÀíµÄ¿Î ²»¸ÒÔì´Î °ïÂ¥Ö÷¶¥¹ý¡£¡£¡£
±ðÃÔÁµ¸ç£¬¸ç²»Ö»ÊǸö´«Ëµ...
4Â¥2009-04-09 17:23:44
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

Сľͷ5898

Òø³æ (СÓÐÃûÆø)

3KU
5Â¥2009-04-11 08:06:35
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

zh1985444

½ð³æ (ÕýʽдÊÖ)

¡ï
bslt(½ð±Ò+1,VIP+0):Ó¦ÖúÓн±£¬»¶Ó­³£À´ÐÅÏ¢¿ÆÑ§°æ£¡ 4-14 09:34
ÎÒÓÐÒ»·Ýmatlab JPEGµÄ´úÂ룬ºËÐIJ¿·ÖÊÇÓÉC³ÌÐòдµÄ£¬ÔÚmatlabÖе÷ÓÃÏà¹Øº¯Êý¾Í¿ÉÒÔÁË¡£¿ÉÒÔͨ¹ýmatlab¶Áȡһ¸öJPEGÎļþ£¬²¢ÌáÈ¡ÀïÃæµÄ¸÷Ïîϸ½Ú£¬°üÀ¨¸÷¸ö·ÖÁ¿Öµ£¬Á¿»¯±íµÈ£¬²¢ÇÒÒ²¿ÉÒÔ±àÂë¡£ÐèÒªµÄ»°·¢Óʼþµ½zh1985444@sina.com.cn£¬×¢Ã÷Сľ³æ
6Â¥2009-04-13 22:00:38
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

zh1985444

½ð³æ (ÕýʽдÊÖ)

ÓʼþÒѾ­·¢Ë͵½ÄãÓÊÏ䣬´úÂë½ö¹©Ñо¿Ñ§Ï°Ê¹Ó㬰æÈ¨¹éÔ­×÷ÕßËùÓС£ÇëÎðÓÃÓÚÉÌÒµÓÃ;
7Â¥2009-04-16 09:05:29
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

Сľͷ5898

Òø³æ (СÓÐÃûÆø)

ÒýÓûØÌû:
Originally posted by zh1985444 at 4/16/09 09:05:
ÓʼþÒѾ­·¢Ë͵½ÄãÓÊÏ䣬´úÂë½ö¹©Ñо¿Ñ§Ï°Ê¹Ó㬰æÈ¨¹éÔ­×÷ÕßËùÓС£ÇëÎðÓÃÓÚÉÌÒµÓÃ;

SKU  
8Â¥2009-04-22 15:42:13
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

sunyuanxin

½û³æ (ÖøÃûдÊÖ)

±¾ÌûÄÚÈݱ»ÆÁ±Î

9Â¥2009-04-22 20:33:45
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

gjliu

Òø³æ (СÓÐÃûÆø)

¡ï
bslt(½ð±Ò+1,VIP+0):Ó¦Öú½±Àø£¡^_^ 5-12 18:44
ÇëÈ¥ÏÂÔØÒ»¸öIndependent JPEG ¿ª·¢µÄMatlab JPEG Toolbox£¬googleÉÏ¿ÉÒÔËÑË÷µ½µÄ¡£
±ÈÄã×Ô¼ºÐ´ºÃºÃÓöàÁË¡£
10Â¥2009-05-11 13:29:06
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ Сľͷ5898 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 290Çóµ÷¼Á +13 ¿Â»´È» 2026-04-12 15/750 2026-04-12 12:26 by laoshidan
[¿¼ÑÐ] Çóµ÷¼Á£¬985²ÄÁÏÓ뻯¹¤348·Ö +8 º­ÖñÁõ 2026-04-11 10/500 2026-04-12 10:01 by ´óÁ¦Ë®ÊÖÁ¦´óÎÞÇ
[¿¼ÑÐ] 297Çóµ÷¼Á +17 ORCHID1 2026-04-10 18/900 2026-04-12 09:59 by zhouwenxian
[¿¼ÑÐ] 0854µ÷¼Á +12 ³¤¹­°Á 2026-04-09 13/650 2026-04-12 09:56 by ÄæË®³Ë·ç
[¿¼ÑÐ] 291Çóµ÷¼Á +8 ¹ØÒä±±. 2026-04-11 8/400 2026-04-12 09:32 by ÄæË®³Ë·ç
[¿¼ÑÐ] µ÷¼Á +10 ÔÂ@163.com 2026-04-11 10/500 2026-04-12 09:14 by zhouyuwinner
[¿¼ÑÐ] 344 ²ÄÁÏרҵ Çóµ÷¼Á211 ÎÞµØÓòÒªÇó +5 hualkop 2026-04-11 5/250 2026-04-11 23:13 by 852137818
[¿¼ÑÐ] 331Çóµ÷¼Á +5 Íõ¹ú˧ 2026-04-11 5/250 2026-04-11 22:56 by Ϫ½§Á÷Ë®
[¿¼ÑÐ] »¯¹¤Çóµ÷¼Á£¡ +35 RichLi_ 2026-04-06 35/1750 2026-04-11 11:02 by zhq0425
[¿¼ÑÐ] Çóµ÷¼Á +6 archer.. 2026-04-09 8/400 2026-04-11 10:55 by zhq0425
[¿¼ÑÐ] ũѧ0904 312Çóµ÷¼Á +6 Say Never 2026-04-10 6/300 2026-04-11 10:33 by wwj2530616
[¿¼ÑÐ] ²ÄÁÏ085601µ÷¼Á +25 ºÎÈó²É123 2026-04-10 27/1350 2026-04-10 23:17 by Ftglcn90
[¿¼ÑÐ] 083200 305·Ö Çó¶þÂÖµ÷¼Á ²»½ÓÊÜ¿çרҵ +9 Claireyyyy 2026-04-09 10/500 2026-04-10 21:21 by Claireyyyy
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +5 hzhahg 2026-04-06 5/250 2026-04-10 10:10 by may_ÐÂÓî
[¿¼ÑÐ] 293·ÖÇóµ÷¼Á£¬ÍâÓïΪ¶íÓï +7 ¼ÓÒ»Ò»¾Å 2026-04-07 10/500 2026-04-08 20:14 by yutian743
[¿¼ÑÐ] 071000ÉúÎïѧ£¬Ò»Ö¾Ô¸ÉîÛÚ´óѧ296·Ö£¬Çóµ÷¼Á +12 TIckLw 2026-04-06 13/650 2026-04-07 20:34 by lijunpoly
[¿¼ÑÐ] 325 µ÷¼Á +6 QQСϺ 2026-04-07 6/300 2026-04-07 15:17 by Ccclqqq
[¿¼ÑÐ] 328Çóµ÷¼Á +4 ghhh88888 2026-04-06 5/250 2026-04-07 14:45 by ghhh88888
[¿¼ÑÐ] 0854Çóµ÷¼Á +9 ºàÊÏ·¬ÇÑɳ˾ 2026-04-06 10/500 2026-04-07 14:37 by shdgaomin
[¿¼ÑÐ] 283Çóµ÷¼Á +5 baiiyu 2026-04-05 6/300 2026-04-05 20:35 by à£à£à£0119
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û