⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 project1_a_test2.m

📁 RLE=Run Lenght Coding for image.
💻 M
字号:
clear; clc; clf;

 A = imread('im_17_kodim15.tif'); % 8 bit gray; 256x256 
 colormap(gray);
% A =  [100  80  80  91  91 255 100  10;
%        10  10  11 123  10  10  11  10;  
%       255 255 255 255 100 100 100  10;   
%       100  80  80  91  91 255 100  10;
%        10  10  11 123  10  10  11  10;  
%       255 255 255 255 100 100 100  10]; 
A=f_addzero(A,4);
imshow(A);
%imagesc(A);
[m,n] = size(A);
B=[]; %reprezinta imginea facuta ca vector
C=[]; %reprezinta vectorul comprimat
 for i=1:m
     B=[B A(i,:)];
  end;

 B=[B 0];
    
   
 for i=1:m*n
    if B(i)==255, B(i)=254;
    end
 end

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%compresie1
%  h = 0; % contor de pixeli de aceesi valoare
%  i=1;
%  while i<m*n+1
%     i=i+1;
%     if B(i-1)==B(i),
%         h=1;
%         C=[C 255];
%         while B(i-1)==B(i),
%             i=i+1;
%             h=h+1; 
%         end
%         C=[C h];
%         C=[C B(i-1)]; 
%     else C=[C B(i-1)];
%     end
%  end
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%compresie2
 h = 0; % contor de pixeli de aceesi valoare
 i=1;
 while i<m*n+1
    i=i+1;
    if B(i-1)==B(i),
        h=1;
        C=[C 255];
        while ((B(i-1)==B(i)) && (i<m*n+1)),
            i=i+1;
            h=h+1;
            if h == 254
                C=[C h B(i-1) 255];
                h=0;
            end
        end
        C=[C h];
        C=[C B(i-1)]; 
    else C=[C B(i-1)];
    end
 end
i
disp('am terminat compresia');


 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% decompresie
 i=0;
 D=[]; %vectorul decomprimat
 
[p,q]=size(C)

 while i<q
     i=i+1
     if C(i)==255,
         for j=1:C(i+1)
             D=[D C(i+2)];
         end
     i=i+2;
     else D=[D C(i)];         
     end
 end
 
disp('am vectorul decomprimat');
 
E=[]; %imaginea refacuta
for i=1:m,
     for j=1:n,
         %E(i,j)=D(i,n*(j-1)+i);
         E(i,j)=D(n*(i-1)+j);
     end
 end
figure(2)
colormap(gray);
imagesc(E);

disp('imagine originala A');
a=size(A)
disp('imagine originala facuta vector +1 B');
b=size(B)
disp('vectorul comprimat C');
c=size(C)
d=size(D)
e=size(E)



% 
% %..............pas2....................
% [m,n] = size(A)
% %dimy = 500;
% %dimx = 600;
% % dimx=256;
% % dimy=256;
% A = A(1:m,1:n);
% imshow(A); pause; 
% 
% figure(1);
% for mask = 1:8,      % between 1 and 8
%     A_bin(:,:,mask) = bitget(A,mask);
%     subplot(2,4,mask), imagesc(A_bin(:,:,mask)), colormap(gray); 
%     title(num2str(mask));
% end;
% 
% %convert binary code to Gray code in each bit plan..
% figure(2)
% for mask = 1:8,      % between 1 and 8
%     a = bitshift(A, -1);
%     b = bitxor(A,a);
%     A_gray(:,:,mask) = bitget(b, mask);
%     subplot(2,4,mask), imagesc(A_gray(:,:,mask)), colormap(gray);
%     title(num2str(mask));
% end;
% 
% pause;
% figure(3);
% %replot in one figure only..
% for mask = 1:4,
%     subplot(2,4,mask), imagesc(A_bin(:,:,mask)), colormap(gray);title(num2str(mask));
% end;
% for mask = 1:4
%     subplot(2,4,4 + mask), imagesc(A_gray(:,:,mask)), colormap(gray);
% end;
% 
% figure(4);
% %replot in one figure only..
% for mask = 1:4,
%     subplot(2,4,mask), imagesc(A_bin(:,:,4+mask)), colormap(gray);title(num2str(4+mask));
% end;
% for mask = 1:4
%     subplot(2,4,4 + mask), imagesc(A_gray(:,:,4+mask)), colormap(gray);
% end;
% h=f_runlength(A)
% pause;
% c=dec2bin(h)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -