block matching image issue

When I did blockmatching algorithm on the tennis man image, and did a comparaison between the original and reconstructed image I got this black boxes, why?

5 commentaires

Image Analyst
Image Analyst le 8 Avr 2023
There is no way to tell with the minimal information you have shared. If you have any more questions, then attach your image(s) and code to read it in with the paperclip icon after you read this:
Blob
Blob le 8 Avr 2023
Modifié(e) : Walter Roberson le 8 Avr 2023
clc
clear all
close all
load('f1.mat');
load('f2.mat');
figure;
subplot 121
imagesc(F1);
title('image 1');
subplot 122
imagesc(F2);
title('image 2');
colormap gray
load('e1.mat');
load('e2.mat');
figure;
subplot 121
imagesc(e1);
title('image 1');
subplot 122
imagesc(e2);
title('image 2');
colormap gray
[M N]=size(F1);
T=16;
nbr_l=M/T;
nbr_c=N/T;
indbloc_x=1:nbr_l;
indbloc_y=1:nbr_c;
L=length(indbloc_x);
Q=length(indbloc_y);
F2_recons = zeros(size(F2));
for i=1:L
for j=1:Q
X=indbloc_x(i);
Y=indbloc_y(j);
if i==L
1+1
end
%for n=1:T
% bloc2=F2(X:X+T-1,Y:Y+T-1);
bloc2=F2((1:16)+(i-1)*16,(1:16)+(j-1)*16);
eqm=inf(15, 15);
mineqm = inf;
for i1=-7:7
for i2=-7:7
condition = (X+i1) >=1 & (Y+i2) >=1;
condition2 = ((16+(i-1)*16+i1)<=M) & ((16+(j-1)*16+i2)<=N);
if ~(condition&&condition2)
continue
else
bloc1=F1((1:16)+(i-1)*16+i1,(1:16)+(j-1)*16+i2);
eqm(i1+8, i2+8)=(1/(nbr_l*nbr_l))*(sum(sum(bloc2-bloc1).^2));
if eqm(i1+8, i2+8)< mineqm
%stocke bloc1 et les indices qui correspondent
mineqm = eqm(i1+8, i2+8);
indx=i1;
indy=i2;
bloc1min = bloc1;
end
end
end
end
F2_recons((1:16)+(i-1)*16,(1:16)+(j-1)*16) = bloc1min;
end
end
figure
imshow(uint8(F2_recons))
Walter Roberson
Walter Roberson le 8 Avr 2023
We would need your .mat files for testing.
Blob
Blob le 8 Avr 2023
(Just showing the output, not trying to debug the problem)
Untitled5

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 8 Avr 2023

0 votes

Your attached code (but not your posted code) has
imshow (F2_recons - e1)
where both of those arrays are double precision and happen to contain integer values. The difference between the two arrays ranges between -255 and +206 . You are passing that array of values -255 to +206 to imshow() as a double precision array. By default, when passed a double precision array, imshow() assumes that the valuable part of the data is the range 0 to 1, and that anything below 0 should be treated as 0 and anything above 1 should be treated as 1. So you more or less end up binarizing the difference array.
You should be considering using
imagesc(F2_recons - e1);
colormap(gray)

2 commentaires

Blob
Blob le 10 Avr 2023
@Walter Roberson thank you, I have one more request, could you please show me how to plot the vectors of motion?
Walter Roberson
Walter Roberson le 10 Avr 2023
Sorry, no, I do not see anything in your code that corresponds to vectors of motion, or anything that corresponds to motion at all. I cannot tell what you are calculating at all.

Connectez-vous pour commenter.

Question posée :

le 8 Avr 2023

Commenté :

le 10 Avr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by