Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to jump to next sub-block in image

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.

5 Comments

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?

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 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);
Willam Willam

Products

No products are associated with this question.

3 Answers

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?

6 Comments

Image Analyst on 27 Jan 2013

Which r loop? You have two loops over r.

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?

Image Analyst
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

1 Comment

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

Matt J
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);

5 Comments

Willam Willam on 1 Feb 2013

so my embed and extract can be done through this method?

Matt J on 1 Feb 2013

Yes. I showed you a few comments ago how your 'embed' code would change.

Willam Willam on 1 Feb 2013

ok. Let me implement your method and my own method. Hahaha.

Matt J

Contact us