필터 지우기
필터 지우기

Loop Problem

조회 수: 1 (최근 30일)
Nil
Nil 2012년 3월 15일
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
  댓글 수: 1
Nil
Nil 2012년 3월 15일
Can anyone pls point wrong logic in my logic

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

채택된 답변

Kevin Holst
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
  댓글 수: 1
Nil
Nil 2012년 3월 16일
Thanks Kevin for your help.you are right..i too reliazed the same and just kept one loop but two variable i & j but initialized i before loop..your suggestion is more correct.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by