How do I call BLOCKPROC with more than one input image?

i have two images,and have a function which requires 3x3 sliding window data from both image A and image B. Is there a way to get it done with blockpro function. Any hint would be useful.

Answers (2)

See demos attached below.

4 Comments

Hi image analyst, i looked at the demos but unable to adapt it to make blockpro to accept two input images. Image A Image B
I have a function which needs sliding input of 3x3 window from both image A and image B which are of same size.
function singleValue = myFilter(blockStructImageA,blockStructImageB)
....
end
myFilterHandle = @myFilter;
blockyImage = blockproc(ImageA,[windowSize windowSize], myFilterHandle);
I dont see to pass block from Image B. The only way i could think of is to stack image A and image B and write code to get each part in the function myFilter.
Your explanation is not clear. Why not just do blockproc on A and then do it on B? That would satisfy "a function which requires 3x3 sliding window data from both image A and image B". If you want something different, then say what is to be done at each block location to A and B.
Perhaps you can use nlfilter().
its because the result of the function depends on both 3x3 blocks of both image A and image B. I finally managed to get around with combining images like cat)3, imageA, imageB). then using blockproc with combine image. In the functin i have extracted imageA and imageB part to proceed with further processing. thx.
Sounds sort of complicated. What type of image are A and B? If they're color then you have 6 color channels on the cat'ed array, if they're grayscale, then you have 2. Usually image processing works with 1 or 3 color channels, not 2 or 6, so I'd be careful that it's doing what you expect. Why would you not do it like I said where you do it on A and then do it on B and then combine the results? That seems much more straightforward and less risky.

Sign in to comment.

Have a look at the Definitions section of the blockproc doc. Consider using the 'location' and 'blockSize' fields to index into the second variable.
>> im1 = ones(10);
>> im2 = ones(10)*2;
>> type myfun.m
function o = myfun(bs, im2)
im1Block = bs.data;
startInd = bs.location;
endInd = bs.location+bs.blockSize-1;
im2Block = im2(startInd(1):endInd(1), startInd(2):endInd(2));
o = im1Block+im2Block;
end
% This is the tricky part. Here, all of im2 gets 'snapshot'ed inthe function handle, so its available inside myfun when called via funcHandle inside blockproc (!).
>> funcHandle = @(bs)myfun(bs,im2);
>> blockproc(im1,[5 5],funcHandle)
ans =
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
>>

1 Comment

hi , i never knew ther is location properties. cheers. But i just combine mz images and extract part of imageA and imageB in my function handle for blockproc. thx.

Sign in to comment.

Asked:

on 8 Oct 2013

Commented:

on 15 Oct 2013

Community Treasure Hunt

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

Start Hunting!