Highly Nonlinear Approximations for Sparse Signal Representation

Logo EPSRC

SCEIF Example

Example demonstrating the use of the Self Contained Encrypted Image Folding Software routines on the image of the nebula NGC 2264 created at the European Southern Observatory (ESO).

Download the MATLAB code for this example here.

Contents

% SCEIF_Example This example demonstrates the use of the Self Contained
% Encrypted Image Folding Software (SCEIF) by reproducing an example in the
% paper:
%
%  [1]  Self Contained Encrypted Image Folding
%
% The SCEIF method is applied to the image before saving as raw and
% clearing the workspace.
% The recovery is then performed and the results displayed using the
% correct and incorrect private keys.
%
% OPTIONAL:
% 1) The included test image is the image of the nebula NGC 2264 stored as
% a raw file.  To use your own image change the imagePath variable, line 33
% to the path where your image is stored.  If the image is not in .raw
% format uncomment line 38 to convert it to raw.
% 2) The approximation quality can be changed by altering the PSNRApprox
% variable (line 62).  This is the desired PSNR in the approximation.
% 3) For a much faster implementation please use the C++ implementations of
% OMP2DMl and OMP2D.  For this run the CompileMex.m script.
% 4) The default algorithm OMPMl2DW processes the three colour plains
% (R,G,B) together returning a single set of indexes and three sets of
% coefficients. This can be changed to OMPMl2DW to process each colour
% plain seperatly by uncommenting line 50.

% Clear all variables from the workspace before starting
    close all;
    clear all;
    clc;

Approximation Variables

% Path to image
    imagePath = 'red_astro.raw';
% - - > > #

% If using a standard image file format uncomment below to convert to
% raw.
%          imagePath = ImageTo16BitRaw(imagePath);
% - - > > #

% Details of the dicitonary used in the approximation
    sApproxDetails.approxMethod = 'Dictionary';
    sApproxDetails.sDetails = struct('name',{'DCT','Hats','Cubic','Cubic'...
        },'parameters',{2,1,1,2});
 % - - > > #

% Approximation algorithm
%   Uncomment desired alg
    algorithm = 'OMP2DMlW';
%     algorithm = 'OMP2DW';
% - - > > #

% Public key to prevent plain text attacks
    publicKey = 19;
% - - > > #

% Save known variables
    save known_vars sApproxDetails algorithm publicKey
% - - > > #

% Desired approximation quality
    PSNRApprox = 39.565;
% - - > > #

Image Approximation

% Approximate the image
    sImageApprox = SImageApproxSCEIFS(imagePath,PSNRApprox,'greedy2D',algorithm,...
        sApproxDetails);
    approxTime = sImageApprox.approxTime
% - - > > #

% Save summary vars
    save summary_vars sImageApprox approxTime
% - - > > #
MImageApproxSCEIFS Routine called
*********************************
Processing supplied image matrix using OMP2DMlW in blocks of 8 x 8
The image has an approximate maximum intensity of 65535
The SR of the approximation is 17.4554
PSNR: 42.50dB SSIM: 0.997

approxTime =

   12.8038

Fold the image

% Encryption Variable
    privateKey = 1234567891;
% - - > > #

% Fold the image
    startTime = clock;
    mImageFolded = Folding(sImageApprox,sApproxDetails,publicKey,privateKey);
    foldTime = etime(clock,startTime)
% - - > > #

% Save variables required for summary information
    save('summary_vars','foldTime','mImageFolded','-append');
% - - > > #

% Save the image as a lossless png file
%   Use PNG as this supports 48 bit truecolour
    saveImagePath = 'SCEIF_folded.raw';
    savePrecision = 'uint16';
    SaveImageRaw(mImageFolded,saveImagePath,savePrecision);
% - - > > #

% Clear workspace to make sure all needed info is in the saved file
    clear all;
% - - > > #
FoldApproxMl Routine Called
***************************
Folded Image: 88 x 1280 x 3 pixels, 11 x 160 blocks
Folding plain 1:- 2.53 seconds
Folding plain 2:- 2.48 seconds
Folding plain 3:- 2.49 seconds

FoldIndexGrey Routine Called
****************************
Folding Indexes:- 2.64 seconds

foldTime =

   11.0083

Expand using the incorrect private key

% Load the folded image
    loadImagePath = 'SCEIF_folded.raw';
    savePrecision = 'uint16';
    mImageLoaded = double(LoadImageRaw(loadImagePath,savePrecision));
% - - > > #

% Encryption Variables
    privateKey = 1234567890; % Incorrect private key
% - - > > #

% Recover the image
    % Load required know variables
        sKnown = load('known_vars','sApproxDetails','publicKey');
    % - - > >

    [mImageRecovered1 cImage] = Expand(mImageLoaded,sKnown.sApproxDetails,...
        sKnown.publicKey,privateKey);
% - - > > #

% Save variables required for summary information
    save('summary_vars','mImageRecovered1','-append');
% - - > > #

% Display figures
    % Load the original image
        load('summary_vars','sImageApprox');
    % - - > >

    % Display fig 2 from the paper
        ShowFig2(RUint16(sImageApprox.mImage));
    % - - > >

    % Display fig 3 from the paper
        ShowFig3(uint16(mImageLoaded),...
            cellfun(@RUint16,cImage,'UniformOutPut',0),...
            uint16(mImageRecovered1),'Incorrect Private Key');
    % - - > >
% - - > > #

% Report quality of the recovery from the folding procedure
    fprintf('\nQuality of the recovery (Original Image / Recovered Plain Text Image)\n')
    fprintf('Incorrect Key: ');
    PrintPSNR(sImageApprox.mImage,mImageRecovered1,sImageApprox.maxIntensity);
% - - > > #

% Clear workspace to make sure all needed info is in the saved file
    clear all;
% - - > > #
ExpandIndexGrey Routine Called
******************************
Time to seperate the embedded image (F) from the host image: 2.63 seconds

ExpandImageRGB Routine Called
*****************************
Time to seperate the embedded image (F) from the host image: 3.04 seconds
Time to reconstruct the rest of the image: 1.48 seconds
Time to seperate the embedded image (F) from the host image: 4.24 seconds
Time to reconstruct the rest of the image: 0.76 seconds
Time to seperate the embedded image (F) from the host image: 2.70 seconds
Time to reconstruct the rest of the image: 0.76 seconds

Quality of the recovery (Original Image / Recovered Plain Text Image)
Incorrect Key: PSNR: 10.57dB

Expand using the correct private key

% Load the folded image
    loadImagePath = 'SCEIF_folded.raw';
    savePrecision = 'uint16';
    mImageLoaded = double(LoadImageRaw(loadImagePath,savePrecision));
% - - > > #

% Encryption Variable
    privateKey = 1234567891; % Correct private key
% - - > > #

% Recover the image
    startTime = clock;
    % Load required know variables
        sKnown = load('known_vars','sApproxDetails','publicKey');
    % - - > > #
    [mImageRecovered2 cImage] = Expand(mImageLoaded,sKnown.sApproxDetails,...
        sKnown.publicKey,privateKey);
    expandTime = etime(clock,startTime);
% - - > > #

% Save variables required for summary information
    save('summary_vars','expandTime','mImageRecovered2','-append');
% - - > > #

% Report quality of the recovery from the folding procedure
    % Load the original image
        load('summary_vars','sImageApprox');
    % - - > >
    fprintf('\nQuality of the recovery (Original Image / Recovered Plain Text Image)\n')
    fprintf('Correct Key: ');
    PrintPSNRSSIM(sImageApprox.mImage,mImageRecovered2,sImageApprox.maxIntensity);
% - - > > #

% Display fig 3 from the paper
    ShowFig3(uint16(mImageLoaded),...
    cellfun(@RUint16,cImage,'UniformOutPut',0),...
    uint16(mImageRecovered2),'Correct Private Key');
% - - > > #
ExpandIndexGrey Routine Called
******************************
Time to seperate the embedded image (F) from the host image: 2.70 seconds

ExpandImageRGB Routine Called
*****************************
Time to seperate the embedded image (F) from the host image: 2.67 seconds
Time to reconstruct the rest of the image: 0.77 seconds
Time to seperate the embedded image (F) from the host image: 2.66 seconds
Time to reconstruct the rest of the image: 0.75 seconds
Time to seperate the embedded image (F) from the host image: 4.48 seconds
Time to reconstruct the rest of the image: 1.47 seconds

Quality of the recovery (Original Image / Recovered Plain Text Image)
Correct Key: PSNR: 42.50dB SSIM: 0.997

Print Summary

% Load the summary info
    load summary_vars
% - - > > #

% Print summary of approx
    fprintf('\n--------------------------------------------------------------------\n');
    PrintWithStars('Summary');
    fprintf('Quaility of the approximation (Original Image / Plain Text Image)\n')
    PrintPSNRSSIM(sImageApprox.mImage,sImageApprox.mImageApprox,...
        sImageApprox.maxIntensity);
    fprintf('Quality of the recovery (Original Image / Recovered Plain Text Image)\n')
    fprintf('Correct Key:   ');
    PrintPSNRSSIM(sImageApprox.mImage,mImageRecovered2,...
        sImageApprox.maxIntensity);
    fprintf('Incorrect Key: ');
    PrintPSNR(sImageApprox.mImage,mImageRecovered1,sImageApprox.maxIntensity);
    PrintWithStars('Image Dimensions');
    fprintf('Plain Text Image\n');
    fprintf('%4i x %4i x %1i\n',sImageApprox.y,sImageApprox.x,sImageApprox.z);
    fprintf('Folded Image\n');
    fprintf('%4i x %4i x %1i\n',size(mImageFolded));
    PrintWithStars('Execution Times');
    fprintf('Approximation: %.2f seconds (Building the Plain Text Image)\n',approxTime);
    fprintf('Folding:       %.2f seconds\n',foldTime);
    fprintf('Expanding:     %.2f seconds\n',expandTime);
    fprintf('Total Time:    %.2f seconds\n',approxTime+foldTime+expandTime);
    fprintf('\n--------------------------------------------------------------------\n')
% - - > > #
--------------------------------------------------------------------

Summary
*******
Quaility of the approximation (Original Image / Plain Text Image)
PSNR: 42.50dB SSIM: 0.997
Quality of the recovery (Original Image / Recovered Plain Text Image)
Correct Key:   PSNR: 42.50dB SSIM: 0.997
Incorrect Key: PSNR: 10.57dB

Image Dimensions
****************
Plain Text Image
1464 x 1280 x 3
Folded Image
 120 x 1280 x 3

Execution Times
***************
Approximation: 12.80 seconds (Building the Plain Text Image)
Folding:       11.01 seconds
Expanding:     17.12 seconds
Total Time:    40.93 seconds

--------------------------------------------------------------------