how can I read perform some operation on an image byte by byte???

plz guide me. I m performing Image steganography in MATLAB. Need help Need to read images byte by byte and perform some operation byte wise

 채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 5일
ImageData = imread('ImageFileName.JPG');
ImageAsBytes = typecast(ImageData(:), 'uint8');
fid = fopen('tempimg.dat', 'w');
fwrite(fid, ImageAsBytes');
fclose(fid);
fid = fopen('tempimg.dat', 'r');
for K = 1 : numel(ImageAsBytes)
thisbyte = fread(fid, '*uint8', 1);
.... perform the byte-wise operation here
end
fclose(fid);
Note that this code has been constructed to suit your requirement to "read images byte by byte", which is seldom necessary (or desirable) for steganography purposes.

댓글 수: 5

Sana Shaikh
Sana Shaikh 2013년 4월 6일
편집: Sana Shaikh 2013년 4월 6일
Thankyou Sir!
Kindly help me in performing:
Step-1: Read one by one byte from the secret message file and convert each byte to 8-bits. Then we apply 1 bit right shift operation on the entire file so that each byte will be modified accordingly.
• Step-2: We read 8 bits at a time and divide into two blocks 4 bits each and then perform the XOR operations with 4-bits on the left side with 4 bits on the right side and substitute the new bits in right 4-bit positions. The same thing repeated for all bytes in the file.
• Step-3: Repeat step-1 by performing 2 bits right shift for all bytes in the secret message file.
secretfid = fopen('secretmessage.txt','r');
while true
[thissecretbyte, secretcount] = fread(secretfid, '*uint8', 1);
if secretcount == 0; break;
.... use the byte
end
fclose(secretfid);
It is not possible to right shift entire files by a bit; the most you can do is shift each byte after you read it. You need to figure out what you want to do with the bits that would be right-shifted "off the end".
See also bitset() and bitget() and xor()
Thankyou for guiding.
Will u answer a few questions please?
1. What does "" while true "" means over here???? means what is this condition indicating??
2. If secretcount == 0; break; does this statement means that for storing the secret msg bits you r skipping the first byte???
3. Can you please tell me that if I store data in a temporary file using tempname ; so How can I display those contents of the temp file??
""
clc; ImageData = imread('hide.bmp');
ImageAsBytes = typecast(ImageData(:), 'uint8') // for byte by byte as you guided :)
fid = fopen(tempname , 'w+');
fwrite(fid, ImageAsBytes);
for K = 1 : numel(ImageAsBytes)
thisbyte = fread(fid,inf, 'uint8');
end
fclose(fid);
In the code given above the statement " thisbyte = fread(fid,inf, 'uint8'); " is displaying a long list of these:
thisbyte =
[]
thisbyte =
[]
thisbyte =
[]
thisbyte =
[]
...............
so what does that mean ? Nothing stored in that temp file???
Look at ImageAsBytes in the variable editor and see what it is. If you don't know what I just said, then look at this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by