how to use user defined function which only change some value of block not all in blockproc() in matlab?
Show older comments
i have one B1 image matrix of size 512*512 and want to apply my dhide_fun on each block which change some values of each 8*8 block no all. my code is:
f1=@(block_struct)dhide_fun(block_struct.data);
B2 = blockproc(B1,[8 8],f1);
function dhide_fun(blk)
msg='important data';
nmsg=double(msg);
bmsg(1:112)=dec2bin(nmsg,8);
num = bmsg - '0'; % convert string to binary array.
persistent u ; % static variable.
for i=1:8
for j=1:8
if((i+j)>=8&&(i+j)<=10)
if(u<112)
u=u+1;
else
return;
end
s=num(1,u);
% x=block.data(i,j);
x=blk(i,j);
if(mod(j,2)==0)
if(x<=0&&s==1)
x=x-1;
elseif(x>0&&s==1)
x=x+1;
elseif(x<=0&&s==0)
x=1;
elseif(x>0&&s==0)
x=0;
end
else
if(x<=0&&s==1)
x=x+1;
elseif(x>0&&s==1)
x=x-1;
elseif(x<=0&&s==0)
x=0;
elseif(x>0&&s==0)
x=1;
end
end
blk(i,j)=x;
if(u<112)
u=u+1;
else
break;
end
end
end
if(u<112)
u=u+1;
else
break;
end
end
no error occur but my B2 matrix is empty after running these commands. anybody can plz tell what's wrong with this code?
Accepted Answer
More Answers (0)
Categories
Find more on Blocked Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!