A list,

DCT Transform is called Discrete Cosine Transform (DCT). It is mainly used for data or image compression. It can Transform the signal from the airspace to the frequency domain, with good discorrelation performance. DCT transformation itself is lossless, but it creates good conditions for the following quantization and Havelman coding in the fields of image coding. Meanwhile, because DCT transformation is symmetric, we can use DCT inverse transformation after quantization coding to recover the original image information at the receiving end. DCT transform in the current image analysis has been compressed field has a very broad use, our common JPEG static image coding as well as MJPEG, MPEG dynamic coding standards have used DCT transform.

1. One-dimensional DCT transformationOne-dimensional DCT transformation is the basis of two-dimensional DCT transformation, so let’s discuss the next one-dimensional DCT transformation. There are eight forms of one-dimensional DCT transformation, among which the second form is the most commonly used, because of its simple operation and wide application range. We will only discuss this form here, which is expressed as follows:Where, f(I) is the original signal, f(u) is the coefficient after DCT transformation, N is the number of points of the original signal, and C (u) can be considered as a compensation coefficient, which can make the DCT transformation matrix an orthogonal matrix.

2. 2d DCT transformationTwo-dimensional DCT transformation is actually a DCT transformation based on one-dimensional DCT transformation, and its formula is as follows:From the formula, we can see that the above only discusses the case that the two-dimensional image data is square matrix. In practical application, if the data is not square matrix, the transformation is usually done after completion. After reconstruction, the completed part can be removed to obtain the original image information. In addition, due to the symmetry of the HEIGHT of DCT transform, we can use a simpler matrix processing method when using Matlab for related operations:

Ii. Source code

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % digital watermark embedding, attack, detect % % % % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all; clc; start_time=cputime; %%%%%%%%%%%% Read watermark image %%%%%%%% I=imread('mark.bmp');
I=rgb2gray(I);
I=double(I)/255; 
I=ceil(I); %%%%%%%%%% Display watermark image %%%%%%%%%%%%% figure(1);
subplot(2.3.1);
imshow(I),title('Watermark image')
dimI=size(I);
rm=dimI(1); cm=dimI(2); % % % % % % % % % % % % % % %5%% mark=I; alpha=50,

a0=imread('lena.bmp');
psnr_cover=double(a0);
subplot(2.3.2),imshow(a0,[]),title('Carrier image');
[r,c]=size(a0);
cda0=blkproc(a0,[8.8].'dct2'); %%%%%%%%%%%%%%%%%%%%% embedded %%%%%%%%%% cda1=cda0; % cda1 =256_256
for i=1:rm  % i=1:32
    for j=1:cm  % j=1:32
        x=(i- 1) *8; y=(j- 1) *8;
        if mark(i,j)= =1
        k=k1;
        else
        k=k2; 
        end
    cda1(x+1,y+8)=cda0(x+1,y+8) +alpha*k(1);
    cda1(x+2,y+7)=cda0(x+2,y+7)+alpha*k(2);
    cda1(x+3,y+6)=cda0(x+3,y+6)+alpha*k(3);
    cda1(x+4,y+5)=cda0(x+4,y+5)+alpha*k(4);
    cda1(x+5,y+4)=cda0(x+5,y+4)+alpha*k(5);
    cda1(x+6,y+3)=cda0(x+6,y+3)+alpha*k(6);
    cda1(x+7,y+2)=cda0(x+7,y+2)+alpha*k(7);
    cda1(x+8,y+1)=cda0(x+8,y+1)+alpha*k(8); End end %%%%%% Attack experiment test robustness %%%%%%%%%%% disp('To experiment with an attack on an embedded watermarked image, enter the selection:');
disp('1-- Add white noise ');
disp('2-- Gaussian low-pass filtering ');
disp('3 - JPEG compression');
disp('4-- Image cut ');
disp('5-- rotate by 10 degrees');
disp('6- Direct detection of watermark ');
disp('Other - do not attack');
d=input('Please enter a selection (1-6) :');
start_time=cputime;

    figure(1);
            switch d
                case 6
            subplot(2.3.4);
            imshow(a1,[]);
            title('Unattacked Watermarked image');
            M1=a1;                      
                case 1
             WImage2=a1;
             noise0=20*randn(size(WImage2));
             WImage2=WImage2+noise0;
             subplot(2.3.4);
             imshow(WImage2,[]);
             title('Image with white noise');
             M1=WImage2;
             M_1=uint8(M1);
             imwrite(M_1,'whitenoise.bmp'.'bmp');
                
                case 2
             WImage3=a1;
             H=fspecial('gaussian'[4.4].0.2);
             WImage3=imfilter(WImage3,H);
             subplot(2.3.4);
             imshow(WImage3,[]);
             title('Gaussian Low-pass filtered image');
             M1=WImage3;
             M_1=uint8(M1);
             imwrite(M_1,'gaussian.bmp'.'bmp');
             
                case 4
             WImage4=a1;
             WImage4(1:64.1:512) =512;
             %WImage4(224:256.1:256) =256;
             %WImage4(1:256.224:256) =256;
             %WImage4(1:256.1:32) =256;
             WImage4cl=mat2gray(WImage4);
             figure(2);
             subplot(1.1.1);
             %subplot(2.3.4);
             imshow(WImage4cl);
             title('Partially cut image');
             figure(1);
             M1=WImage4cl;
             %M_1=uint8(M1);
             %imwrite(M_1,'cutpart.bmp'.'bmp');
             function N=nc(mark_get,mark_prime)
mark_get=double(mark_get);
mark_prime=double(mark_prime);
if size(mark_get)~=size(mark_prime)
    error('Input vectors must  be the same size!')
else
    [m,n]=size(mark_get);
    fenzi=0;
    fenmu=0;
    for i=1:m
        for j=1:n
            fenzi=fenzi+mark_get(i,j)*mark_prime(i,j);
            fenmu=fenmu+mark_prime(i,j)*mark_prime(i,j);
        end
    end
Copy the code

Third, the operation result

Fourth, note

Version: 2014 a