How would I vectorise this code

tempSum = 0;
for m = topLeft(2) : topLeft(2) + widthhight(2) -8
for n = topLeft(1) : topLeft(1) + widthhight(1) -8
for x = 0 : 8
for y = 0 : 8
tempSum = tempSum + double(double(i(n+y,m+x)) * kernel(y+1,x+1));
end
end
result(n + 4,m + 4) = tempSum/81;
tempSum=0;
end
end

댓글 수: 2

Walter Roberson
Walter Roberson 2020년 3월 6일
conv2() some subset of i with kernel as being the thing to convolve with. Use the 'valid' option, I suspect.
Josh Webb
Josh Webb 2020년 3월 6일
Thank you, a lot faster now. I knew about conv2 but didn't know about the "valid" argument

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 3월 6일

댓글:

2020년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by