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

조회 수: 1 (최근 30일)
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);

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 2월 10일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by