Convolution of a matrix

조회 수: 1 (최근 30일)
The Eagle
The Eagle 2020년 4월 1일
편집: The Eagle 2020년 4월 2일
I've tried to code some of the problem and it is working for a 3*3 filter

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 1일
편집: Ameer Hamza 2020년 4월 1일
Check conv2() to avoid for loop. Following correct the mistake in your code
clc;
clear all;
close all;
im=double(imread('cameraman.tif'));
w=[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;];
k = floor(size(w,1)/2);
[M,N]=size(im);
g = zeros(M, N);
for i=k+1:M-k
for j=k+1:N-k
g(i,j)=sum(im(i-k:i+k,j-k:j+k).*w, 'all');
end
end
figure,imshow(im,[]);
figure,imshow(g,[]);
A simple version with conv2
im=im2double(imread('cameraman.tif'));
w=ones(5);
g = conv2(im, w, 'same');
figure,imshow(im,[]);
figure,imshow(g,[]);
  댓글 수: 4
The Eagle
The Eagle 2020년 4월 1일
Yes I'm using R2016a thank you for helping. :)
Ameer Hamza
Ameer Hamza 2020년 4월 1일
Glad to be of help.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by