我想在blockproc
函数中使用我自己的(自定义)函数。但我无法弄清楚如何真正融入这一点。我是MATLAB的新手。
在这个函数中,我试图将信息(LR_seq
的位)嵌入到块中。我在块中一次选择一对像素并尝试将我的信息嵌入其中。
这是我的功能代码:
function dataencode(block_struct,LR_seq)
LR_seq = vec2mat(LR_seq,2,4);%changing it into a 2,4 mat to make it fit into the for loop
LR_mat = zeros(4,4);%adding zero columns in between to convert it into 4,4 mat to fit into the for loop
LR_mat(:,1:2:end) = LR_seq;
for r = 1 : 4
for c = [1 3]
x = uint16(block_struct.data(r,c)) ;
y = uint16(block_struct.data(r,c+1));
x1 = de2bi(x,12); y1 = de2bi(y,12);
if(~(2*x - y == 1) | ~(2*y - x == 1) | ~(2*x - y == 255) | ~(2*y - x == 255))
if((x1(1) == 0) & (y1(1) == 0)) %because in maltab lsb comes first
xt = (2*x - y) ; yt = (2*y - x);
xt_bin = de2bi(xt,12); xt_bin(1) = 1; xtd = bi2de(xt_bin);block_struct.data(r,c) =xtd;
yt_bin = de2bi(yt,12) ; yt_bin(1) = LR_mat(r,c); ytd = bi2de(yt_bin); block_struct.data(r,c+1) = ytd;
elseif((x1(1) == 1) | (y1(1) == 1))
x1(1) = 0 ; xtd = bi2de(x1) ; block.data(r,c) = xtd;
y1(1) = LR_mat(r,c); ytd = bi2de(y1) ; block_struct.data(r,c+1) = ytd;
end
else
x1(1) = 0; xtd = bi2de(x1) ; block.data(r,c) = xtd;
ytd = bi2de(y1); block_struct.data(r,c+1) = ytd;
end
end
end
end
M
是一个RGB 256x256图像,我希望在其中嵌入比特序列LR_seq
。
我试图在命令窗口中调用此函数,但它给了我一个空矩阵,请帮忙。这是我调用函数的代码
for ii = 1 : 8 : size(LR_seq)
myfunc = @(block_struct) dataencode(block_struct,LR_seq(ii : ii+7));
U_im_new = blockproc(M,[4 4],myfunc)
end
答案 0 :(得分:0)
dataencode
应该在参数中使用block_struct
。但是您的函数myfunc_red
使用block_struct
的数据调用encode函数。
您可能更喜欢这样做:
myfunc = @(block_struct) dataencode(block_struct,LR_seq(1 : 8));
U_im_r = blockproc(M(:,:,1),[4 4],myfunc);