Azzera filtri
Azzera filtri

Cant seem understand the error in code

2 visualizzazioni (ultimi 30 giorni)
Divya
Divya il 22 Ago 2023
Risposto: Dyuman Joshi il 22 Ago 2023
%%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

Risposte (2)

Walter Roberson
Walter Roberson il 22 Ago 2023
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 il 22 Ago 2023
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

Categorie

Scopri di più su Image Processing and Computer Vision in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by