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

1 vue (au cours des 30 derniers jours)
deep k
deep k le 10 Fév 2020
Commenté : deep k le 22 Fév 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=(im2double(imread('bookshelf.jpg')));
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
%// Generate Gaussian mask
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
I_pad = padarray(b, [floor(N/2) floor(N/2)]);
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);

Réponse acceptée

Subhadeep Koley
Subhadeep Koley le 10 Fév 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 = im2double(imread('peppers.png'));
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
% Generate Gaussian mask
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
I_pad = padarray(b, [floor(N/2) floor(N/2)]);
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, []);
xCorr2Demo.png

Plus de réponses (0)

Catégories

En savoir plus sur Feature Detection and Extraction dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by