How can I implement block search in this program?

조회 수: 3 (최근 30일)
Emmanuel
Emmanuel 2014년 9월 25일
편집: Stephen23 2014년 9월 25일
Hello all! I wanted to compare image al , with another image b, which is a block of image form the previous image al. I tried splitting image al block by block and storing them in 4 different matrices(and implement SSD), which I've programmed below. But when I run them, it looks like its into an infinite loop. Is there any other method to process blocks and match them? Please help.
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);
for(i =1:1:126)
for (j = 1:1:126)
c(i,j) = al(i,j)
end
end
for(i =99:1:225)
for (j = 99:1:225)
d(i,j) = al(i,j)
end
end
for(i =99:1:225)
for (j = 1:1:126)
e(i,j) = al(i,j)
end
end
for(i =1:1:126)
for (j = 99:1:225)
f(i,j) = al(i,j)
end
end
imtool(c); imtool(d); imtool(e); imtool(f)
  댓글 수: 1
Stephen23
Stephen23 2014년 9월 25일
You mention that you wish to "match" the blocks from the image. What exactly do you mean by this? Is pixel-wise RGB value equivalence a "match"?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2014년 9월 25일
편집: Stephen23 2014년 9월 25일
MATLAB's feature called vectorization would be a great help, it allows you to perform operations on whole arrays, without requiring any loops. It is faster, neater, and less prone to bugs.
This means that
for(i =1:1:126)
for (j = 1:1:126)
c(i,j) = al(i,j)
end
end
can simply be
c(1:126,1:126) = al(1:126,1:126);
or, if this is the first time that c is defined:
c = al(1:126,1:126);
This also applies to the two lines
br = uint8(zeros(125, 125, 3));
br(1:126, 1:126,:) = al(80:205, 100:225 , :)
where the first line really is not required:
br = al(80:205,100:225,:);
This introduction to indexing might be useful to read too:
However you are working with image data, which often consists of 3D arrays. You will also need to consider what happens to that third array dimension.
Note that it is best to avoid i and j as a variable names, as these represent imaginary/complex values.
  댓글 수: 1
Emmanuel
Emmanuel 2014년 9월 25일
Thanks!! Now my code snippet looks like this:
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)
I got four image blocks :). Is there any other efficient algorithm that will help me in block matching. Also, from where can I learn about the algorithms? Any online tutorials or sources which you might help me. I'm a beginner in image processing and matlab and would like to learn more about them

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by