how to use user defined function which only change some value of block not all in blockproc() in matlab?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
sonam chhikara
il 23 Set 2015
Commentato: sonam chhikara
il 24 Set 2015
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?
0 Commenti
Risposta accettata
Walter Roberson
il 23 Set 2015
The function you invoked with blockproc() must return a block of data (though the block can be empty.) Your function is not returning anything.
If you want to modify some values but not others, set an output variable as a copy of the input variable and then modify whatever locations you want in the output variable (you do this so that you can still examine all the values in the input variable as they were before any changes were made.) The places you do not modify would contain the input values.
Remember, blockproc() does not directly modify an image: it is used to return a whole series of blocks that are pieced together to form a new image, which you might possibly assign over top of the old image if you want.
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!