# while executing my code there is no error but i did not get any output

1 view (last 30 days)
deep k on 10 Feb 2020
Commented: deep k on 22 Feb 2020
while performing cross correlation i get white screen as my output.can anyone please tell me whats my mistake in my code,because i m a new matlab user.I am attaching my code for your kind reference..your help is really appreciated
clc;
clear all;
close all;
a=imresize(a,[255 255]);
figure();
subplot(2,2,1);
imshow(a);
b=rgb2gray(a);
% r =a(:,:,1);
% g =a(:,:,2);
% b =a(:,:,3);
% d=0.33*(a(:,:,1)+a(:,:,2)+a(:,:,3));
subplot(2,2,2);
imshow(b);
% gaussian kernel
N = 5; %// Define size of Gaussian mask
sigma =2; %// Define sigma here
ind = -floor(N/2) : floor(N/2);
[X Y] = meshgrid(ind, ind);
h = exp(-(X.^2 + Y.^2) / (2*sigma*sigma));
h = h / sum(h(:));
%// Convert filter into a column vector
h = h(:);
%// Filter our image
C = im2col(I_pad, [N N], 'sliding');
C_filter = sum(bsxfun(@times, C, h), 1);
out = col2im(C_filter, [N N], size(I_pad), 'sliding');
subplot(2,2,3);
imshow(out);
out=out(:);
b=b(:);
l_p=xcorr(b,out);
subplot(2,2,4);
imshow(l_p);

Subhadeep Koley on 10 Feb 2020
You are not getting any output because you are trying to display the vector l_p as an image. It seems you are trying to 2-D calculate the cross-correlation between b & out. Therefore, using xcorr2 instead of xcorr might help. Refer the code below.
clc; close all;
a = imresize(a, [255, 255]);
figure; subplot(2, 2, 1); imshow(a, []);
b = rgb2gray(a);
subplot(2, 2, 2); imshow(b, []);
% gaussian kernel
N = 5; %// Define size of Gaussian mask
sigma =2; %// Define sigma here
ind = -floor(N/2) : floor(N/2);
[X, Y] = meshgrid(ind, ind);
h = exp(-(X.^2 + Y.^2) / (2*sigma*sigma));
h = h / sum(h(:));
% Convert filter into a column vector
h = h(:);
% Filter our image
C = im2col(I_pad, [N, N], 'sliding');
C_filter = sum(bsxfun(@times, C, h), 1);
out = col2im(C_filter, [N, N], size(I_pad), 'sliding');
subplot(2, 2, 3); imshow(out, []);
l_p = xcorr2(b, out);
subplot(2, 2, 4); imshow(l_p, []);

#### 1 Comment

deep k on 22 Feb 2020
thank you so much for ur help.