Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
how can i separte texte and background and compresse each one séparatelly (compression old image document)
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
clear all;     
close all;
clc;
f=imread('manuscrit1.tif'); %insérer the image.
imshow(f)
title('image originalle')   %pour afficher l'image originale.
infos = whos('auto.tif');
fprintf('la taille de lmage originale est :' )
infos.bytes
%------------------------redimensionner l'image---------
BlockSize = 64;   %la taille de chaque bloque 
[rows1, columns1, numberOfColorChannels] = size(f);
e1=floor(rows1/BlockSize);
e2=floor(columns1/BlockSize);
    h1 = e1*BlockSize;
    h2 = e2*BlockSize;
J = imresize(f,[h1 h2]) ;
%----------------------------------------------------------------------
imgTSV=rgb2hsv(J);  % pour tranformer l'image au systeme TSV
imshow(imgTSV)
title('en TSV')   %pour afficher l'image originale.
%T Component of Colour Image
Tcom= imgTSV(:,:,1);
%S Component of Colour Image
Scom=imgTSV(:,:,2);
%V Component of Colour Image
Vcom=imgTSV(:,:,3);
%---------------------Dévision en block----------------------------------------
[rows, columns] = size(Tcom);
wholeBlockRows = floor(rows / BlockSize);
wholeBlockCols = floor(columns /BlockSize);
%---------------------dwt avec dévision------------------------
%--------------pour le composant T---------------------------
TOTAL_BLOCKS = wholeBlockRows*wholeBlockCols ;
dividedImage = zeros([BlockSize BlockSize TOTAL_BLOCKS]);
%-----_---------------------------------------------------------------------------------------------
T=BlockSize*wholeBlockCols;%on utilise ces parametre pour la partie de reconstuire l'image
 image11=zeros(h1,h2,3); %create an rgb empty image 
imgTSV1=rgb2hsv(image11);
Tcom1= imgTSV1(:,:,1)
%S Component of Colour Image       %cette partie pour créer une image vide afin de réccuper l'avant plan
Scom1=imgTSV1(:,:,2);
%V Component of Colour Image
Vcom1=imgTSV1(:,:,3);
          % pour récupeérer l'arrier plan
 image22=zeros(h1,h2,3); 
imgTSV2=rgb2hsv(image22);
Tcom11= imgTSV2(:,:,1);
%S Component of Colour Image      
Scom11=imgTSV2(:,:,2);
%V Component of Colour Image
Vcom11=imgTSV2(:,:,3);
%---------------------------------------------------------------------------------------
row = 1;
col = 1;
%-----_---------------------------------------------------------------------------------------------
T=BlockSize*wholeBlockCols;%on utilise ces parametre pour la partie de reconstuire l'image
%---------------------------------------------------------------------------------------
    for count=1:TOTAL_BLOCKS
        dividedImage1(:,:,count) = Tcom(row:row+BlockSize-1,col:col+BlockSize-1);
        col = col + BlockSize;
        if(col >= size(Tcom,2))
            col = 1;
            row = row + BlockSize;
            if(row >= size(Tcom,1))
                row = 1;
            end
        end
     %il est possible d'utiliser une forme simple de DWT mais la fonction BLOCKPLROC mieux pour bien préciser la taille de chaque BLOCK.       
      fun1 = @(block_struct) nth_output(1, @dwt2, block_struct.data,'db4');
      fun2 = @(block_struct) nth_output(2, @dwt2, block_struct.data,'db4');
      fun3 = @(block_struct) nth_output(3, @dwt2, block_struct.data,'db4');
      fun4 = @(block_struct) nth_output(4, @dwt2, block_struct.data,'db4');
      cAt = blockproc(dividedImage1(:,:,count),[BlockSize BlockSize],fun1);
      cHt= blockproc(dividedImage1(:,:,count),[BlockSize BlockSize],fun2);
      cVt= blockproc(dividedImage1(:,:,count),[BlockSize BlockSize],fun3);
      cDt= blockproc(dividedImage1(:,:,count),[BlockSize BlockSize],fun4);
       vt1=reshape(cHt,[],1);   %pour regrouper la matrice LHt à un vecteur
       vt2=reshape(cVt,[],1);   %pour regrouper la matrice HLt à un vecteur
       vt3=[vt1; vt2]; %pour linaisiser les deux premier HL et LH dans un seul vecteur
%--------------pour le composant S---------------------------
        dividedImage2(:,:,count) = Scom(row:row+BlockSize-1,col:col+BlockSize-1);
        col = col + BlockSize;
        if(col >= size(Scom,2))
            col = 1;
            row = row + BlockSize;
            if(row >= size(Scom,1))
                row = 1;
            end
        end
       fun5= @(block_struct) nth_output1(1, @dwt2, block_struct.data,'db4');
       fun6 = @(block_struct) nth_output1(2, @dwt2, block_struct.data,'db4');
       fun7= @(block_struct) nth_output1(3, @dwt2, block_struct.data,'db4');
       fun8= @(block_struct) nth_output1(4, @dwt2, block_struct.data,'db4');
       cAs= blockproc(dividedImage2(:,:,count),[BlockSize BlockSize],fun5);
       cHs= blockproc(dividedImage2(:,:,count),[BlockSize BlockSize],fun6);
       cVs= blockproc(dividedImage2(:,:,count),[BlockSize BlockSize],fun7);
       cDs= blockproc(dividedImage2(:,:,count),[BlockSize BlockSize],fun8);
       vs1=reshape(cHs,[],1);   %pour regrouper la matrice LHt à un vecteur
       vs2=reshape(cVs,[],1);   %pour regrouper la matrice HLt à un vecteur
       vs3=[vs1; vs2]; %pour linaisiser les deux premier HL et LH dans un seul vecteur
%--------------pour le composant V---------------------------
        dividedImage3(:,:,count) = Vcom(row:row+BlockSize-1,col:col+BlockSize-1);
        col = col + BlockSize;
        if(col >= size(Vcom,2))
            col = 1;
            row = row + BlockSize;
            if(row >= size(Vcom,1))
                row = 1;
            end
        end
        fun9= @(block_struct) nth_output2(1, @dwt2, block_struct.data,'db4');
        fun10= @(block_struct) nth_output2(2, @dwt2, block_struct.data,'db4');
        fun11= @(block_struct) nth_output2(3, @dwt2, block_struct.data,'db4');
        fun12= @(block_struct) nth_output2(4, @dwt2, block_struct.data,'db4');
        cAv= blockproc(dividedImage3(:,:,count),[BlockSize BlockSize],fun9);
        cHv= blockproc(dividedImage3(:,:,count),[BlockSize BlockSize],fun10);
        cVv= blockproc(dividedImage3(:,:,count),[BlockSize BlockSize],fun11);
        cDv= blockproc(dividedImage3(:,:,count),[BlockSize BlockSize],fun12);
        vv1=reshape(cHv,[],1);   %pour regrouper la matrice LHt à un vecteur
        vv2=reshape(cVv,[],1);   %pour regrouper la matrice HLt à un vecteur
        vv3=[vv1; vv2]; %pour linaisiser les deux premier HL et LH dans un seul vecteur
%-----------------on regroupe tout les HL et LH dans seul vector----------
        vhr = [vt3; vs3; vv3] ;
%---------pour calculer la variance de chaque block-----------
  vari = var(vhr) 
%---------------------condition de seuil (threshold)---------------
 seuil =  0.001 ;        %inserer une valeur .
   if (vari > seuil)
           Av1 =  dividedImage1(:,:,count) ;
           Av2 =  dividedImage2(:,:,count) ;
           Av3 =  dividedImage3(:,:,count) ;
        %.-----------------reconstruire une image avant plant
     if(count==1)       %.-----------------reconstruire une image Tcom1
                          Tcom1(3:3+size(Av1,1), 3:3+size(Av1,2), :) = Av1;    
     else                     
                v2=count-1;
                         Tcom1(BlockSize*v2+count:BlockSize*count,BlockSize*v2+count:BlockSize*count,:) = Av1;    
     end
     if(count==1)       %.-----------------reconstruire une image Tcom1
                          Scom1(1:BlockSize, 1:BlockSize, :) = Av2;    
     else                     
                v2=count-1;
                         Tcom1(Blocksize*v2+count:BlockSize*count , Blocksize*v2+count:BlockSize*count, :) = Av2;    
     end
     if(count==1)       %.-----------------reconstruire une image Vcom1
                          Scom1(1:BlockSize, 1:BlockSize, :) = Av3;    
     else                     
                v2=count-1;
                         Tcom3(Blocksize*v2+count:BlockSize*count , Blocksize*v2+count:BlockSize*count, :) = Av3;    
     end
     else            %--------reconstruire une image arriere plant 
           Av1 =  dividedImage1(:,:,count) ;
           Av2 =  dividedImage2(:,:,count) ;
           Av3 =  dividedImage3(:,:,count) ;
     if(count==1)       %.-----------------reconstruire une image Tcom11
                          Tcom11(1:BlockSize, 1:BlockSize, :) = Av1;    
     else                     
                v2=count-1;
                         Tcom11(Blocksize*v2+count:BlockSize*count , Blocksize*v2+count:BlockSize*count, :) = Av1;    
     end
     if(count==1)       %.-----------------reconstruire une image Tcom1
                          Scom11(1:BlockSize, 1:BlockSize, :) = Av2;    
     else                     
                v2=count-1;
                         Scom11(Blocksize*v2+count:BlockSize*count , Blocksize*v2+count:BlockSize*count, :) = Av2;    
     end
                 if(count==1)       %.-----------------reconstruire une image Tcom1
                          Vcom11(1:BlockSize, 1:BlockSize, :) = Av3;    
     else                     
                v2=count-1;
                         Vcom11(Blocksize*v2+count:BlockSize*count , Blocksize*v2+count:BlockSize*count, :) = Av3;    
                 end
    end
    end
    tsvAVP= cat(3, Tcom1, Scom1, Vcom1);     %pour aficher l'image avant plan
    AVPimage=hsv2rgb(tsvAVP); 
    subplot(2,1,1)
    imshow(AVPimage)
    title('image avant plan')
    tsvARP= cat(3, Tcom11, Scom11, Vcom11);   %pour afficher l'image arriere plan
    AVPimage=hsv2rgb(tsvARP); 
    subplot(2,1,2)
    imshow(ARPimage)
    title('image arriere plan')
댓글 수: 2
  Image Analyst
      
      
 2020년 5월 11일
				Well, let's start by you attaching your image and your m-file.  Then we can run your code and begin to help you.  Also, please edit and format the code as code with the Code icon.
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!