Loop Problem
1 次查看(过去 30 天)
显示 更早的评论
Hi,
Overview on Question
I am working on image steganography code and s, n, p are calculated values which I am getting as per requirement but struggling to get “Bits_to_Modify ” column result shown in below table
Output of Existing program
==========================================================
My text=’ab’
TextLength=2
Binary representation:
s= 0110000101100010
n=8 (Textlength*4)
p=
2
0
1
2
0
1
2
0
=============================================================
First converting text to bytes, then calculating index variable (called as p) & formula is MOD(No of Bytes,3).
I have text length as 2 bytes so Index Variable (P) is 2..
I will always have index variable values as 0 or 1 or 2 which will be based on no. of Bytes I have assigned
for first two bits (01) , index variable assigned as 2
for next two bits (10), index variable assigned as 0
for next two bits (00), index variable assigned as 1
for next two bits (01), index variable assigned as 2..
so on till end of my bits.
I want to modify bits of pixels (4th pixel onwards) as per my value of index variable.
In 5th Pixel need to embed the data bits 01 in 6th and 8th bit locations, and next value of p becomes 0. Need to embed the next data bits 10 into 6th Pixel in 6th and 7th bit locations, next value of p becomes 1. Now need to embed the next two bits 00 into 7th Pixel in 7th and 8th bit locations and so on.
Pixcel IndexVariable Bits_to_Modify
5 2 b6=0 b8=1
6 0 b6=1 b7=0
7 1 b7=0 b8=0
8 2 b6=0 b8=1
9 0 b6=0 b7=1
10 1 b7=1 b8=0
11 2 b6=0 b8=0
12 0 b6=1 b7=0
Question
I have written the following program taking above values of S,n & P which i am getting
but it dont give following output..Please provide me direction
for j=0:2:2*n-2
for i=1:1:n
if p(i)==2
p1= p(i)
pv=(i+4)
b6=s(j+1)
b8=s(j+2)
end
if p(i)==0
p1= p(i)
pv=(i+4)
b6=s(j+1)
b7=s(j+2)
end
if p(i)==1
p1= p(i)
pv=(i+4)
b7=s(j+1)
b8=s(j+2)
end
end
end
Expected Output
p1=2
pv=5
b6=0
b8=1
p1=0
pv=6
b6=1
b7=0
p1=1
pv=7
b7=0
b8=0
p1=2
pv=8
b6=0
b8=1
p1=0
pv=9
b6=0
b7=1
p1=1
pv=10
b7=1
b8=0
p1=2
pv=11
b6=0
b8=0
p1=0
pv=12
b6=1
b7=0
采纳的回答
Kevin Holst
2012-3-15
You have two loops when you just need one. Essentially you're looping through the entire binary variable for each p value, but each p value corresponds to 2 bits in your binary variable (my understanding). Try this, it gets the right answer:
for i=1:1:n
if p(i)==2
p1= p(i)
pv=(i+4)
b6=s(2*i-1)
b8=s(2*i)
end
if p(i)==0
p1= p(i)
pv=(i+4)
b6=s(2*i-1)
b7=s(2*i)
end
if p(i)==1
p1= p(i)
pv=(i+4)
b7=s(2*i-1)
b8=s(2*i)
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!