There are two methods of image compression in matlab (DCT method and run-length coding compression method)

The DCT (Discrete Cosine Transform) compression method is one of the most advanced image compression encoding methods in modern times. After searching a lot of information and reading a few parts of the code, I will talk about my understanding of using DCT with matlab.

DCT is to use 8*8 small matrix blocks to divide the grayscale image into many small blocks. Of course, it is not necessary to divide it into 8*8 small modules, and it can be converted to DCT as a whole; when we get a picture, we need to It is compressed and we use 8*8 modules to divide; according to mathematics, we know that if we want to use 8*8 to divide and leave no remaining parts, the picture must be a multiple of 8, so the first step we read After finishing the picture, convert it into a grayscale image, read the rows and columns of the grayscale image, and convert the rows and columns into multiples of 8, so that we can completely separate them, and then we can use the functions that come with the system for DCT conversion. You can also write it yourself (writing by yourself means converting all 8*8 small matrices with a for loop).

picture2=zeros(x,y);
for i=1:8:x
    for j=1:8:y
        transition1=picture1(i:i+7,j:j+7);
        transition2=dct2(transition1);
        picture2(i:i+7,j:j+7)=transition2;
    end
end

Then we get the overall DCT coefficients. The next step is to reverse the DCT. If we write it ourselves, we also write it in a for loop; after the reverse conversion, we get the compressed picture;

The operation of the run-length coding compression method is relatively simple, and the decompression is relatively fast; the principle is to divide the connected pixels into two numbers, the first number is how many connected to the same pixels, and the second number is How much is the pixel in the pixel index table; for example, 0506 means that there are five consecutive identical pixels, and the position of the pixel in the pixel index table is 06; this greatly reduces the size of the picture; but this compression It seems that no picture can be formed, it can only be in the form of one-dimensional data; but the size of the picture is greatly reduced; first read the picture and create it into one-dimensional data, use the one-dimensional data for calculation, and then convert it into two-dimensional data ;

Guess you like

Origin blog.csdn.net/new_EAGLE/article/details/125767585