필터 지우기
필터 지우기

Cant seem understand the error in code

조회 수: 2 (최근 30일)
Divya
Divya 2023년 8월 22일
답변: Dyuman Joshi 2023년 8월 22일
%%convolution
for i=1:size(I,1)-M %This line of code gives error as "At least one END is missing. The statement beginning here does not have a matching end."
for j=1:size(I,2)-N
Temp=I(i:i+M,j:j+M).*Kernel;% Multiply kernel with original image
Output(i,j)=sum(Temp(:));
end
Output=uint8(Output);
figure, imshow(Output);
Pl help

답변 (2개)

Walter Roberson
Walter Roberson 2023년 8월 22일
You have an end statement corresponding to for j but you do not have an end statement corresponding to for i
I suspect you want
%%convolution
for i=1:size(I,1)-M
for j=1:size(I,2)-N
Temp=I(i:i+M,j:j+M).*Kernel;% Multiply kernel with original image
Output(i,j)=sum(Temp(:));
end
end
Output=uint8(Output);
figure, imshow(Output);

Dyuman Joshi
Dyuman Joshi 2023년 8월 22일
for loops need to be completed with "end". You initiated 2 for loops, but you only closed one.
for i=1:size(I,1)-M
for j=1:size(I,2)-N
% v
Temp=I(i:i+M,j:j+M).*Kernel;% Multiply kernel with original image
Output(i,j)=sum(Temp,'all');
end
%Missing end
end
There might be a typo in the index, as I have highlighted above, you might want to use -
j:j+N

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by