Kindly review my program for block matching ? How do I overcome its constraints?

2 次查看(过去 30 天)
Hello all! Below is the code for block matching of two imags al and br(which is a sub-image of al). I divided al into 4 blocks, matched with br and computed SSd. Though the result was quite accurate, I have few questions:
  • In this case, my images blocks are divided exactly, what if my block sizes are different
  • This is not the most accurate algorithm. Is there any other way to implement "block matching algorithm"?
clear all;
close all;
al = imread('testimage.jpg');
br = uint8(zeros(125, 125, 3));
br(1:126, 1:126,:) = al(80:205, 100:225 , :)
imtool(al); imtool(br);
al= rgb2gray(al);
al = im2double(al);
br= rgb2gray(br);
br = im2double(br);
c(1:126 , 1:126, :) = al(1:126 , 1:126, :)
d(1:126, 1:126,:) = al(100:225, 100:225,:)
e(1:126, 1:126,:) = al(100:225, 1:126,:)
f(1:126, 1:126,:) = al(1:126,100:225, :)
imtool(c); imtool(d); imtool(e); imtool(f)
ssdc= 0; ssde=0; ssdd=0; ssdf=0;
diffc = 0; diffd = 0; diffe=0; difff=0;
for( k = 1:1:126)
for(l = 1:1:126)
diffc = c(k,l) - br(k,l);
ssdc = ssdc+ (diffc*diffc);
diffd = d(k,l) - br(k,l);
ssdd = ssdd+ (diffd*diffd);
diffe = e(k,l) - br(k,l);
ssde = ssde+ (diffe*diffe);
difff = f(k,l) - br(k,l);
ssdf = ssdf+ (difff*difff);
end
end
y = [ssdc ssdd ssde ssdf] ;
min(y)
<<
>> The sub-block is the image d, which is a part of image a. I got the minimum cost at d. Kindly help me solve the above problem. Thank you!!

回答(1 个)

Image Analyst
Image Analyst 2014-9-25
You can use normalized cross correlation. See demo attached below the image it creates.

类别

Help CenterFile Exchange 中查找有关 Biomedical Imaging 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by