0

I am attempting to extract data from a DWT subband. I am able to embed data correctly (I have followed it in the debugger),cal PSNR etc. PSNR rate seem very high 76.2?? however,I am having lot of trouble extracting data back!It is sometimes extracting the number 128?? Can anyone help or have any idea why this is? I would be very thankful.I have been working on this all day & having no luck!I am very curious to know??

Data Embedding:

coverImage = imread('lena.bmp');
message = importdata('minutiaTest.txt');
%message = 'Bifurcations:'; 

[LL,LH,HL,HH] = dwt2(coverImage,'haar');
if size(message) > size(coverImage,1) * size(coverImage,2)
   error ('message too big to embed');
end

bit_count = 0;
steg_coeffs = [4, 4.75, 5.5, 6.25, 7];

for jj=1:size(message,2)+1
    if jj > size(message,2)
        charbits = [0,0,0,0,0,0,0,0];
    else
        charbits = dec2bin(message(jj),8)';
        charbits = charbits(:)'-'0';
    end

    for ii=1:8
        bit_count = bit_count + 1;

        if charbits(ii) == 1
            if HH(bit_count) <= 0
                HH(bit_count) = steg_coeffs(randi(numel(steg_coeffs)));
            end
        else
            if HH(bit_count) >= 0
                HH(bit_count) = -1 * steg_coeffs(randi(numel(steg_coeffs)));
            end
        end
    end
end

stego_image = idwt2(LL,LH,HL,HH,'haar');
imwrite(uint8(stego_image),'newStego.bmp');

Data Extraction:

new_Stego = imread('newStego.bmp');
[LL,LH,HL,HH] = dwt2(new_Stego,'haar');
message = '';
msgbits = '';
for ii = 1:size(HH,1)*size(HH,2)
    if HH(ii) > 0
        msgbits = strcat (msgbits, '1');
    elseif HH(ii) < 0
        msgbits = strcat (msgbits, '0');
    else
        return;
    end

    if mod(ii,8) == 0
        msgChar = bin2dec(msgbits);
        if msgChar == 0
            break;
        end
        msgChar = char (msgChar);
        message = [message msgChar]; 
        msgbits = '';
    end
end
  • I have edited code above. Sorry I should have included all my code. Still no luck!Still seem to be getting the number 128 on extraction.Any ideas??When running in the degugger It's definately retrieving data,but then I just get 128! – Hitmanpaddy Jan 06 '15 at 12:18
  • Hi,the minutiaTest.txt contains x and y coordinates of fingerprint minutia. i.e 247 25. I can mail it to you If you want. Or is there anyway I can attach it here? I am getting 128 everytime. Are you telling me that the code is working for you?Do you get exact data back? – Hitmanpaddy Jan 06 '15 at 12:28
  • Tried to upload it on pastebin and got the following error:"Sorry, but the file you sent has more than 10% binary characters in it. We're guessing that means it is a binary file, and not a text file. It will be ignored."I have used filebin instead here is the link:http://filebin.ca/1nD7xOGR0QVF/minutiaTest.txt – Hitmanpaddy Jan 06 '15 at 12:41

1 Answers1

0

The problem arises from reading your data with importdata.

This command will load the data to an array. Since you have 39 lines and 2 columns (skipping any empty lines), its size will be 39 2. However, the program assumes that your message will be a string. For example, 'i am a string' has a size 1 13. This expectation of the program compared to the data you actually give it creates all sorts of problems.

What you want is to read your data as a single string, where the number 230 is not one element, but 3 individual characters. Tabs and newlines will also be read in as well.

To read your file:

message = fileread('minutiaTest.txt');

After you extract your message, to save it to a file:

fid = fopen('myFilename.txt','w');
fprintf(fid,message);
fclose(fid);
Reti43
  • 9,656
  • 3
  • 28
  • 44
  • Ok, thank you! I will try this and give an update. One last question,So I replace the line message = importdata('minutiaTest.txt'); with message = fileread('minutiaTest.txt'); Then after the data extration process I include the other two lines. I'm guessing these two lines will create a txt file called myFilename.txt and save extracted data into it, and print extracted data (which I have called message) to screen?? – Hitmanpaddy Jan 06 '15 at 13:19
  • Yes, you replace the command `importdata` with `fileread` to change the way you read in your data. The other two lines save the extracted data to a file. `fid` creates a reference to the file you create and `fprintf` writes the data to that file. Do this only if you want to save the data to a text file. If you just want to print it to the screen, typing `message` in the console/script (note the lack of semi-colon) will do just fine. – Reti43 Jan 06 '15 at 13:25
  • Hi,I have tried your suggestions and now I only get the following data after extraction http://filebin.ca/1nEfHMUbtNvH/myExtractedMin.txt It does not seem to be retrieving all data that was embedded. Any ideas on this? – Hitmanpaddy Jan 06 '15 at 17:59
  • It works fine for me. I am using your code exactly as provided, except from changing `importdata` to `fileread` and using the `minutiaTest.txt` you provided above. How do you run your code? Do you have two separate scripts? Two functions? All in one file? – Reti43 Jan 06 '15 at 18:12
  • I have all code in one script. I also inserted clear; at the top of my script. I have some other code to calc PSNR,MSE etc but I have this commented out,it shouldn't effect it? – Hitmanpaddy Jan 06 '15 at 22:48
  • I would suggest you create a clean script and copy your code from here. Add a `clear;` at the beginning of both the embedding and extraction stages. Remove any `newStego.bmp` images you have and then try running it again. – Reti43 Jan 06 '15 at 22:51