complex loop help--Matlab

This is a discussion on complex loop help--Matlab within the Tech Board forums, part of the Community Boards category; Hi I am working on following data hiding algorithm in images using Matlab Example: Suppose the cipher text to be ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    8

    complex loop help--Matlab

    Hi

    I am working on following data hiding algorithm in images using Matlab

    Example: Suppose the cipher text to be sent is: 11001011 01111010 10101010 10011001 01010101. This data is five bytes. So n=5 and p=2. Suppose the different bytes of the digital image are A,B,C,D,E etc. From table-3 we can see that in byte A of the carrier file we embeded the data bits 11 in 6th and 8th bit locations, and next value of p becomes 0. We embed the next data bits 00 into byte B in 6th and 7th bit locations, next value of p becomes 1. Now we embed the next two bits 10 in C in 7th and 8th bit locations and so on.

    Carrier FileByte Operation location IndexVariable,P
    Byte A Embed (11) 6th and 8th 2
    Byte B Embed (00) 6th and 7th 0
    Byte C Embed (10) 7th and 8th 1
    Byte D Embed (11) 6th and 8th 2
    Byte E Embed (01) 6th and 7th 0
    Byte F Embed (11) 7th and 8th 1
    Byte G Embed (10) 6th and 8th 2
    Byte H Embed (10) 6th and 7th 0
    Byte I Embed (10) 7th and 8th 1
    Byte J Embed (10) 6th and 8th 2
    Byte K Embed (10) 6th and 7th 0
    Byte L Embed (10) 7th and 8th 1
    so on………
    I have used following logic-

    I have converted image into row format and storing the ciphertext length in 7th&8th bits of first four pixles

    using below logic in attached file for this

    pv=v(1,1);
    pb=dec2bin(pv,8);
    pb(7)=b(1);
    pb(8)=b(2);
    pv=bin2dec(pb);
    v(1,1)=pv;
    pv=v(1,2);
    pb=dec2bin(pv,8);
    pb(7)=b(3);
    pb(8)=b(4);
    pv=bin2dec(pb);
    v(1,2)=pv;
    pv=v(1,3);
    pb=dec2bin(pv,8);
    pb(7)=b(5);
    pb(8)=b(6);
    pv=bin2dec(pb);
    v(1,3)=pv;
    pv=v(1,4);
    pb=dec2bin(pv,8);
    pb(7)=b(7);
    pb(8)=b(8);
    pv=bin2dec(pb);
    v(1,4)=pv;
    Now I want to store bits of my ciphertext following way

    Say ciphertext is 11001011 01111010 10101010 10011001 01010101

    This data is five bytes. So n=5 therefore p=2 ((Mod(n,3))

    Carrier FileByte Operation location IndexVariable,P
    (1,5) Embed (11) 6th and 8th 2
    (1,6) Embed (00) 6th and 7th 0
    (1,7) Embed (10) 7th and 8th 1
    (1,8) Embed (11) 6th and 8th 2
    (1,9) Embed (01) 6th and 7th 0
    (1,10) Embed (11) 7th and 8th 1
    (1,11) Embed (10) 6th and 8th 2
    (1,12) Embed (10) 6th and 7th 0
    (1,13) Embed (10) 7th and 8th 1
    (1,14) Embed (10) 6th and 8th 2
    (1,15) Embed (10) 6th and 7th 0
    (1,16) Embed (10) 7th and 8th 1
    --so on
    But i am not getting how to implement above logic..

    I am calculating index variable and based on its value taking locations as fixed..in this case p=2 so embedding data in each 6th and 8th bit locations of next pixels which is not as per above table.. I am struggling in framing above logic in Matlab where bit locations and index variable are changing.

    my code as below. pls provide me direction

    Thanks in Advance


    my code---


    global l ciphertxt;

    [f p]=uigetfile('*.*','Open Cover Image');
    fp=[p f];

    im=imread(fp);
    [r c n]=size(im);
    if n==3
    im=rgb2gray(im);
    end

    figure;
    imshow(im)
    title('Input Image')

    v=reshape(im,1,r*c);

    b=dec2bin(l,8);

    pv=v(1,1);
    pb=dec2bin(pv,8);
    pb(7)=b(1);
    pb(8)=b(2);
    pv=bin2dec(pb);
    v(1,1)=pv;

    pv=v(1,2);
    pb=dec2bin(pv,8);
    pb(7)=b(3);
    pb(8)=b(4);
    pv=bin2dec(pb);
    v(1,2)=pv;

    pv=v(1,3);
    pb=dec2bin(pv,8);
    pb(7)=b(5);
    pb(8)=b(6);
    pv=bin2dec(pb);
    v(1,3)=pv;

    pv=v(1,4);
    pb=dec2bin(pv,8);
    pb(7)=b(7);
    pb(8)=b(8);
    pv=bin2dec(pb);
    v(1,4)=pv;

    l=length(ciphertxt);

    for i=1:l

    t=ciphertxt(i);
    n=abs(t);
    b1=dec2bin(n,8);

    p=mod(l,3);

    %%%%%%%%%here i want my index variable and bit locations dynamic to store data after 4th pixel as below
    %%Carrier FileByte Operation location IndexVariable,P
    %%%(1,5) Embed (11) 6th and 8th 2
    %% (1,6) Embed (00) 6th and 7th 0
    %% (1,7) Embed (10) 7th and 8th 1
    %% (1,8) Embed (11) 6th and 8th 2
    %%%%%%%%%

    if p==0

    pv=v(1,(i-1)*4+5);
    b2=dec2bin(pv,8);
    b2(6)=b1(1);
    b2(7)=b1(2);
    nn=bin2dec(b2);
    v(1,(i-1)*4+5)=nn;

    pv=v(1,(i-1)*4+6);
    b2=dec2bin(pv,8);
    b2(6)=b1(3);
    b2(7)=b1(4);
    nn=bin2dec(b2);
    v(1,(i-1)*4+6)=nn;

    pv=v(1,(i-1)*4+7);
    b2=dec2bin(pv,8);
    b2(6)=b1(5);
    b2(7)=b1(6);
    nn=bin2dec(b2);
    v(1,(i-1)*4+7)=nn;

    pv=v(1,(i-1)*4+8);
    b2=dec2bin(pv,8);
    b2(6)=b1(7);
    b2(7)=b1(8);
    nn=bin2dec(b2);
    v(1,(i-1)*4+8)=nn;

    end

    if p==1

    pv=v(1,(i-1)*4+5);
    b2=dec2bin(pv,8);
    b2(7)=b1(1);
    b2(8)=b1(2);
    nn=bin2dec(b2);
    v(1,(i-1)*4+5)=nn;

    pv=v(1,(i-1)*4+6);
    b2=dec2bin(pv,8);
    b2(7)=b1(3);
    b2(8)=b1(4);
    nn=bin2dec(b2);
    v(1,(i-1)*4+6)=nn;

    pv=v(1,(i-1)*4+7);
    b2=dec2bin(pv,8);
    b2(7)=b1(5);
    b2(8)=b1(6);
    nn=bin2dec(b2);
    v(1,(i-1)*4+7)=nn;

    pv=v(1,(i-1)*4+8);
    b2=dec2bin(pv,8);
    b2(7)=b1(7);
    b2(8)=b1(8);
    nn=bin2dec(b2);
    v(1,(i-1)*4+8)=nn;

    end

    if p==2

    pv=v(1,(i-1)*4+5);
    b2=dec2bin(pv,8);
    b2(6)=b1(1);
    b2(8)=b1(2);
    nn=bin2dec(b2);
    v(1,(i-1)*4+5)=nn;

    pv=v(1,(i-1)*4+6);
    b2=dec2bin(pv,8);
    b2(6)=b1(3);
    b2(8)=b1(4);
    nn=bin2dec(b2);
    v(1,(i-1)*4+6)=nn;

    pv=v(1,(i-1)*4+7);
    b2=dec2bin(pv,8);
    b2(6)=b1(5);
    b2(8)=b1(6);
    nn=bin2dec(b2);
    v(1,(i-1)*4+7)=nn;

    pv=v(1,(i-1)*4+8);
    b2=dec2bin(pv,8);
    b2(6)=b1(7);
    b2(8)=b1(8);
    nn=bin2dec(b2);
    v(1,(i-1)*4+8)=nn;

    end

    end

    steg=uint8(reshape(v,r,c));
    figure;
    imshow(steg)
    title('Stego Image')

    [f p]=uiputfile('*.bmp','Save Stego Image');
    fp=[p f];

    imwrite(steg,fp);


    % --- Executes on button press in pushbutton3.
    function pushbutton3_Callback(hObject, eventdata, handles)
    % hObject handle to pushbutton3 (see GCBO)
    % eventdata reserved - to be defined in a future version of MATLAB
    % handles structure with handles and user data (see GUIDATA)

    global im1 r c;

    [f p]=uigetfile('*.bmp','Open Stego Image');
    fp=[p f];

    im1=imread(fp);
    [r c n]=size(im1);
    if n==3
    im1=rgb2gray(im1);
    end

    figure;
    imshow(im1)
    title('Input Image')
    Last edited by patneel; 03-12-2012 at 04:35 AM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    This isn't C, it should be moved to the tech forum; you're more likely to get a response there.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    And there is a "code" tag, you should use it when posting code!
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    8
    Quote Originally Posted by MK27 View Post
    This isn't C, it should be moved to the tech forum; you're more likely to get a response there.
    Thanks..but i thought that if get some help in c then I can implement same in logic using matlab syntax..

    Say ciphertext is 11001011 01111010 10101010 10011001 01010101

    This data is five bytes. So n=5 therefore p=2 ((Mod(n,3))


    Say ciphertext is 11001011 01111010 10101010 10011001 01010101

    This data is five bytes. So n=5 therefore p=2 ((Mod(n,3))


    Code:
    Carrier FileByte Operation   location            IndexVariable,P
    (1,5)             Embed (11)  6th and 8th             2
    (1,6)              Embed (00) 6th and 7th             0
    (1,7)              Embed (10)  7th and 8th            1         
    (1,8)              Embed (11)  6th and 8th            2                
    (1,9)              Embed (01)  6th and 7th            0
    (1,10)            Embed (11)  7th and 8th             1
    (1,11)            Embed (10)  6th and 8th             2
    (1,12)            Embed (10)  6th and 7th             0
    (1,13)            Embed (10)  7th and 8th             1
    (1,14)            Embed (10)  6th and 8th             2
    (1,15)            Embed (10)  6th and 7th             0
    (1,16)            Embed (10)  7th and 8th             1
    ---so on

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    Moved
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matlab help
    By cyberfish in forum Tech Board
    Replies: 1
    Last Post: 03-07-2011, 05:53 AM
  2. Matlab Help
    By anirban in forum Tech Board
    Replies: 1
    Last Post: 09-02-2010, 05:00 AM
  3. C++ to matlab
    By loga in forum C++ Programming
    Replies: 1
    Last Post: 02-10-2008, 12:33 AM
  4. MATLAB infinite loop
    By strokebow in forum Tech Board
    Replies: 0
    Last Post: 11-17-2007, 07:16 AM
  5. C/C++ and Matlab?
    By darkwalk in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2006, 03:00 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21