实践课题:

  1. 自己项目总的代码量(行):474行
  2. 统计自己编写的代码量:388行
  3. 统计能讲明白,改的动的代码量:100行
  4. 提交不低于100行体现毕业设计水平,自己理解最透彻的代码,老师查看能不能修改,重现。

function test(TRN_cover_path,TRN_stego_path,TST_image_path)

Quality_factor = 75;

TRN_cover = load(TRN_cover_path);
TRN_stego = load(TRN_stego_path);

TRN_cover_data = TRN_cover.F_TRN_Cover;
TRN_stego_data = TRN_stego.F_TRN_Stego;

[F_TST,names] = feature_extraction(TST_image_path, Quality_factor);

[trained_ensemble,results] = ensemble_training(TRN_cover_data(1:1000,:),TRN_stego_data(1:1000,:));

test_results = ensemble_testing(F_TST,trained_ensemble);

for i = 1:size(names,2)
if test_results.predictions(i) == -1
fprintf([names{i},' 是载体图像!\n'])
end

if test_results.predictions(i) == 1
    fprintf([names{i},' 是隐写图像!\n'])
end

end
end

function F = DCTRV1(I_STRUCT, QF)

%% Set parameters
% number of histogram bins
T = 2;

% compute quantization step based on quality factor
if QF<50
q = min(8 * (50 / QF), 100);
else
q = max(8 * (2 - (QF/50)), 0.2);
end

%% Prepare for computing DCT bases
k=0:7;
l=0:7;
[k,l]=meshgrid(k,l);

A=0.5cos(((2.k+1).lpi)/16);
A(1,:)=A(1,:)./sqrt(2);
A=A';

%% Compute DCTR locations to be merged
mergedCoordinates = cell(15, 1);
kk=0;
for i=1:5
for j=1:5
if i<=j
kk = kk+1;
coordinates = [i,j; i,10-j; 10-i,j; 10-i,10-j; j,i; 10-j,i; j,10-i; 10-j,10-i];
coordinates = coordinates(all(coordinates<9, 2), 😃;
mergedCoordinates{kk} = unique(coordinates, 'rows');
end
end
end

%% Decompress to spatial domain
fun = @(x)x.data .*I_STRUCT.quant_tables{1};
I_spatial = blockproc(I_STRUCT.coef_arrays{1},[8 8],fun);
fun=@(x)idct2(x.data);
I_spatial = blockproc(I_spatial,[8 8],fun)+128;

%% Compute features
modeFeaDim = numel(mergedCoordinates)(2T+1);
% F = zeros(1, 28modeFeaDim, 'single');
modeIndex = 0;
for mode_r = 1:8
for mode_c = 1:8
if mode_r < mode_c
modeIndex = modeIndex + 1;
% Get DCT base for current mode
DCTbase1 = A(:,mode_r)
A(:,mode_c)';
DCTbase2 = A(:,mode_c)*A(:,mode_r)';

        % Obtain DCT residual R by convolution between image in spatial domain and the current DCT base
        R1 = conv2(I_spatial-128, DCTbase1, 'valid');
        R2 = conv2(I_spatial-128, DCTbase2, 'valid');
        Rmin = min(R1,R2);
        Rmax = max(R1,R2);

        % Quantization, rounding, absolute value, thresholding
        Rmin = (round(Rmin / q));      
        Rmin(Rmin > T) = T;
        Rmin(Rmin <-T) =-T;
        Rmax = (round(Rmax / q));      
        Rmax(Rmax > T) = T;
        Rmax(Rmax <-T) =-T;

        % Core of the feature extraction
        for merged_index=1:numel(mergedCoordinates)
            fmin_merged = zeros(1, 2*T+1, 'single');
            fmax_merged = zeros(1, 2*T+1, 'single');
            for coord_index = 1:size(mergedCoordinates{merged_index}, 1)
                r_shift = mergedCoordinates{merged_index}(coord_index, 1);
                c_shift = mergedCoordinates{merged_index}(coord_index, 2);
                Rmin_sub = Rmin(r_shift:8:end, c_shift:8:end);
                fmin_merged = fmin_merged + hist(Rmin_sub(:), -T:T);
                Rmax_sub = Rmax(r_shift:8:end, c_shift:8:end);
                fmax_merged = fmax_merged + hist(Rmax_sub(:), -T:T);
            end
            F_index_from = (modeIndex-1)*modeFeaDim+(merged_index-1)*(2*T+1)+1;
            F_index_to = (modeIndex-1)*modeFeaDim+(merged_index-1)*(2*T+1)+2*T+1;
            F1 = fmin_merged / sum(fmin_merged);
            F2 = fmax_merged / sum(fmax_merged);
            Fmin(F_index_from:F_index_to) = F1;
            Fmax(F_index_from:F_index_to) = fliplr(F2);
        end
    end
end

end
F = (Fmin+Fmax)/2;
end

posted on 2021-05-31 22:55  20175321wdc  阅读(164)  评论(0编辑  收藏  举报