A list,

1 DCT algorithm:

DCT is the equivalent of a Discrete Fourier Transform of about twice the length of the DCT, which is performed on a real even function. Through the study of digital signal processing we know that the spectrum obtained by the Fourier transform of real functions is mostly complex, while the Fourier transform of even functions results in real functions. On this basis, it is one of the characteristics of cosine transformation to make the signal function even and remove the imaginary part of the spectral function. It can convert a set of light intensity data into frequency data in order to know how the intensity changes. If the high-frequency data is modified, it is obviously different from the original data when it is converted back to the original form, but it is not easily recognized by the human eye. During compression, the original image data is divided into 8*8 data element matrix, such as the first matrix of brightness value.



2. Engineering background of DCT generation:

The spectrum line of video signal is in the range of 0-6mhz, and most of the frequency spectrum lines contained in a video image are low-frequency spectrum lines, and only the video signal at the edge of the image, which accounts for a very low proportion of the image area, contains high-frequency spectrum lines. Therefore, in the digital processing of video signal, the number of bits can be allocated according to the spectrum factors: more bits can be allocated to the low spectrum region containing large amount of information, and less bits can be allocated to the high frequency spectrum region containing low amount of information, and the image quality has no perceptible damage, so as to achieve the purpose of bit rate compression. However, all of this requires a low Entropy value for efficient coding. The ability to encode a string of data effectively depends on the probability of each data occurrence. The large difference in the probability of occurrence of each data indicates that the entropy value is low and this string of data can be efficiently coded. On the contrary, the probability difference is small and the entropy value is high, so efficient coding cannot be carried out. The digitalization of the video signal is converted to the video level by A/D converter at A specified sampling frequency. The amplitude of the video signal of each pixel changes periodically with the time of each layer. The sum of the average information content of each pixel is the total average information content, namely the entropy value. Since each video level has almost equal probability, the entropy value of video signal is very high. The entropy value is a parameter that defines the compression rate of the bit rate. The compression rate of the video image depends on the entropy value of the video signal. In most cases, the video signal has a high entropy value. How do I get low entropy? This requires analysis of the characteristics of the video spectrum. In most cases, the amplitude of the video spectrum decreases as the frequency increases. Where the low frequency spectrum acquires zero to the highest level with almost equal probability. In contrast, the high frequency spectrum usually yields low levels and rare high levels. Obviously, the low frequency spectrum has a higher entropy value and the high frequency spectrum has a lower entropy value. Accordingly, the low frequency and high frequency components of video can be processed separately to obtain the compression value of high frequency.

Since Ahmed and Rao gave the definition of discrete cosine transform (DCT) in 1974, discrete cosine transform (DCT) and improved discrete cosine transform (MDCT) have become an important tool and technology widely used in signal processing and image processing, especially for image compression and speech compression codec. It has been the research hotspot of international academic circle and high-tech industry. Many image and video coding standards (e.g. Mpeg-1, MPG-2, and part 2 of MPG-4) require integer 8×8 DCT and IDCT, while MDCT and IMDCT are mainly used in audio signal codec (e.g. Mpeg-1, Mpg-2 and AC-] and other standard audio coding parts). Because this kind of transformation is widely used, it is very important to study the fast algorithm of this kind of transformation. In particular, the research of fast algorithms under specific application conditions is of great help to improve the performance of the whole system. As can be seen from the above reference, bit rate compression is based on transformation coding and entropy coding. The former is used to reduce entropy, while the latter transforms data into efficient encoding that reduces the number of bits. In MPEG standard, DCT is used for transformation coding. Although the transformation process itself does not produce bit-rate compression, the frequency coefficient after transformation is very conducive to bit-rate compression. In fact, the whole process of compression digital video signal is divided into block sampling, DCT, quantization and coding four main processes —– First, the original image is divided into N(horizontal)×N (vertical) sampling blocks in the time domain, and 4×4, 4×8, 8×8, 8×16, 16×16 blocks can be selected according to the need. These sampled pixel blocks represent the gray value of each pixel of the original image frame, which ranges from 139 to 163, and are sequentially fed into the DCT encoder to convert the sample blocks from the time domain to DCT coefficient blocks in the frequency domain. The conversion of the DCT system is carried out separately in each sample block, in which each sample is a digitized value representing the amplitude value of the corresponding pixel of the video signal in a field

3. Realization of discrete cosine transform:

There are many ways to realize DCT, the most direct is to calculate according to the definition of DCT. In the case of two-dimensional 8xSDCT, 4096 multiplications and 3584 additions are required. The realization of this algorithm requires a huge amount of calculation and has no practical value. In application, it is necessary to find fast and accurate algorithm. The more commonly used method is to make use of the separable characteristics of DCT. Similarly, taking two-dimensional 8xSDCT as an example, eight one-dimensional DCT rows need 64xS multiplication and 56xS addition first, and the next eight one-dimensional DCT rows need 64xS multiplication and 56xS addition. A total of 64x8xZ=1024 multiplications and 56x8xZ=896 additions are required, greatly reducing the amount of computation.

In addition, DCT has many fast algorithms that are publicly available. Fast algorithms reduce computation time mainly by reducing the number of operations, which is very effective for designing fast hardware systems. The fast algorithm of two-dimensional DCT generally adopts the DCT algorithm of column and column separation, that is, the DCT algorithm is converted into two one-dimensional transformations, which are connected by transpose matrix. The most classic and commonly used fast algorithms are THE AAN algorithm proposed by Arai et al in 1988 and the LLM algorithm proposed by Loeffier et al in 1989. However, because the DCT algorithm for row and column separation can reuse the one-dimensional transformation structure, it has more advantages in practical implementation, especially in hardware.

Ii. Source code

function varargout = imDCT(varargin)
% IMDCT M-file for imDCT.fig
%      IMDCT, by itself, creates a new IMDCT or raises the existing
%      singleton*.
%
%      H = IMDCT returns the handle to a new IMDCT or the handle to
%      the existing singleton*.
%
%      IMDCT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMDCT.M with the given input arguments.
%
%      IMDCT('Property'.'Value',...). creates anew IMDCT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before imDCT_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to imDCT_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help imDCT

% Last Modified by GUIDE v2. 5 07-Dec- 2009. 19:54:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @imDCT_OpeningFcn, ...
                   'gui_OutputFcn',  @imDCT_OutputFcn, ...
                   'gui_LayoutFcn', [],...'gui_Callback'[]);if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before imDCT is made visible.
function imDCT_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to imDCT (see VARARGIN)

% Choose default command line output for imDCT
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes imDCT wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = imDCT_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0.'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor'.'white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0.'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor'.'white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
ImgPath=get(handles.edit1,'String');
CompressRate=uint8(fix(str2num(get(handles.edit2,'String'))));
if CompressRate>64
    CompressRate=64;
end
if CompressRate<1
    CompressRate=1;
end
set(handles.edit2,'String',num2str(CompressRate));
img=imread(ImgPath);
axes(handles.axes1);
imshow(img);
set(handles.text7,'Visible'.'off');
set(handles.text7,'String'.'Processing status: in processing... ');
set(handles.text7,'Visible'.'on');
pause(0.1);
Block=ceil(size(img)/8);
ImgDCT=zeros(Block*8);
ImgRestoreTemp=zeros(Block*8);
ImgRestore=zeros(size(img));
ImgBlock=zeros(8);
DCTBlock=zeros(8);
vector=zeros(1.64);
for ii=1:Block(1)
    for jj=1:Block(2)
        ImgBlock(:,:)=zeros(8);
        if ii==Block(1)
            if jj==Block(2)
                ImgBlock(1:size(img,1)-(ii- 1) *8.1:size(img,2)-(jj- 1) *8)=img((ii- 1) *8+1:size(img,1),(jj- 1) *8+1:size(img,2));
            else
                ImgBlock(1:size(img,1)-(ii- 1) *8,:)=img((ii- 1) *8+1:size(img,1),(jj- 1) *8+1:jj*8);
            end
        else
            if jj==Block(2)
                ImgBlock(:,1:size(img,2)-(jj- 1) *8)=img((ii- 1) *8+1:ii*8,(jj- 1) *8+1:size(img,2));
            else
                ImgBlock(:,:)=img((ii- 1) *8+1:ii*8,(jj- 1) *8+1:jj*8);
            end
        end
        DCTBlock(:, :)=dct2(ImgBlock(:,:));
        if CompressRate~=64
            vector(1:64)=m2v(DCTBlock(:,:));
            vector(CompressRate+1:64) =0;
            DCTBlock(:,:)=v2m(vector(1:64));
        end
        ImgDCT((ii- 1) *8+1:ii*8,(jj- 1) *8+1:jj*8)=DCTBlock(:,:);
    end
end
Copy the code

3. Operation results

Fourth, note

Version: 2014 a