How can we choose a block of pixels?

Hi! I want to run a block matching search on two images. How can I choose the block of pixels?

 Accepted Answer

Can you elaborate? Until then I can offer demos of blockproc (attached), normalized cross correlation, and non-linear filtering, and the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F

5 Comments

Result from using normalized cross correlation to find a template sub-image:
Hi! Thank you for your reply! I am having two images f and g, where g contains a block of image from f. I want to select this block from g and run a search and find its match on f. How do I go about it? Also, can you please tell me as to how to implement Sum of Squared Difference? Is it a pixel by pixel search?
That's a different method. I think it might take longer than normxcorr2. You can use blockproc_demo2 and for each block in the function compute the SSD
% Extract our block out of the structure.
array2D = blockStruct.data;
diffsSquared = (double(array2D) - double(yourTemplateImage))) .^ 2;
% Do the filtering. Multiply by kernel and sum.
singleValue = sum(diffsSquared(:));
Be sure to pass in your template image, yourTemplateImage.
Then when you get the SSD image, you want to use
[rowOfMax, colOfMax] = find(yourImage == min(yourImage));
to get the location of where the SSD is minimum, which corresponds to the template location. This should be enough for you to complete the assignment, so Mark the answer as Accepted if I've given you enough.
Actually you probably want to do this in nlfilter since blockproc moves in "jumps" whereas nlfilter moves a pixel at a time, but the basica algorithm is the same.
Hi; I have a same assignment on SSD matching template. I could not follow/understand your earlier answer and code. Can you please create a single Matlab code by considering an example image to carry out SSD matching.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!