How to jump to next sub-block in image

2 次查看(过去 30 天)
Hi all. I want ask how to embed and retrieve data from block to block? Because I can get the data at the entire block only. Thanks for your help.
  5 个评论
Willam Willam
Willam Willam 2013-1-26
Matt, because i'm done on image watermarking apply spatial domain method. As you know, the 2*2 block size are used to embed the one ASCII binary data(for my research purpose). So my problem now cant proceed to the next block while after my first data had been embed and retrieved.
Willam Willam
Willam Willam 2013-1-26
this is embedding and retrieving algorithms
display('EMBED');
for b=1:1:size_char
n=1;
for r=1:2
for c=1:2
block(r,c)=bitset(block(r,c),1,embed(n));
n=n+1;
block(r,c)=bitset(block(r,c),2,embed(n));
n=n+1;
end
end
if (x2+blocksize) > (N_RONI+startx-1)
if y2+blocksize < (M_RONI+starty)
x2=startx;
y2=y2+blocksize;
end
else
x2=x2+blocksize;
end
watermarked_image(y2:y2+blocksize-1,x2:x2+blocksize-1)=block;
end
watermarked_image_int=uint8(watermarked_image);
imwrite(watermarked_image_int,'watermarked.bmp');
display('Done of Embeddding');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Extract Algorithms %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
block=watermarked_image(y2:y2+blocksize-1,x2:x2+blocksize-1);
retrieveblock = [];
for a=1:1:size_char
display('EXTRACT');
for r=1:2
for c=1:2
retrievebits=bitget(block(r,c),1);
retrieveblock=[retrieveblock retrievebits];
%display(retrieveblock);
retrievebits=bitget(block(r,c),2);
retrieveblock=[retrieveblock retrievebits];
%display(retrieveblock);
end
end
if (x2+blocksize) > (N_RONI+startx)
if y2+blocksize < (M_RONI+starty)
x2=startx;
y2=y2+blocksize;
end
else
x2=x2+blocksize;
end
end
display(retrieveblock);

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-1-26
I'm not sure I understand why you can't just have two for loops where you move the window along:
for row = 1 : windowSize : rows-windowSize
for col = 1 : windowSize : columns-windowSize
% Get rectangular block.
thisBlock = yourImage(row:row+windowSize-1, column:column+windowSize-1);
% Now process this block somehow...
end
end
It's the brute force, intuitive, totally obvious approach that I'm sure you've considered already, but what's wrong with it?
  6 个评论
Willam Willam
Willam Willam 2013-2-23
excuse me. My variable n got problem. leave it outside for loop it will get the latest data while put into the for loop will get the first data. How can i embed it therefore it can follow the sequence of embedding from first to the last?

请先登录,再进行评论。

更多回答(2 个)

Matt J
Matt J 2013-1-26
编辑:Matt J 2013-1-26
extract= yourimage(i+(0:M-1),j+(0:N-1))
or
yourimage(i+(0:M-1),j+(0:N-1)) = embed
  1 个评论
Willam Willam
Willam Willam 2013-1-26
Matt, thanks. But can you help me check provided code to check why it cant continue go to the next block? Appreciate your help

请先登录,再进行评论。


Matt J
Matt J 2013-1-27
I only vaguely understand what you're doing, but nowhere in your code do you show where "block" originally comes from or how you update it. Maybe the problem is that you are not updating it.
Below might be something like what you're looking for for the 'embed' part. The 'extract' would probably be very similar. I'm using MAT2TILES which is available here
C=mat2tiles(YourImage,[2,2]);
W=C;
for i=1:numel(C);
block=C{i};
n=1;
for r=1:2
for c=1:2
block(r,c)=bitset(block(r,c),1,embed(n));
n=n+1;
block(r,c)=bitset(block(r,c),2,embed(n));
n=n+1;
end
end
W{i}=block;
end
watermarked_image=cell2mat(W);
  5 个评论
Matt J
Matt J 2013-2-1
Yes. I showed you a few comments ago how your 'embed' code would change.
Willam Willam
Willam Willam 2013-2-1
ok. Let me implement your method and my own method. Hahaha.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by