www.pudn.com > Block-Based_Image_Steganalysis_v1.zip > RandomSampling.m, change:2010-09-01,size:2837b


function [ random_sample ] = RandomSampling ( image_number, sample_no, BLOCK_NO, COVER_UCID, STEGO_UCID )
% 08-14-2009 Random Sampling from Cover and Stego Images
% USC EE SIPI MCL Steve Cho
tic;    % start a stopwatch timer
random_sample = [];
for image_index = 1:image_number
    % random order 
%     select_index = randperm(200);
    % increasing order
    for k = 1:image_number
        select_index( k ) = k;
    end
    cover_file = strcat( COVER_UCID, 'cover', num2str(image_index, '%.4d\n'), '.fea' );
    stego_file = strcat( STEGO_UCID, 'stego', num2str(image_index, '%.4d\n'), '.fea' );   
%     stego_test_file = strcat('D:\Research\Steganography\UCID\PQ\Features\stego',  num2str(image_index, '%.4d\n'), '.fea'  );
    random_index = randperm(BLOCK_NO);    % 24*32 = 768 blocks for each image
    fprintf( 'processing cover and stego image %d \n', select_index(image_index) );
        for file_index = 1:2
            % Random Sampling: For example, select 100 blocks for each image (50 cover blocks and 50 stego blocks)
            if file_index == 1  % cover image
                input_file = fopen (cover_file, 'r+');
                % Extract features from all the macroblocks
                for block_index = 1:BLOCK_NO
                    subimage_features = textscan(input_file, '%.5f ', 274);
                    image_features ( block_index, 1:274 ) = transpose( subimage_features{:} );
                end
                % Select macroblock randomly and save features from selected macroblocks
                for select_block_index = 1:sample_no
                    random_sample ( (image_index-1)*sample_no*2 + select_block_index, : ) = image_features ( random_index(select_block_index), :);
                end
            else    % file_index == 2   stego image
                input_file = fopen (stego_file, 'r+');
                for block_index = 1:BLOCK_NO
                    subimage_features = textscan(input_file, '%.5f', 274);
                    image_features ( block_index, 1:274 ) = transpose( subimage_features{:} );
                end
                for select_block_index = 1:sample_no
                    random_sample ( (image_index-1)*sample_no*2 + sample_no + select_block_index, : ) = image_features ( random_index(select_block_index), :);
                end
            end
            fclose(input_file);
        end     % for file_index = 1:2  % cover, stego
end     % for image_index = start_index:end_index
fprintf('End of processing.\n');
% Get the time needed for processing the current image
elasped_time = toc;
fprintf('----------------------------------\n');
fprintf('Total Time Consumption: %d Min %.0f Sec\n', floor( elasped_time/60), mod(elasped_time, 60) );

送体验金的网站