How to jump to next sub-block in image

1 view (last 30 days)
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 Comments
Willam Willam
Willam Willam on 26 Jan 2013
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 on 26 Jan 2013
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);

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 26 Jan 2013
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 Comments
Willam Willam
Willam Willam on 23 Feb 2013
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?

Sign in to comment.

More Answers (2)

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

Sign in to comment.


Matt J
Matt J on 27 Jan 2013
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 Comments
Matt J
Matt J on 1 Feb 2013
Yes. I showed you a few comments ago how your 'embed' code would change.
Willam Willam
Willam Willam on 1 Feb 2013
ok. Let me implement your method and my own method. Hahaha.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!