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 = untitled(varargin)
% UNTITLED M-file for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property'.'Value',...). creates anew UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFunction gets called.  An
%      unrecognized property name orinvalid value makes property application % stop. All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2. 5 08-May- 2021. 09:30:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_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 untitled is made visible.
function untitled_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 untitled (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled_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;


% --- Executes on button press in OpenImage.
function OpenImage_Callback(hObject, eventdata, handles)
% hObject    handle to OpenImage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global mydata
[filename,pathname]=uigetfile('*. *'.'select picture to open');
if filename==0
    return; end str=[pathname,filename]; mydata.a=imread(str); mydata.a=rgb2gray(mydata.a); axes(handles.YsImage); imshow(mydata.a); % buttonset(handles.OpensyImage, 'Enable'.'on');
 set(handles.AddImage, 'Enable'.'off');
 set(handles.Extractsy, 'Enable'.'off');
 set(handles.popupmenu1, 'Enable'.'off');
 set(handles.popupmenu2, 'Enable'.'off');
 set(handles.OutputImage, 'Enable'.'off');
 
 
 %clear static text

set(handles.text3, 'String'."); %clear nc %clear img2 TODO... cla(handles.SyImage, 'reset');
set(handles.SyImage, 'Box', 'on');
set(handles.SyImage, 'XTick', inf);
set(handles.SyImage, 'YTick', inf); cla(handles.ClhImage, 'reset');
set(handles.ClhImage, 'Box', 'on');
set(handles.ClhImage, 'XTick', inf);
set(handles.ClhImage, 'YTick', inf); cla(handles.TqsyImage, 'reset');
set(handles.TqsyImage, 'Box', 'on');
set(handles.TqsyImage, 'XTick', inf);
set(handles.TqsyImage, 'YTick', inf); % --- Executes on button press in AddImage. function AddImage_Callback(hObject, eventdata, handles) % hObject handle to AddImage (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global mydata cimage=mydata.a; a1_string=get(handles.popupmenu2,'String');
p1_string=a1_string{get(handles.popupmenu2,'Value')}; switch p1_string case '10 '
        alpha=10;
    case '20'
        alpha=20;
    case '30'
        alpha=30;
    case '40'
        alpha=40;
     case '50'
        alpha=50;
    case '60'
        alpha=60;
end
OutputImage=DCT(mydata.a,mydata.b,alpha);
a2_string=get(handles.popupmenu1,'String');
p2_string=a2_string{get(handles.popupmenu1,'Value')};
gjfs=gongji(OutputImage,p2_string);
mydata.c=gjfs;
axes(handles.ClhImage);
imshow(mydata.c);
set(handles.Extractsy, 'Enable'.'on');
set(handles.OutputImage, 'Enable'.'on');

function gjfs=gongji(image,gj)
switch (gj)
    case 'Not under attack'
        
        gjfs=image;
    case 'Add white noise'
        gjhimage=image;
        Wnoise=20*randn(size(gjhimage));
        Wnoise=uint8(Wnoise);
        gjhimage=gjhimage+Wnoise;
        gjfs=gjhimage;
    case 'Gaussian low-pass filtering'
       
        H=fspecial('gaussian'[4.4].0.5);
        gjfs=imfilter(image,H);
    case 'cut'
       gjhimage=image;
        gjhimage(1:128.1:128) =256;
        gjfs=gjhimage;
    case 'rotation'
        gjhimage=image;
        gjhimage=imrotate(gjhimage,10.'bilinear'.'crop');
        gjhimage=double(gjhimage);
        gjhimage=mat2gray(gjhimage);
        gjfs=gjhimage;
    case 'compression'
         gjhimage=image;
%          WImage5=a1;
             gjhimage=im2double(gjhimage);
%              gjhimage=wextend('2D'.'sym',gjhimage,8);
             cnum=10;
             dctm=dctmtx(8);
             P1=dctm;
             P2=dctm. ';
             imageDCT=blkproc(gjhimage,[8.8].'P1*x*P2',dctm,dctm. ');
             DCTvar=im2col(imageDCT,[8.8].'distinct'). ';
             n=size(DCTvar,1);
             DCTvar=(sum(DCTvar.*DCTvar)-(sum(DCTvar)/n).^2)/n;
             [dum,order]=sort(DCTvar);
             cnum=64-cnum;
Copy the code

3. Operation results

Fourth, note

Version: 2014 a