How to jump to next sub-block in image

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

Are you asking how to break an image up into sub-blocks ?
no sir Walter. My problem now is I can embed the data that had embedded and retrieve it in one sub-block only. But it cant continuously proceed to the next sub-block to continue embed and retrieve the data.
Matt J
Matt J on 26 Jan 2013
Edited: Matt J on 26 Jan 2013
What block structure are you working with? Does your image consist of non-overlapping tiles or is it the position of a sliding window that determines a block?
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.
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

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

Sir Image Analyst, it cant go to the next block. Example now I'm within area of (1,1) to (3,3). How do I update the coordinate to (4,1) to (6,3)? It is 2*2 block size.
I just showed you. There are two for loops. See where it says row = 1 : windowSize : rows-windowSize? Well that means that the first time it executes the code in the for loop row will have a value of 1, and same for col. Let's say that windowSize = 2 by 2. so that means thisBlock will get the chunk of the window from 1,1 to 2,2: thisBlock = yourImage(1:2, 1:2); You can't get all of 1,1 to 3,3 with a window size of 2 - you'd need a window size of 3 rather than 2. Now if you want to have the next row be 4, you'd have to jump by the window size plus 1. 1+4 = 4, so you need to jump by 3 which is 2+1 which is the window size plus 1. And you'd be skipping row 3 entirely. William William, have you really though about the coordinates? And you want a different "jump" size that is different than the window size?
I tried already but it do not work. As you see the coding as I provided above, after the for loop for r, there is an algorithm for go to next block, but it seems not works on my situation.
Which r loop? You have two loops over r.
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

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.

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

i do not understand, matt
Here's a small example to convey the general idea. I start with a 4x4 image A, which I will think of as composed of 2x2 blocks (four of them)
>> A=reshape((1:16).',4,4)
A =
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
Now, I use mat2tiles to assign the 2x2 blocks to cells.
>> C=mat2tiles(A,[2,2])
C =
[2x2 double] [2x2 double]
[2x2 double] [2x2 double]
Now I will do something simple like loop through and display all 4 blocks. The point is that I can index each block individually as C{i}
>> for ii=1:4, C{ii}, end
ans =
1 5
2 6
ans =
3 7
4 8
ans =
9 13
10 14
ans =
11 15
12 16
so my embed and extract can be done through this method?
Yes. I showed you a few comments ago how your 'embed' code would change.
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!