MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Willam Willam on 18 Jan 2013

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.

*No products are associated with this question.*

Answer by Image Analyst on 26 Jan 2013

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?

Show 3 older comments

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?

Answer by Matt J on 26 Jan 2013

Edited by 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

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

Answer by 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);

Show 2 older comments

## 5 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59156#comment_125188

Are you asking how to break an image up into sub-blocks ?

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59156#comment_125191

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.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59156#comment_125192

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?

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59156#comment_125193

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.

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59156#comment_125195

this is embedding and retrieving algorithms