block processing with multiple input matrices
Asked Answered
T

3

5

I'm working in matlab processing images for steganography. In my work so far I have been working with block processing command blockproc to break the image up into blocks to work on it. I'm now looking to start working with two image, the secret and the cover, but i can't find anyway to use blockproc with two input matrices instead of one.

Would anyone knowof a way to do this?

Tackle answered 2/3, 2011 at 10:47 Comment(0)
T
6

blockproc allows you to iterate over a single image only, but doesn't stop you from operating on whatever data you would like. The signature of the user function takes as input a "block struct", which contains not only the data field (which is used in all the blockproc examples) but also several other fields, one of which is "location". You can use this to determine "where you are" in your input image and to determine what other data you need to operate on that block.

for example, here's how you could do element-wise multiplication on 2 same-size images. This is a pretty clunky example but just here to demonstrate how this could look:

im1 = rand(100);
im2 = rand(100);
fun = @(bs) bs.data .* ...        
    im2(bs.location(1):bs.location(1)+9,bs.location(2):bs.location(2)+9);
im3 = blockproc(im1,[10 10],fun);
im4 = im1 .* im2;
isequal(im3,im4)

Using the "location" field of the block struct you can figure out the appropriate parts of a 2nd, 3rd, 4th, etc. data set you need for that particular block.

hope this helps!

-brendan

Tetrode answered 2/3, 2011 at 14:24 Comment(1)
Kudos for starting your Stack Overflow account with a competent, elaborate answer :)Burgess
C
3

I was struggling with the same thing recently and solved it by combining both my input matrices into a single 3D matrix as follows. The commented out lines were my original code, prior to introducing block processing to it. The other problem I had was using variables other than the image matrix in the function: I had to do that part of the calculation first. If someone can simplify it please let me know!

%%LAB1 - L*a*b nearest neighbour classification
%distance_FG = ((A-FG_A).^2 + (B-FG_B).^2).^0.5;
%distance_BG = ((A-BG_A).^2 + (B-BG_B).^2).^0.5;

distAB = @(bs) ((bs.data(:,:,1)).^2 + (bs.data(:,:,2)).^2).^0.5;
AB = A - FG_A; AB(:,:,2) = B - FG_B;
distance_FG = blockproc(AB, [1000, 1000], distAB);
clear AB
AB = A - BG_A; AB(:,:,2) = B - BG_B;
distance_BG = blockproc(AB, [1000, 1000], distAB);
clear AB
Conchitaconchobar answered 8/11, 2012 at 0:31 Comment(0)
B
2

I assume the solution to your problem lies in creating a new matrix that contains both input matrices.

e.g. A(:,:,1) = I1; A(:,:,2) = I2;

Now you can use blockproc on A.

Burgess answered 2/3, 2011 at 11:14 Comment(1)
so you suggest creating a 3d matrix and the blockproc command working on this? Thats a good idea, I'll try it and see if it worksTackle

© 2022 - 2024 — McMap. All rights reserved.